Compare commits

...

22 Commits

Author SHA1 Message Date
semantic-release-bot
4bb965e9ff chore(release): 1.0.0-dev.5 [skip ci]
# @revanced/bot-websocket-api [1.0.0-dev.5](https://github.com/revanced/revanced-helper/compare/@revanced/bot-websocket-api@1.0.0-dev.4...@revanced/bot-websocket-api@1.0.0-dev.5) (2024-07-23)
2024-07-23 20:30:32 +00:00
PalmDevs
a8ceeb29ae chore: update lockfile 2024-07-24 03:29:32 +07:00
PalmDevs
96a6540434 build(Needs bump): revert building with bun explicitly
Building with only Bun causes compatibility issues, like Drizzle Kit not being to generate any schema for the database of the Discord bot.
2024-07-24 03:25:30 +07:00
PalmDevs
e02c86a9c4 ci(release): add time limit for job 2024-07-24 03:05:54 +07:00
semantic-release-bot
e82f2ab34b chore(release): 1.0.0-dev.4 [skip ci]
# @revanced/discord-bot [1.0.0-dev.4](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.3...@revanced/discord-bot@1.0.0-dev.4) (2024-07-23)

### Bug Fixes

* **bots/discord:** wrong database schema path ([875bd20](875bd209b2))
2024-07-23 20:04:31 +00:00
PalmDevs
2a6f3c3013 chore: update lockfile 2024-07-24 03:03:19 +07:00
PalmDevs
875bd209b2 fix(bots/discord): wrong database schema path 2024-07-24 01:12:30 +07:00
semantic-release-bot
2b601b1a1d chore(release): 1.0.0-dev.3 [skip ci]
# @revanced/discord-bot [1.0.0-dev.3](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.2...@revanced/discord-bot@1.0.0-dev.3) (2024-07-23)

### Bug Fixes

* **bots/discord:** revert dist denesting, fixes config not found ([0d4898d](0d4898dae8))
2024-07-23 15:42:43 +00:00
semantic-release-bot
164570d176 chore(release): 1.0.0-dev.4 [skip ci]
# @revanced/bot-websocket-api [1.0.0-dev.4](https://github.com/revanced/revanced-helper/compare/@revanced/bot-websocket-api@1.0.0-dev.3...@revanced/bot-websocket-api@1.0.0-dev.4) (2024-07-23)

### Bug Fixes

* **apis/websocket:** hardcoded paths in tesseract worker builds ([38e00eb](38e00eb4e5))
2024-07-23 15:42:10 +00:00
PalmDevs
0d4898dae8 fix(bots/discord): revert dist denesting, fixes config not found 2024-07-23 22:41:15 +07:00
PalmDevs
38e00eb4e5 fix(apis/websocket): hardcoded paths in tesseract worker builds 2024-07-23 22:38:23 +07:00
semantic-release-bot
3117af5497 chore(release): 1.0.0-dev.2 [skip ci]
# @revanced/discord-bot [1.0.0-dev.2](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.1...@revanced/discord-bot@1.0.0-dev.2) (2024-07-23)

### Features

* **bots/discord:** don't nest builds in src directory, autogen db when missing ([4834685](4834685186))
2024-07-23 14:16:41 +00:00
PalmDevs
6a87464b40 chore(bots/discord): fix build script oversight 2024-07-23 21:15:07 +07:00
semantic-release-bot
5db076aee5 chore(release): 1.0.0-dev.3 [skip ci]
# @revanced/bot-websocket-api [1.0.0-dev.3](https://github.com/revanced/revanced-helper/compare/@revanced/bot-websocket-api@1.0.0-dev.2...@revanced/bot-websocket-api@1.0.0-dev.3) (2024-07-23)

### Bug Fixes

* **apis/websocket:** build and runtime issues ([89d8ab1](89d8ab1ee5))
2024-07-23 14:05:57 +00:00
PalmDevs
12f5aaf70f chore: update dependencies 2024-07-23 21:01:05 +07:00
PalmDevs
94d0dcc32b fix(packages/api): misleading errors being thrown 2024-07-23 21:01:04 +07:00
PalmDevs
4834685186 feat(bots/discord): don't nest builds in src directory, autogen db when missing 2024-07-23 21:01:04 +07:00
PalmDevs
ffe0a3ddf5 chore(bots/discord): change config to a js file 2024-07-23 21:01:03 +07:00
PalmDevs
89d8ab1ee5 fix(apis/websocket): build and runtime issues 2024-07-23 21:01:02 +07:00
semantic-release-bot
f142c2b82e chore(release): 1.0.0-dev.2 [skip ci]
# @revanced/bot-websocket-api [1.0.0-dev.2](https://github.com/revanced/revanced-helper/compare/@revanced/bot-websocket-api@1.0.0-dev.1...@revanced/bot-websocket-api@1.0.0-dev.2) (2024-07-22)

### Bug Fixes

