From df9471a7e4777c6cd581747c6623583e52f3bbed Mon Sep 17 00:00:00 2001 From: Danil Nikolaev Date: Mon, 12 Jan 2026 15:32:50 +0300 Subject: [PATCH] refactor!: rewrite bot core; add AI (Ollama, Gemini), DB, new commands --- .eslintrc.json | 30 + .github/dependabot.yml | 6 + .github/workflows/docker-publish.yml | 53 + .gitignore | 3 + .idea/modules.xml | 2 +- .idea/{tg-ts-bot.iml => tg-chat-bot.iml} | 0 .idea/workspace.xml | 390 +- Dockerfile | 25 + Dockerfile-bun | 25 + answers.json | 118 - assets/Inter_18pt-Black.ttf | Bin 0 -> 344820 bytes assets/Inter_18pt-Bold.ttf | Bin 0 -> 344152 bytes assets/Inter_18pt-ExtraBold.ttf | Bin 0 -> 345008 bytes assets/Inter_18pt-ExtraLight.ttf | Bin 0 -> 343532 bytes assets/Inter_18pt-Light.ttf | Bin 0 -> 343704 bytes assets/Inter_18pt-Medium.ttf | Bin 0 -> 343200 bytes assets/Inter_18pt-Regular.ttf | Bin 0 -> 342680 bytes assets/Inter_18pt-SemiBold.ttf | Bin 0 -> 343828 bytes assets/Inter_18pt-Thin.ttf | Bin 0 -> 343088 bytes base/base.js | 201 - base/base.js.map | 1 - base/base.ts | 261 - base/db.js | 105 - base/db.js.map | 1 - base/db.ts | 112 - base/net.js | 26 - base/net.js.map | 1 - base/net.ts | 30 - base/package.json | 4 - bun.lock | 928 +++ commands/ae.js | 28 - commands/ae.js.map | 1 - commands/ae.ts | 34 - commands/base/command.d.ts | 13 - commands/base/commands.js | 54 - commands/base/commands.js.map | 1 - commands/base/commands.ts | 60 - commands/base/stats.js | 15 - commands/base/stats.js.map | 1 - commands/base/stats.ts | 15 - commands/dad.js | 16 - commands/dad.js.map | 1 - commands/dad.ts | 14 - commands/fuckYou.js | 16 - commands/fuckYou.js.map | 1 - commands/fuckYou.ts | 14 - commands/help.js | 14 - commands/help.js.map | 1 - commands/help.ts | 17 - commands/mom.js | 16 - commands/mom.js.map | 1 - commands/mom.ts | 14 - commands/mute.js | 23 - commands/mute.js.map | 1 - commands/mute.ts | 25 - commands/ping.js | 20 - commands/ping.js.map | 1 - commands/ping.ts | 22 - commands/q.js | 14 - commands/q.js.map | 1 - commands/q.ts | 16 - commands/randomString.js | 21 - commands/randomString.js.map | 1 - commands/randomString.ts | 25 - commands/systemSpecs.js | 14 - commands/systemSpecs.js.map | 1 - commands/systemSpecs.ts | 13 - commands/test.js | 17 - commands/test.js.map | 1 - commands/test.ts | 16 - commands/unmute.js | 23 - commands/unmute.js.map | 1 - commands/unmute.ts | 25 - data.json | 7 - debug.bat | 2 - debug_data.json | 1 - drizzle.config.ts | 12 + index.js | 10 - index.js.map | 1 - index.ts | 10 - package-lock.json | 6887 +++++++++++++++++++++- package.json | 39 +- src/base/callback-command.ts | 42 + src/base/chat-command.ts | 15 + src/base/dao.ts | 9 + src/base/requirement.ts | 7 + src/base/requirements.ts | 33 + src/commands/admins-add.ts | 42 + src/commands/admins-remove.ts | 42 + src/commands/ae.ts | 37 + src/commands/ban.ts | 50 + src/commands/cache-clear.ts | 18 + src/commands/cache-size.ts | 17 + src/commands/choice.ts | 37 + src/commands/coin.ts | 14 + src/commands/dice.ts | 28 + src/commands/distort.ts | 56 + src/commands/gemini-chat.ts | 139 + src/commands/help.ts | 39 + src/commands/id.ts | 18 + src/commands/leave.ts | 17 + src/commands/mute.ts | 39 + src/commands/ollama-chat.ts | 122 + src/commands/ollama-kill.ts | 24 + src/commands/ollama-prompt.ts | 115 + src/commands/ollama-search.ts | 47 + src/commands/ping.ts | 17 + src/commands/prefix-response.ts | 12 + src/commands/qr.ts | 57 + src/commands/quote.ts | 432 ++ src/commands/random-int.ts | 24 + src/commands/random-string.ts | 26 + src/commands/shutdown.ts | 46 + src/commands/start.ts | 14 + src/commands/system-specs.ts | 14 + src/commands/test.ts | 14 + src/commands/title.ts | 28 + src/commands/unban.ts | 50 + src/commands/unmute.ts | 38 + src/commands/uptime.ts | 13 + src/commands/what-better.ts | 19 + src/commands/when.ts | 90 + src/common/environment.ts | 74 + src/common/message-part.ts | 5 + src/common/message-store.ts | 44 + src/common/user-store.ts | 38 + src/db/database-manager.ts | 12 + src/db/database.ts | 97 + src/db/message-dao.ts | 113 + src/db/schema.ts | 25 + src/db/user-dao.ts | 105 + src/index.ts | 263 + src/model/stored-message.ts | 8 + src/model/stored-user.ts | 8 + src/model/web-search-response.ts | 5 + src/util/utils.ts | 731 +++ tsconfig.json | 18 +- 137 files changed, 11341 insertions(+), 2025 deletions(-) create mode 100644 .eslintrc.json create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/docker-publish.yml rename .idea/{tg-ts-bot.iml => tg-chat-bot.iml} (100%) create mode 100644 Dockerfile create mode 100644 Dockerfile-bun delete mode 100644 answers.json create mode 100644 assets/Inter_18pt-Black.ttf create mode 100644 assets/Inter_18pt-Bold.ttf create mode 100644 assets/Inter_18pt-ExtraBold.ttf create mode 100644 assets/Inter_18pt-ExtraLight.ttf create mode 100644 assets/Inter_18pt-Light.ttf create mode 100644 assets/Inter_18pt-Medium.ttf create mode 100644 assets/Inter_18pt-Regular.ttf create mode 100644 assets/Inter_18pt-SemiBold.ttf create mode 100644 assets/Inter_18pt-Thin.ttf delete mode 100644 base/base.js delete mode 100644 base/base.js.map delete mode 100644 base/base.ts delete mode 100644 base/db.js delete mode 100644 base/db.js.map delete mode 100644 base/db.ts delete mode 100644 base/net.js delete mode 100644 base/net.js.map delete mode 100644 base/net.ts delete mode 100644 base/package.json create mode 100644 bun.lock delete mode 100644 commands/ae.js delete mode 100644 commands/ae.js.map delete mode 100644 commands/ae.ts delete mode 100644 commands/base/command.d.ts delete mode 100644 commands/base/commands.js delete mode 100644 commands/base/commands.js.map delete mode 100644 commands/base/commands.ts delete mode 100644 commands/base/stats.js delete mode 100644 commands/base/stats.js.map delete mode 100644 commands/base/stats.ts delete mode 100644 commands/dad.js delete mode 100644 commands/dad.js.map delete mode 100644 commands/dad.ts delete mode 100644 commands/fuckYou.js delete mode 100644 commands/fuckYou.js.map delete mode 100644 commands/fuckYou.ts delete mode 100644 commands/help.js delete mode 100644 commands/help.js.map delete mode 100644 commands/help.ts delete mode 100644 commands/mom.js delete mode 100644 commands/mom.js.map delete mode 100644 commands/mom.ts delete mode 100644 commands/mute.js delete mode 100644 commands/mute.js.map delete mode 100644 commands/mute.ts delete mode 100644 commands/ping.js delete mode 100644 commands/ping.js.map delete mode 100644 commands/ping.ts delete mode 100644 commands/q.js delete mode 100644 commands/q.js.map delete mode 100644 commands/q.ts delete mode 100644 commands/randomString.js delete mode 100644 commands/randomString.js.map delete mode 100644 commands/randomString.ts delete mode 100644 commands/systemSpecs.js delete mode 100644 commands/systemSpecs.js.map delete mode 100644 commands/systemSpecs.ts delete mode 100644 commands/test.js delete mode 100644 commands/test.js.map delete mode 100644 commands/test.ts delete mode 100644 commands/unmute.js delete mode 100644 commands/unmute.js.map delete mode 100644 commands/unmute.ts delete mode 100644 data.json delete mode 100644 debug.bat delete mode 100644 debug_data.json create mode 100644 drizzle.config.ts delete mode 100644 index.js delete mode 100644 index.js.map delete mode 100644 index.ts create mode 100644 src/base/callback-command.ts create mode 100644 src/base/chat-command.ts create mode 100644 src/base/dao.ts create mode 100644 src/base/requirement.ts create mode 100644 src/base/requirements.ts create mode 100644 src/commands/admins-add.ts create mode 100644 src/commands/admins-remove.ts create mode 100644 src/commands/ae.ts create mode 100644 src/commands/ban.ts create mode 100644 src/commands/cache-clear.ts create mode 100644 src/commands/cache-size.ts create mode 100644 src/commands/choice.ts create mode 100644 src/commands/coin.ts create mode 100644 src/commands/dice.ts create mode 100644 src/commands/distort.ts create mode 100644 src/commands/gemini-chat.ts create mode 100644 src/commands/help.ts create mode 100644 src/commands/id.ts create mode 100644 src/commands/leave.ts create mode 100644 src/commands/mute.ts create mode 100644 src/commands/ollama-chat.ts create mode 100644 src/commands/ollama-kill.ts create mode 100644 src/commands/ollama-prompt.ts create mode 100644 src/commands/ollama-search.ts create mode 100644 src/commands/ping.ts create mode 100644 src/commands/prefix-response.ts create mode 100644 src/commands/qr.ts create mode 100644 src/commands/quote.ts create mode 100644 src/commands/random-int.ts create mode 100644 src/commands/random-string.ts create mode 100644 src/commands/shutdown.ts create mode 100644 src/commands/start.ts create mode 100644 src/commands/system-specs.ts create mode 100644 src/commands/test.ts create mode 100644 src/commands/title.ts create mode 100644 src/commands/unban.ts create mode 100644 src/commands/unmute.ts create mode 100644 src/commands/uptime.ts create mode 100644 src/commands/what-better.ts create mode 100644 src/commands/when.ts create mode 100644 src/common/environment.ts create mode 100644 src/common/message-part.ts create mode 100644 src/common/message-store.ts create mode 100644 src/common/user-store.ts create mode 100644 src/db/database-manager.ts create mode 100644 src/db/database.ts create mode 100644 src/db/message-dao.ts create mode 100644 src/db/schema.ts create mode 100644 src/db/user-dao.ts create mode 100644 src/index.ts create mode 100644 src/model/stored-message.ts create mode 100644 src/model/stored-user.ts create mode 100644 src/model/web-search-response.ts create mode 100644 src/util/utils.ts diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..18adabe --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,30 @@ +{ + "env": { + "browser": true, + "es2021": true + }, + "extends": [ + "eslint:recommended", + "plugin:@typescript-eslint/recommended" + ], + "overrides": [ + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module" + }, + "plugins": [ + "@typescript-eslint" + ], + "rules": { + "quotes": [ + "error", + "double" + ], + "semi": [ + "error", + "always" + ] + } +} diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..d1f0d08 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "npm" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..dfd8362 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,53 @@ +name: Docker + +on: + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_OWNER: ${{ github.repository_owner }} + IMAGE_NAME: tg-chat-bot + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + id-token: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=latest,enable=${{ github.ref_name == 'master' }} + type=ref,event=branch + + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.gitignore b/.gitignore index 6704566..91acca0 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,9 @@ yarn-debug.log* yarn-error.log* lerna-debug.log* +.idea +data + # Diagnostic reports (https://nodejs.org/api/report.html) report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json diff --git a/.idea/modules.xml b/.idea/modules.xml index fe0c06d..de7d726 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,7 +2,7 @@ - + \ No newline at end of file diff --git a/.idea/tg-ts-bot.iml b/.idea/tg-chat-bot.iml similarity index 100% rename from .idea/tg-ts-bot.iml rename to .idea/tg-chat-bot.iml diff --git a/.idea/workspace.xml b/.idea/workspace.xml index b9f22ac..11317cd 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -19,34 +19,140 @@