-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 15a5e5a
Showing
33 changed files
with
7,139 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module.exports = { | ||
parser: '@typescript-eslint/parser', | ||
parserOptions: { | ||
project: 'tsconfig.json', | ||
tsconfigRootDir: __dirname, | ||
sourceType: 'module', | ||
}, | ||
plugins: ['@typescript-eslint/eslint-plugin'], | ||
extends: [ | ||
// 'plugin:@typescript-eslint/recommended', | ||
// 'plugin:prettier/recommended', | ||
], | ||
root: true, | ||
env: { | ||
node: true, | ||
jest: true, | ||
}, | ||
ignorePatterns: ['.eslintrc.js'], | ||
rules: { | ||
'@typescript-eslint/interface-name-prefix': 'off', | ||
'@typescript-eslint/explicit-function-return-type': 'off', | ||
'@typescript-eslint/explicit-module-boundary-types': 'off', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
|
||
|
||
"require-await": "off", | ||
"@typescript-eslint/require-await": "error", | ||
// "@typescript-eslint/explicit-module-boundary-types": "error", | ||
// "@typescript-eslint/no-empty-function": "error",? | ||
"@typescript-eslint/no-floating-promises": "error" | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Publish to NPM | ||
|
||
on: | ||
push: | ||
tags: | ||
- '*' | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: '0' | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '19.x' | ||
registry-url: 'https://registry.npmjs.org' | ||
|
||
- name: Install dependencies and build 🔧 | ||
run: yarn && yarn run build | ||
- name: Publish package on NPM 📦 | ||
run: yarn publish --new-version $(git describe --tags `git rev-list --tags --max-count=1`) | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
name: "ts_tests" | ||
|
||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Setup Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: '19.x' | ||
|
||
- name: Install dependencies | ||
run: yarn | ||
|
||
- name: Run tests | ||
run: yarn test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# compiled output | ||
/dist | ||
/node_modules | ||
/build | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
pnpm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
lerna-debug.log* | ||
|
||
# OS | ||
.DS_Store | ||
|
||
# Tests | ||
/coverage | ||
/.nyc_output | ||
|
||
# IDEs and editors | ||
/.idea | ||
.project | ||
.classpath | ||
.c9/ | ||
*.launch | ||
.settings/ | ||
*.sublime-workspace | ||
|
||
# IDE - VSCode | ||
.vscode/* | ||
!.vscode/settings.json | ||
!.vscode/tasks.json | ||
!.vscode/launch.json | ||
!.vscode/extensions.json | ||
|
||
# dotenv environment variable files | ||
.env | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
.env.local | ||
|
||
# temp directory | ||
.temp | ||
.tmp | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
*.pid.lock | ||
|
||
# Diagnostic reports (https://nodejs.org/api/report.html) | ||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"singleQuote": true, | ||
"trailingComma": "all" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"recommendations": [ | ||
"neo4j-extensions.neo4j-for-vscode", | ||
"gruntfuggly.todo-tree", | ||
"dbaeumer.vscode-eslint", | ||
"yoavbls.pretty-ts-errors", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"files.insertFinalNewline": true, | ||
"editor.tabSize": 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/nest-cli", | ||
"collection": "@nestjs/schematics", | ||
"sourceRoot": "src", | ||
"compilerOptions": { | ||
"deleteOutDir": true | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
{ | ||
"name": "chat-toolkit", | ||
"version": "0.0.1", | ||
"description": "", | ||
"author": "", | ||
"private": true, | ||
"license": "UNLICENSED", | ||
"scripts": { | ||
"build": "nest build", | ||
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"", | ||
"start": "nest start", | ||
"start:dev": "nest start --watch", | ||
"start:debug": "nest start --debug --watch", | ||
"start:prod": "node dist/main", | ||
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix", | ||
"test": "jest", | ||
"test:watch": "jest --watch", | ||
"test:cov": "jest --coverage", | ||
"test:debug": "node --inspect-brk -r tsconfig-paths/register -r ts-node/register node_modules/.bin/jest --runInBand", | ||
"test:e2e": "jest --config ./test/jest-e2e.json" | ||
}, | ||
"dependencies": { | ||
"@nestjs/common": "^10.0.0", | ||
"@nestjs/core": "^10.0.0", | ||
"@nestjs/platform-express": "^10.0.0", | ||
"@types/ramda": "^0.30.2", | ||
"moment": "^2.30.1", | ||
"ramda": "^0.30.1", | ||
"reflect-metadata": "^0.2.0", | ||
"rxjs": "^7.8.1", | ||
"telegraf": "^4.16.3", | ||
"tsup": "^8.3.0" | ||
}, | ||
"devDependencies": { | ||
"@nestjs/cli": "^10.0.0", | ||
"@nestjs/schematics": "^10.0.0", | ||
"@nestjs/testing": "^10.0.0", | ||
"@types/express": "^4.17.17", | ||
"@types/jest": "^29.5.2", | ||
"@types/node": "^20.3.1", | ||
"@types/supertest": "^6.0.0", | ||
"@typescript-eslint/eslint-plugin": "^8.0.0", | ||
"@typescript-eslint/parser": "^8.0.0", | ||
"eslint": "^8.42.0", | ||
"eslint-config-prettier": "^9.0.0", | ||
"eslint-plugin-prettier": "^5.0.0", | ||
"jest": "^29.5.0", | ||
"prettier": "^3.0.0", | ||
"source-map-support": "^0.5.21", | ||
"supertest": "^7.0.0", | ||
"ts-jest": "^29.1.0", | ||
"ts-loader": "^9.4.3", | ||
"ts-node": "^10.9.1", | ||
"tsconfig-paths": "^4.2.0", | ||
"typescript": "^5.1.3" | ||
}, | ||
"jest": { | ||
"moduleFileExtensions": [ | ||
"js", | ||
"json", | ||
"ts" | ||
], | ||
"rootDir": "src", | ||
"testRegex": ".*\\.spec\\.ts$", | ||
"transform": { | ||
"^.+\\.(t|j)s$": "ts-jest" | ||
}, | ||
"collectCoverageFrom": [ | ||
"**/*.(t|j)s" | ||
], | ||
"coverageDirectory": "../coverage", | ||
"testEnvironment": "node" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
// const originalR4equire = global.require | ||
|
||
|
||
// global.require = Object.assign((args) => { | ||
// console.log('required') | ||
// return originalR4equire(args) | ||
|
||
// }, originalR4equire) | ||
|
||
import 'tsconfig-paths/register' | ||
import '@/modules/neo4j' | ||
|
||
import '@/models/__relations' | ||
import { Telegraf } from 'telegraf'; | ||
import * as dotenv from 'dotenv'; | ||
import 'neogma' | ||
import { findOrCreateUser } from '@/lib/telegram_context'; | ||
import { allStates } from '@/lib/state'; | ||
import { createTelegramHandler, ExtractContext } from './handler'; | ||
|
||
import '@/jobs/hunger' | ||
import '@/states/callback_execution' | ||
import { setupNotificationHandler } from '@/jobs/notifications'; | ||
import { Ref } from '@/utils/Ref'; | ||
import { executeByUUID } from '@/states/callback_execution'; | ||
import { setupSleep } from '@/jobs/sleep'; | ||
|
||
import { setupCallbackQueryHandling } from '@/states/hunger'; | ||
import { setupFamilyCallbackQueryHandling } from '@/lib/referal/states/familty'; | ||
import { setupCommands } from '@/commands/@setup'; | ||
import { setupBonusNotifications } from './jobs/bonus'; | ||
import { setupIndexesAndUniq } from './modules/neo4j'; | ||
import { setupMarketCallbackQueryHandling } from './states/market/inline-keyboard'; | ||
import { setupInventoryCallbackQueryHandling } from './states/inventory/inline-keyboard'; | ||
import { logger } from './modules/logger'; | ||
import { detectBlockingStates } from './lib/detect-blocking-states'; | ||
|
||
|
||
dotenv.config(); | ||
|
||
console.log({ | ||
TG_BOT_API_TOKEN: process.env.TG_BOT_API_TOKEN | ||
}) | ||
|
||
|
||
|
||
export const bot = new Telegraf(process.env.TG_BOT_API_TOKEN as string) | ||
|
||
|
||
|
||
const handler | ||
= createTelegramHandler({ | ||
bot, | ||
allStates, | ||
defaultState: 'startingState' | ||
}) | ||
|
||
export const { privateContextStore, cancelContext, handlePrivateMessage } = handler | ||
|
||
|
||
// bot | ||
|
||
bot.use(async (ctx, next) => { | ||
if (!ctx.from) { | ||
return | ||
} | ||
|
||
const { id, first_name } = ctx.from | ||
|
||
await findOrCreateUser(id, first_name) | ||
await next() | ||
}) | ||
|
||
|
||
// Should run after handlePrivateMessage to be sure that user exists in db | ||
|
||
|
||
|
||
bot.action(/.*/, async ctx => { | ||
await ctx.answerCbQuery(); | ||
|
||
const mid = ctx.callbackQuery.message?.message_id | ||
|
||
const data = (ctx.callbackQuery as any).data | ||
|
||
await executeByUUID(data, { | ||
...await setupInventoryCallbackQueryHandling(ctx), | ||
...setupCallbackQueryHandling(ctx), | ||
...await setupFamilyCallbackQueryHandling(ctx), | ||
...await setupMarketCallbackQueryHandling(ctx), | ||
}) | ||
|
||
}) | ||
|
||
|
||
type c = ExtractContext<Parameters<typeof bot.on<'message'>>[1]> | ||
|
||
const onMessage = async (ctx: c) => { | ||
|
||
console.log(ctx.message) | ||
|
||
if (ctx.message.chat.type != 'private') { | ||
logger.warn('skipping non private') | ||
return | ||
} | ||
|
||
await handlePrivateMessage(ctx as any) | ||
|
||
} | ||
|
||
|
||
bot.catch((err) => console.error(err)) | ||
|
||
export interface SharedCtxState { | ||
botUsername?: string | ||
} | ||
|
||
|
||
export const sharedCtxRef: Ref<SharedCtxState> = { value: {} } | ||
|
||
async function start() { | ||
|
||
await detectBlockingStates() | ||
|
||
await setupCommands(bot, handler) | ||
bot.on('message', onMessage) | ||
|
||
await setupIndexesAndUniq() | ||
setupNotificationHandler(handler) | ||
setupBonusNotifications() | ||
setupSleep() | ||
|
||
const me = await bot.telegram.getMe() | ||
|
||
sharedCtxRef.value!.botUsername = me.username! | ||
|
||
await bot.launch(() => { | ||
logger.info(`Startd bot - t.me/${me.username}`) | ||
}) | ||
} | ||
|
||
if (require.main === module) { | ||
void start() | ||
} | ||
|
||
|
Oops, something went wrong.