* **apis/websocket:** also include tesseract core files in build ([7dfbf6c](7dfbf6c92c))
2024-07-22 17:46:37 +00:00
PalmDevs
7dfbf6c92c fix(apis/websocket): also include tesseract core files in build 2024-07-23 00:44:08 +07:00
semantic-release-bot
55631b220f chore(release): 1.0.0-dev.1 [skip ci]
# @revanced/discord-bot 1.0.0-dev.1 (2024-07-22)

### Bug Fixes

* **bots/discord/commands/mute:** use existing `parseDuration` util function' ([3e07429](3e07429664))
* **bots/discord/commands/unmute:** fix option description and embeds ([7fdf8c0](7fdf8c0dc7))
* **bots/discord/commands:** minor issues ([3b2596e](3b2596e748))
* **bots/discord/commands:** refactor and add checks ([a2bf3ea](a2bf3eade9))
* **bots/discord/database:** fix schema for role presets ([4aa138a](4aa138a9af))
* **bots/discord/scripts:** unintentional escaping on windows ([09dc706](09dc70632d))
* **bots/discord/utils/discord/embeds:** set thumbnail on moderation embeds ([b056291](b056291ad0))
* **bots/discord/utils/discord/rolePresets:** correct property access for presets ([4c6ad11](4c6ad11be3))
* **bots/discord/utils/discord:** add `moderation` module related functions ([7e8270f](7e8270f7d2))
* **bots/discord/utils/duration:** fix empty string returning with duration is 0 ([83c314e](83c314ef5f))
* **bots/discord:** apply active role presets if members rejoin ([f50b26b](f50b26b82d))
* **bots/discord:** check token before connecting to bot api ([f3e4408](f3e4408aa2))
* **bots/discord:** clear role presets after they expire ([faa81f4](faa81f4d88))
* **bots/discord:** connect to discord API even if initial bot API connection fails ([6658b58](6658b582db))
* **bots/discord:** do decancer after resetting nickname ([0303fe3](0303fe3e36))
* **bots/discord:** follow-up if reply is already sent when error ([f75060b](f75060bc9c))
* **bots/discord:** messed up file name for `unmute` command ([399dca7](399dca7153))
* **bots/discord:** owners cannot bypass checks on some commands ([39cba97](39cba97341))
* **bots/discord:** remove auto-generated files ([fb8af00](fb8af00866))
* **bots/discord:** remove usage of macros ([7f27c56](7f27c5607c))
* **bots/discord:** remove useless feature ([d830e48](d830e48bc2))
* **bots/discord:** use `APIEmbed` for response config ([35b9448](35b944800a))
* **bots/discord:** use env for initializing database ([af3759c](af3759caf4))
* **bots/discord:** wrong command file path being imported ([fa0159c](fa0159c3a8))
* config file not being read ([474a8be](474a8be4af))
* **discord-bot:** also execute slash commands ([f0d45b2](f0d45b2c92))
* **discord-bot:** check for role position ([d332043](d332043b1a))
* **discord-bot:** check if the member has the role ([9bff68c](9bff68c8c4))
* **discord-bot:** not executing slash commands ([aa08087](aa0808768b))
* **discord-bot:** only send lowercased text ([7803758](78037580dc))
* dislike button not working properly ([85eba55](85eba55424))
* fix deprecation ([4373ede](4373ede855))
* fix the fiter for the interaction collector ([a9ff003](a9ff00394a))
* ignore message if there's no content ([3cbebc2](3cbebc2842))
* move modules to `/bots` ([cd7156e](cd7156e792))
* trainAI not using the bin location ([bd29943](bd2994388b))

### chore

* fix more build issues ([77fefb9](77fefb9bef))

### Features

* add wit.ai support ([1909e2c](1909e2c421))
* **bots/discord/commands/reply:** send stacktrace when failed ([9f1ac37](9f1ac37927))
* **bots/discord/commands:** add `ban` and `unban` commands ([dc4863d](dc4863dc20))
* **bots/discord/commands:** add `eval` command ([e64d1da](e64d1da00c))
* **bots/discord/commands:** add `mute` and `unmute` commands ([c0fa2fe](c0fa2fe1c3))
* **bots/discord/commands:** add `purge` and `role-preset` commands ([fb01ce5](fb01ce5740))
* **bots/discord/commands:** allow process exception in `exception-test` ([ca47535](ca475356ad))
* **bots/discord/utils/discord/embeds:** expose `applyCommonEmbedStyles` fn ([2d794ed](2d794ede7d))
* **bots/discord/utils/embeds:** make title parameter nullable ([ee885ca](ee885ca758))
* **bots/discord/utils/fs:** use `recursive` option for listing files ([da21e1a](da21e1a6f7))
* **bots/discord/utils:** add duration utility ([a9add9e](a9add9ea9a))
* **bots/discord/utils:** add functions for role presets ([fb32a04](fb32a04ad3))
* **bots/discord/utils:** allow loading commands from custom dir ([8b690b8](8b690b879b))
* **bots/discord:** add `api.disconnectRetryInterval` config ([2f86586](2f86586179))
* **bots/discord:** add `moderation.roles` config to be used in `moderation` commands ([39d5b3a](39d5b3a479))
* **bots/discord:** add `ocrTriggers` resp config, embed footer scan mode ([744a56a](744a56a4fd))
* **bots/discord:** add a better way to manage databases ([a68d726](a68d726875))
* **bots/discord:** add more fallbacks for decancering ([2e1e009](2e1e009b42))
* **bots/discord:** add source ([f9d50a0](f9d50a0a6b))
* **bots/discord:** improve logs ([6abb740](6abb740994))
* **bots/discord:** sanitize `BasicDatabase` inputs ([fd76e0a](fd76e0af72))
* **bots/discord:** support nickname decancering ([1723e8c](1723e8cacf))
* **bots/discord:** switch to `drizzle-orm` ([e204b7b](e204b7b756))
* **bots/discord:** update config ([197d2ac](197d2acea8))
* discord bot scanning messages ([d1bd3b2](d1bd3b2b7e))
* **discord-bot:** a way to train AI ([355a508](355a50803a))
* **discord-bot:** command handler and train cmd ([6aee8a4](6aee8a4c63))
* **discord-bot:** event handler ([0ad5ece](0ad5ece085))
* GODEL AI ([0ba525c](0ba525c4a5))
* initalize discord bot ([bb4a5a7](bb4a5a77ee))
* initialize helper client ([7f9ca77](7f9ca77e03))
* message buttons for training ([6551ca9](6551ca9dad))
* platform specific responses ([18e57b0](18e57b0c32))
* prettier and eslint ([1c27ccb](1c27ccb17c))
* refactor and new features ([#7](https://github.com/revanced/revanced-helper/issues/7)) ([8b9f45d](8b9f45dc22))
* run bots in one process ([d26d533](d26d533174))
* training and replies changed ([715aa91](715aa918cf))
* **utils/discord/embeds:** allow adding extra fields for moderation embeds ([49ce9a7](49ce9a7ca3))

### BREAKING CHANGES

* In `@revanced/discord-bot`, its environment variable
                 `DATABASE_URL` has been renamed to `DATABASE_PATH`
                 and the `file:` prefix is no longer needed
2024-07-22 16:04:34 +00:00
19 changed files with 268 additions and 59 deletions

View File

@@ -14,6 +14,7 @@ jobs:
permissions:
contents: read
packages: write
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4

View File

@@ -1,3 +1,26 @@
# @revanced/bot-websocket-api [1.0.0-dev.5](https://github.com/revanced/revanced-helper/compare/@revanced/bot-websocket-api@1.0.0-dev.4...@revanced/bot-websocket-api@1.0.0-dev.5) (2024-07-23)
# @revanced/bot-websocket-api [1.0.0-dev.4](https://github.com/revanced/revanced-helper/compare/@revanced/bot-websocket-api@1.0.0-dev.3...@revanced/bot-websocket-api@1.0.0-dev.4) (2024-07-23)
### Bug Fixes
* **apis/websocket:** hardcoded paths in tesseract worker builds ([38e00eb](https://github.com/revanced/revanced-helper/commit/38e00eb4e59c763bd74d27b9b9b482ea66e4dcf4))
# @revanced/bot-websocket-api [1.0.0-dev.3](https://github.com/revanced/revanced-helper/compare/@revanced/bot-websocket-api@1.0.0-dev.2...@revanced/bot-websocket-api@1.0.0-dev.3) (2024-07-23)
### Bug Fixes
* **apis/websocket:** build and runtime issues ([89d8ab1](https://github.com/revanced/revanced-helper/commit/89d8ab1ee58278a9a96cdc31c679d0a0a0d865af))
# @revanced/bot-websocket-api [1.0.0-dev.2](https://github.com/revanced/revanced-helper/compare/@revanced/bot-websocket-api@1.0.0-dev.1...@revanced/bot-websocket-api@1.0.0-dev.2) (2024-07-22)
### Bug Fixes
* **apis/websocket:** also include tesseract core files in build ([7dfbf6c](https://github.com/revanced/revanced-helper/commit/7dfbf6c92c49100954fa4aca471dce4ab9fd9565))
# @revanced/bot-websocket-api 1.0.0-dev.1 (2024-07-22)

View File

@@ -6,7 +6,7 @@ FROM base AS build
WORKDIR /build
COPY . .
RUN bun install --frozen-lockfile
RUN cd apis/websocket && bun --bun run build
RUN cd apis/websocket && bun run build
FROM base AS release

View File

@@ -2,7 +2,7 @@
"name": "@revanced/bot-websocket-api",
"type": "module",
"private": true,
"version": "1.0.0-dev.1",
"version": "1.0.0-dev.5",
"description": "🧦 WebSocket API server for bots assisting ReVanced",
"main": "dist/index.js",
"scripts": {

View File

@@ -1,23 +1,34 @@
import { createLogger } from '@revanced/bot-shared'
import { cp } from 'fs/promises'
import { cp, rm } from 'fs/promises'
async function build(): Promise<void> {
const logger = createLogger()
const logger = createLogger()
logger.info('Building Tesseract.js worker...')
await Bun.build({
entrypoints: ['../../node_modules/tesseract.js/src/worker-script/node/index.js'],
target: 'bun',
outdir: './dist/worker',
})
logger.info('Cleaning previous build...')
await rm('./dist', { recursive: true })
logger.info('Building WebSocket API...')
await Bun.build({
entrypoints: ['./src/index.ts'],
outdir: './dist',
target: 'bun',
})
}
logger.info('Building WebSocket API...')
await Bun.build({
entrypoints: ['./src/index.ts'],
outdir: './dist',
target: 'bun',
minify: true,
sourcemap: 'external',
})
await build()
logger.info('Building Tesseract.js worker...')
await Bun.build({
entrypoints: ['../../node_modules/tesseract.js/src/worker-script/node/index.js'],
external: ['tesseract.js-core/*'],
target: 'bun',
outdir: './dist/worker',
minify: true,
sourcemap: 'external',
})
// Tesseract.js is really bad for minification
// It forcefully requires this core module to be present which contains the WASM files
logger.info('Copying Tesseract.js Core...')
await cp('../../node_modules/tesseract.js-core', './dist/node_modules/tesseract.js-core', { recursive: true })
logger.info('Copying config...')
await cp('config.json', 'dist/config.json')

View File

@@ -53,11 +53,11 @@ export interface WitMessageResponse {
}>
}
const TesseractWorkerPath = joinPath(import.meta.dir, 'worker', 'index.js')
const TesseractCompiledWorkerExists = await pathExists(TesseractWorkerPath)
const TesseractWorkerDirPath = joinPath(import.meta.dir, 'worker')
const TesseractWorkerPath = joinPath(TesseractWorkerDirPath, 'index.js')
export const tesseract = await createTesseractWorker(
'eng',
OEM.DEFAULT,
TesseractCompiledWorkerExists ? { workerPath: TesseractWorkerPath } : undefined,
(await pathExists(TesseractWorkerDirPath)) ? { workerPath: TesseractWorkerPath } : undefined,
)

View File

@@ -181,6 +181,7 @@ config.ts
*.db
*.sqlite
*.sqlite3
.drizzle
# Auto-generated files
src/commands/index.ts

116
bots/discord/CHANGELOG.md Normal file
View File

@@ -0,0 +1,116 @@
# @revanced/discord-bot [1.0.0-dev.4](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.3...@revanced/discord-bot@1.0.0-dev.4) (2024-07-23)
### Bug Fixes
* **bots/discord:** wrong database schema path ([875bd20](https://github.com/revanced/revanced-helper/commit/875bd209b252566414bf89349839cabc01697e1c))
# @revanced/discord-bot [1.0.0-dev.3](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.2...@revanced/discord-bot@1.0.0-dev.3) (2024-07-23)
### Bug Fixes
* **bots/discord:** revert dist denesting, fixes config not found ([0d4898d](https://github.com/revanced/revanced-helper/commit/0d4898dae8b26f8466d3f6b8f62875866f581644))
# @revanced/discord-bot [1.0.0-dev.2](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.1...@revanced/discord-bot@1.0.0-dev.2) (2024-07-23)
### Features
* **bots/discord:** don't nest builds in src directory, autogen db when missing ([4834685](https://github.com/revanced/revanced-helper/commit/48346851864c4d4b6276388644dd24ce16222b3e))
# @revanced/discord-bot 1.0.0-dev.1 (2024-07-22)
### Bug Fixes
* **bots/discord/commands/mute:** use existing `parseDuration` util function' ([3e07429](https://github.com/revanced/revanced-helper/commit/3e07429664f7dbb6ce653083e0adb1a232737fde))
* **bots/discord/commands/unmute:** fix option description and embeds ([7fdf8c0](https://github.com/revanced/revanced-helper/commit/7fdf8c0dc722e21fe5a3ad6ef8d3a306ef85f532))
* **bots/discord/commands:** minor issues ([3b2596e](https://github.com/revanced/revanced-helper/commit/3b2596e748cf2cde1500ef2ded55f0faabc2c272))
* **bots/discord/commands:** refactor and add checks ([a2bf3ea](https://github.com/revanced/revanced-helper/commit/a2bf3eade99b46f9ffb55d45b8caf1bcf3d22a9b))
* **bots/discord/database:** fix schema for role presets ([4aa138a](https://github.com/revanced/revanced-helper/commit/4aa138a9af8db7093ef637470fcfdea1f5341236))
* **bots/discord/scripts:** unintentional escaping on windows ([09dc706](https://github.com/revanced/revanced-helper/commit/09dc70632da0597fdb26677acee3f6fccbb2b9b5))
* **bots/discord/utils/discord/embeds:** set thumbnail on moderation embeds ([b056291](https://github.com/revanced/revanced-helper/commit/b056291ad0f2e2eac5eec8aa71f15dbc769aa0f9))
* **bots/discord/utils/discord/rolePresets:** correct property access for presets ([4c6ad11](https://github.com/revanced/revanced-helper/commit/4c6ad11be30c1d6af97c4ae40fc62d05fa7bdd57))
* **bots/discord/utils/discord:** add `moderation` module related functions ([7e8270f](https://github.com/revanced/revanced-helper/commit/7e8270f7d260322e1950e058b221ab088bd595d0))
* **bots/discord/utils/duration:** fix empty string returning with duration is 0 ([83c314e](https://github.com/revanced/revanced-helper/commit/83c314ef5f721abc355272db0e4c182dcfe5d943))
* **bots/discord:** apply active role presets if members rejoin ([f50b26b](https://github.com/revanced/revanced-helper/commit/f50b26b82d66c88fd1dbb8c07d77c177c0e781df))
* **bots/discord:** check token before connecting to bot api ([f3e4408](https://github.com/revanced/revanced-helper/commit/f3e4408aa28fb6a9d21365af8c1bea3d07b481de))
* **bots/discord:** clear role presets after they expire ([faa81f4](https://github.com/revanced/revanced-helper/commit/faa81f4d887eaeae809651f5b68187d033a260f2))
* **bots/discord:** connect to discord API even if initial bot API connection fails ([6658b58](https://github.com/revanced/revanced-helper/commit/6658b582dbeba7e072a7a04c4efa255e7f634aef))
* **bots/discord:** do decancer after resetting nickname ([0303fe3](https://github.com/revanced/revanced-helper/commit/0303fe3e367c07e92f831365d5548ca5b03435b2))
* **bots/discord:** follow-up if reply is already sent when error ([f75060b](https://github.com/revanced/revanced-helper/commit/f75060bc9cda44902cf872def73c116a6df039d7))
* **bots/discord:** messed up file name for `unmute` command ([399dca7](https://github.com/revanced/revanced-helper/commit/399dca71538fe5c8831977694a97058254a17578))
* **bots/discord:** owners cannot bypass checks on some commands ([39cba97](https://github.com/revanced/revanced-helper/commit/39cba973418027ba6ed67e1ae5ab5c6458807562))
* **bots/discord:** remove auto-generated files ([fb8af00](https://github.com/revanced/revanced-helper/commit/fb8af008661bf37389e01cba19d64a8b4fc82139))
* **bots/discord:** remove usage of macros ([7f27c56](https://github.com/revanced/revanced-helper/commit/7f27c5607ceeeef56d67097e88f68caa1b8791b3))
* **bots/discord:** remove useless feature ([d830e48](https://github.com/revanced/revanced-helper/commit/d830e48bc2de7aa457eab3a5f96ae652a93178f9))
* **bots/discord:** use `APIEmbed` for response config ([35b9448](https://github.com/revanced/revanced-helper/commit/35b944800a3943c187d5b0e0d3e465ad7d2056fe))
* **bots/discord:** use env for initializing database ([af3759c](https://github.com/revanced/revanced-helper/commit/af3759caf428fada3b3f4a51852543d6fb280018))
* **bots/discord:** wrong command file path being imported ([fa0159c](https://github.com/revanced/revanced-helper/commit/fa0159c3a8dd4dad8778ccdb75b9e7c02ebbb64f))
* config file not being read ([474a8be](https://github.com/revanced/revanced-helper/commit/474a8be4af4eb2bae6e80a893439d846ad4f7503))
* **discord-bot:** also execute slash commands ([f0d45b2](https://github.com/revanced/revanced-helper/commit/f0d45b2c926ed753e2d21f2e06e24d7e6c43880a))
* **discord-bot:** check for role position ([d332043](https://github.com/revanced/revanced-helper/commit/d332043b1a4bb7ac9698a2fc912832e184130b4b))
* **discord-bot:** check if the member has the role ([9bff68c](https://github.com/revanced/revanced-helper/commit/9bff68c8c40c692764e4dec15a058e35059efbc9))
* **discord-bot:** not executing slash commands ([aa08087](https://github.com/revanced/revanced-helper/commit/aa0808768b90844c5fbd3e75d9f2d01c723b0151))
* **discord-bot:** only send lowercased text ([7803758](https://github.com/revanced/revanced-helper/commit/78037580dc92883f5ca21157e45268850cb5db90))
* dislike button not working properly ([85eba55](https://github.com/revanced/revanced-helper/commit/85eba554247738066af72a8efd0de215ec1164dc))
* fix deprecation ([4373ede](https://github.com/revanced/revanced-helper/commit/4373ede855333f209676551162a525238656e1f8))
* fix the fiter for the interaction collector ([a9ff003](https://github.com/revanced/revanced-helper/commit/a9ff00394a73f68a6793c2b35ff184675ee5a72c))
* ignore message if there's no content ([3cbebc2](https://github.com/revanced/revanced-helper/commit/3cbebc284277808495e64cf0fb47c555924ad9c5))
* move modules to `/bots` ([cd7156e](https://github.com/revanced/revanced-helper/commit/cd7156e792e65777ad1ab5a6f5d828b9ef6a9754))
* trainAI not using the bin location ([bd29943](https://github.com/revanced/revanced-helper/commit/bd2994388bc65f720120ef49edb6ba8163260309))
### chore
* fix more build issues ([77fefb9](https://github.com/revanced/revanced-helper/commit/77fefb9bef286a22f40a4d76b79c64fcc5a2467f))
### Features
* add wit.ai support ([1909e2c](https://github.com/revanced/revanced-helper/commit/1909e2c42148d635dcd045c738d88f65c8be16e3))
* **bots/discord/commands/reply:** send stacktrace when failed ([9f1ac37](https://github.com/revanced/revanced-helper/commit/9f1ac379276c11da65235577a9c6717e01cb02eb))
* **bots/discord/commands:** add `ban` and `unban` commands ([dc4863d](https://github.com/revanced/revanced-helper/commit/dc4863dc208b3fede4d4def323306ab58daffe04))
* **bots/discord/commands:** add `eval` command ([e64d1da](https://github.com/revanced/revanced-helper/commit/e64d1da00cc2ba718da5a4b0da141fe86a0e48d2))
* **bots/discord/commands:** add `mute` and `unmute` commands ([c0fa2fe](https://github.com/revanced/revanced-helper/commit/c0fa2fe1c36acdc7c52cde277aa7da867065f55e))
* **bots/discord/commands:** add `purge` and `role-preset` commands ([fb01ce5](https://github.com/revanced/revanced-helper/commit/fb01ce57400130c93751a11573eb444c0ba103eb))
* **bots/discord/commands:** allow process exception in `exception-test` ([ca47535](https://github.com/revanced/revanced-helper/commit/ca475356ad95fec86e8e8b5bf4bbf17b70add5fe))
* **bots/discord/utils/discord/embeds:** expose `applyCommonEmbedStyles` fn ([2d794ed](https://github.com/revanced/revanced-helper/commit/2d794ede7d7a208bd3616c45e8e6d2a2cd83e9ed))
* **bots/discord/utils/embeds:** make title parameter nullable ([ee885ca](https://github.com/revanced/revanced-helper/commit/ee885ca7585a55fdc31e137ae29dc13a37ce2fb2))
* **bots/discord/utils/fs:** use `recursive` option for listing files ([da21e1a](https://github.com/revanced/revanced-helper/commit/da21e1a6f76deaeb477203b04263bd170863825b))
* **bots/discord/utils:** add duration utility ([a9add9e](https://github.com/revanced/revanced-helper/commit/a9add9ea9affb42bdfcb17cf4b268feec5729854))
* **bots/discord/utils:** add functions for role presets ([fb32a04](https://github.com/revanced/revanced-helper/commit/fb32a04ad38be8d0836dc99259b6ef05a0825830))
* **bots/discord/utils:** allow loading commands from custom dir ([8b690b8](https://github.com/revanced/revanced-helper/commit/8b690b879bb5c6023c8fc863afbd9fd1d02719bb))
* **bots/discord:** add `api.disconnectRetryInterval` config ([2f86586](https://github.com/revanced/revanced-helper/commit/2f8658617923c07f6847cbf1fdfc5f5379d95b6c))
* **bots/discord:** add `moderation.roles` config to be used in `moderation` commands ([39d5b3a](https://github.com/revanced/revanced-helper/commit/39d5b3a479b4d856aabe12cc31177c24f88ae23e))
* **bots/discord:** add `ocrTriggers` resp config, embed footer scan mode ([744a56a](https://github.com/revanced/revanced-helper/commit/744a56a4fdc8844e37959a88bcf81ee39fe726ef))
* **bots/discord:** add a better way to manage databases ([a68d726](https://github.com/revanced/revanced-helper/commit/a68d72687584332587455962b0202a306288057d))
* **bots/discord:** add more fallbacks for decancering ([2e1e009](https://github.com/revanced/revanced-helper/commit/2e1e009b4272495798313bd3bd61f258875c62e1))
* **bots/discord:** add source ([f9d50a0](https://github.com/revanced/revanced-helper/commit/f9d50a0a6bef8beaa428a0a555bfa4f879f685f1))
* **bots/discord:** improve logs ([6abb740](https://github.com/revanced/revanced-helper/commit/6abb7409945c10bd3af451fb45ef4b4d4ebe9489))
* **bots/discord:** sanitize `BasicDatabase` inputs ([fd76e0a](https://github.com/revanced/revanced-helper/commit/fd76e0af72fe28b414ae3b5e8d3886e58561e57e))
* **bots/discord:** support nickname decancering ([1723e8c](https://github.com/revanced/revanced-helper/commit/1723e8cacf96e8c6bdee22cfd30e89524fdcef74))
* **bots/discord:** switch to `drizzle-orm` ([e204b7b](https://github.com/revanced/revanced-helper/commit/e204b7b7566fd7fa423baef32977a8575d44a9e0))
* **bots/discord:** update config ([197d2ac](https://github.com/revanced/revanced-helper/commit/197d2acea89c38e43858d52736508d449152e804))
* discord bot scanning messages ([d1bd3b2](https://github.com/revanced/revanced-helper/commit/d1bd3b2b7e4985a64e9b070ab006cc6f3508c46e))
* **discord-bot:** a way to train AI ([355a508](https://github.com/revanced/revanced-helper/commit/355a50803adc85b5579155b55ddbba4fa0449237))
* **discord-bot:** command handler and train cmd ([6aee8a4](https://github.com/revanced/revanced-helper/commit/6aee8a4c63eb108800fcb0a23ca61f200d8f1f2a))
* **discord-bot:** event handler ([0ad5ece](https://github.com/revanced/revanced-helper/commit/0ad5ece08593c0db111fa4a592b42c6e0348fd1c))
* GODEL AI ([0ba525c](https://github.com/revanced/revanced-helper/commit/0ba525c4a5802106d582c75f713728accf2f151a))
* initalize discord bot ([bb4a5a7](https://github.com/revanced/revanced-helper/commit/bb4a5a77eefbc7ac88536f73a111df1050b235e7))
* initialize helper client ([7f9ca77](https://github.com/revanced/revanced-helper/commit/7f9ca77e0331ec143160ee51ed7c3aa9e4e70b9c))
* message buttons for training ([6551ca9](https://github.com/revanced/revanced-helper/commit/6551ca9dadc2e3ddfe98875e80ed61f7d71a1651))
* platform specific responses ([18e57b0](https://github.com/revanced/revanced-helper/commit/18e57b0c320732a937bb60db11c5d6794ed11522))
* prettier and eslint ([1c27ccb](https://github.com/revanced/revanced-helper/commit/1c27ccb17c85f0f6982db45de426181d2c231d0e))
* refactor and new features ([#7](https://github.com/revanced/revanced-helper/issues/7)) ([8b9f45d](https://github.com/revanced/revanced-helper/commit/8b9f45dc22de29dc2ccb1cfab9a026db00457e25))
* run bots in one process ([d26d533](https://github.com/revanced/revanced-helper/commit/d26d53317440c64fb775cea609a87d29be6c8b40))
* training and replies changed ([715aa91](https://github.com/revanced/revanced-helper/commit/715aa918cf84213c9b19591a398d7532eb3f232a))
* **utils/discord/embeds:** allow adding extra fields for moderation embeds ([49ce9a7](https://github.com/revanced/revanced-helper/commit/49ce9a7ca3d8558b73a9b94dfe7a01d809db6fff))
### BREAKING CHANGES
* In `@revanced/discord-bot`, its environment variable
`DATABASE_URL` has been renamed to `DATABASE_PATH`
and the `file:` prefix is no longer needed

View File

@@ -6,7 +6,7 @@ FROM base AS build
WORKDIR /build
COPY . .
RUN bun install --frozen-lockfile
RUN cd bots/discord && bun --bun run build
RUN cd bots/discord && bun run build
FROM base AS release

View File

@@ -1,5 +1,8 @@
import type { Config } from './config.schema'
// @ts-check
/**
* @type {import('./config.schema').Config}
*/
export default {
owners: ['USER_ID_HERE'],
guilds: ['GUILD_ID_HERE'],
@@ -70,4 +73,4 @@ export default {
disconnectLimit: 3,
disconnectRetryInterval: 10000,
},
} satisfies Config as Config
}

View File

@@ -29,9 +29,8 @@ The distribution files will be placed inside the `dist` directory. Inside will i
To deploy the bot, you'll need to:
1. Replace the `config.ts` file with your own configuration _(optional)_
2. [Build the bot as seen in the previous step](#-building)
3. Run the `reload-slash-commands` script
1. [Build the bot as seen in the previous step](#-building)
2. Run the `reload-slash-commands` script
This is to ensure all commands are registered, so they can be used.
**It may take up to 2 hours until **global** commands are updated. This is a Discord limitation.**
@@ -40,7 +39,7 @@ To deploy the bot, you'll need to:
bun run scripts/reload-slash-commands.ts
```
4. Copy contents of the `dist` directory
3. Copy contents of the `dist` directory
```sh
# For instance, we'll copy them both to /usr/src/discord-bot
@@ -48,18 +47,10 @@ To deploy the bot, you'll need to:
cp -R ./dist/* /usr/src/discord-bot
```
5. Copy the empty database (or use your own existing database)
```sh
# By default, the build script creates the database called "db.sqlite3"
# Unless you specify otherwise via the "DATABASE_PATH" environment variable
cp ./db.sqlite3 /usr/src/discord-bot
```
6. Configure environment variables
4. Configure environment variables
As seen in [`.env.example`](../.env.example). You can also optionally use a `.env` file which **Bun will automatically load**.
7. Finally, run the bot
5. Finally, run the bot
```sh
cd /usr/src/discord-bot

View File

@@ -3,6 +3,7 @@ import { defineConfig } from 'drizzle-kit'
export default defineConfig({
dialect: 'sqlite',
schema: './src/database/schemas.ts',
out: './.drizzle',
dbCredentials: {
url: process.env['DATABASE_PATH'] ? `file:./${process.env['DATABASE_PATH']}` : 'file:./db.sqlite3',
},

View File

@@ -2,17 +2,16 @@
"name": "@revanced/discord-bot",
"type": "module",
"private": true,
"version": "0.1.0",
"version": "1.0.0-dev.4",
"description": "🤖 Discord bot assisting ReVanced",
"main": "src/index.ts",
"scripts": {
"register": "bun run scripts/reload-slash-commands.ts",
"start": "bun prepare && bun run src/index.ts",
"dev": "bun prepare && bun --watch src/index.ts",
"build:config": "bun build config.ts --outdir=dist",
"build": "bun prepare && bun build:config && bun build src/index.ts -e ./config.js --target=bun --outdir=dist/src",
"build": "bun prepare && bun run scripts/build.ts",
"watch": "bun dev",
"prepare": "bun run scripts/generate-indexes.ts && drizzle-kit push"
"prepare": "bun run scripts/generate-indexes.ts && drizzle-kit generate --name=schema"
},
"repository": {
"type": "git",
@@ -44,4 +43,4 @@
"discord-api-types": "^0.37.92",
"drizzle-kit": "^0.22.8"
}
}
}

View File

@@ -0,0 +1,23 @@
import { createLogger } from '@revanced/bot-shared'
import { cp, rename, rm } from 'fs/promises'
const logger = createLogger()
logger.warn('Cleaning previous build...')
await rm('./dist', { recursive: true })
logger.info('Building bot...')
await Bun.build({
entrypoints: ['./src/index.ts'],
outdir: './dist/src',
target: 'bun',
external: ['./config.js'],
minify: true,
sourcemap: 'external',
})
logger.info('Copying config...')
await cp('config.js', 'dist/config.js')
logger.info('Copying database schema...')
await rename('.drizzle', 'dist/.drizzle')

View File

@@ -1,4 +1,6 @@
import { Database } from 'bun:sqlite'
import { existsSync, readFileSync, readdirSync } from 'fs'
import { join } from 'path'
import { Client as APIClient } from '@revanced/bot-api'
import { createLogger } from '@revanced/bot-shared'
import { ActivityType, Client as DiscordClient, Partials } from 'discord.js'
@@ -29,7 +31,33 @@ export const api = {
disconnectCount: 0,
}
const db = new Database(process.env['DATABASE_PATH'])
const DatabasePath = process.env['DATABASE_PATH']
const DatabaseSchemaDir = join(import.meta.dir, '..', '.drizzle')
let dbSchemaFileName: string | undefined
if (DatabasePath && !existsSync(DatabasePath)) {
logger.warn('Database file not found, trying to create from schema...')
try {
const file = readdirSync(DatabaseSchemaDir, { withFileTypes: true })
.filter(file => file.isFile() && file.name.endsWith('.sql'))
.sort()
.at(-1)
if (!file) throw new Error('No schema file found')
dbSchemaFileName = file.name
logger.debug(`Using schema file: ${dbSchemaFileName}`)
} catch (e) {
logger.fatal('Could not create database from schema, check if the schema file exists and is accessible')
logger.fatal(e)
process.exit(1)
}
}
const db = new Database(DatabasePath)
if (dbSchemaFileName) db.run(readFileSync(join(DatabaseSchemaDir, dbSchemaFileName)).toString())
export const database = drizzle(db, {
schema: schemas,

View File

@@ -9,6 +9,7 @@
"composite": false,
"exactOptionalPropertyTypes": false,
"esModuleInterop": true,
"allowJs": true,
"paths": {
"$/*": ["./src/*"],
"$constants": ["./src/constants"],

BIN
bun.lockb

Binary file not shown.

View File

@@ -41,11 +41,11 @@
"@tsconfig/strictest": "^2.0.5",
"@types/bun": "^1.1.6",
"conventional-changelog-conventionalcommits": "^7.0.2",
"lefthook": "^1.7.4",
"lefthook": "^1.7.5",
"portainer-service-webhook": "https://github.com/newarifrh/portainer-service-webhook#v1",
"semantic-release": "^24.0.0",
"turbo": "^2.0.9",
"typescript": "^5.5.3"
"typescript": "^5.5.4"
},
"trustedDependencies": [
"@biomejs/biome",

View File

@@ -53,23 +53,34 @@ export class ClientWebSocketManager {
}
}, this.timeout)
this.#socket.on('open', () => {
this.disconnected = false
clearTimeout(timeout)
this.#listen()
rs()
})
this.#socket.on('error', err => {
clearTimeout(timeout)
const errorBeforeReadyHandler = (err: Error) => {
cleanup()
throw err
})
}
this.#socket.on('close', (code, reason) => {
const closeBeforeReadyHandler = (code: number, reason: Buffer) => {
clearTimeout(timeout)
this._handleDisconnect(code, reason.toString())
throw new Error('WebSocket connection closed before ready')
})
}
const readyHandler = () => {
this.disconnected = false
cleanup()
this.#listen()
rs()
}
const cleanup = () => {
this.#socket.off('open', readyHandler)
this.#socket.off('close', closeBeforeReadyHandler)
this.#socket.off('error', errorBeforeReadyHandler)
clearTimeout(timeout)
}
this.#socket.on('open', readyHandler)
this.#socket.on('error', errorBeforeReadyHandler)
this.#socket.on('close', closeBeforeReadyHandler)
} catch (e) {
rj(e)
}