Compare commits

...

69 Commits

Author SHA1 Message Date
semantic-release-bot
b01a4accee chore(release): 1.0.2 [skip ci]
## @revanced/bot-websocket-api [1.0.2](https://github.com/revanced/revanced-bots/compare/@revanced/bot-websocket-api@1.0.1...@revanced/bot-websocket-api@1.0.2) (2025-06-23)
2025-06-23 13:32:58 +00:00
PalmDevs
858e989bdc build(Needs bump): update dependencies 2025-06-23 20:32:18 +07:00
PalmDevs
3a0f0fe786 fix(bots/discord): disable unneeded cache, enable message cache sweeping 2025-06-23 20:30:28 +07:00
semantic-release-bot
409e850768 chore(release): 1.2.2 [skip ci]
## @revanced/discord-bot [1.2.2](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.2.1...@revanced/discord-bot@1.2.2) (2025-06-10)

### Bug Fixes

* **bots/discord:** use intervals for checking expired presets ([6e89b87](6e89b874cd))
2025-06-10 17:40:44 +00:00
PalmDevs
6e89b874cd fix(bots/discord): use intervals for checking expired presets 2025-06-11 00:40:08 +07:00
semantic-release-bot
b4a5c62549 chore(release): 1.2.1 [skip ci]
## @revanced/discord-bot [1.2.1](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.2.0...@revanced/discord-bot@1.2.1) (2025-05-02)

### Bug Fixes

* **bots/discord:** fix timeout overflow check for role presets ([495f686](495f686292))
2025-05-02 16:11:20 +00:00
PalmDevs
495f686292 fix(bots/discord): fix timeout overflow check for role presets 2025-05-02 23:01:37 +07:00
semantic-release-bot
71eb11b67f chore(release): 1.2.0 [skip ci]
# @revanced/discord-bot [1.2.0](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.1.2...@revanced/discord-bot@1.2.0) (2025-05-02)

### Features

* **bots/discord:** switch duration parser to `@sapphire/duration` ([04ce825](04ce8252c0))
2025-05-02 15:58:00 +00:00
PalmDevs
04ce8252c0 feat(bots/discord): switch duration parser to @sapphire/duration 2025-05-02 22:57:13 +07:00
semantic-release-bot
27e06db1d9 chore(release): 1.1.2 [skip ci]
## @revanced/discord-bot [1.1.2](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.1.1...@revanced/discord-bot@1.1.2) (2025-04-16)

### Bug Fixes

* **bots/discord/commands/admin/reload:** fix type error ([3908854](3908854fe0))
* **bots/discord/commands/moderation:** check if timeout amount is safe in role-preset commands ([0c1382c](0c1382c558))
* **bots/discord:** replace use of deprecated `options.ephemeral` in replies ([31e5cf7](31e5cf7fc5))
2025-04-16 13:41:16 +00:00
PalmDevs
3908854fe0 fix(bots/discord/commands/admin/reload): fix type error 2025-04-16 20:40:16 +07:00
PalmDevs
0c1382c558 fix(bots/discord/commands/moderation): check if timeout amount is safe in role-preset commands 2025-04-16 20:40:14 +07:00
PalmDevs
410d289297 ci(release): hash new lockfile for dependency caching 2025-04-16 20:40:12 +07:00
PalmDevs
31e5cf7fc5 fix(bots/discord): replace use of deprecated options.ephemeral in replies 2025-04-16 20:40:11 +07:00
semantic-release-bot
4e797a2cfd chore(release): 1.1.1 [skip ci]
## @revanced/discord-bot [1.1.1](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.1.0...@revanced/discord-bot@1.1.1) (2025-04-14)

### Bug Fixes

* **bots/discord:** fix sticky msg force timer always starting, add more logging ([cb4dc42](cb4dc42dfa))
2025-04-14 14:09:38 +00:00
PalmDevs
cb4dc42dfa fix(bots/discord): fix sticky msg force timer always starting, add more logging 2025-04-14 21:08:47 +07:00
semantic-release-bot
33ba5b1f61 chore(release): 1.1.0 [skip ci]
# @revanced/discord-bot [1.1.0](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.0.4...@revanced/discord-bot@1.1.0) (2025-04-14)

### Features

* **bots/discord:** delete and send sticky msg concurrently, add more logging ([247a00f](247a00f57f))
2025-04-14 14:01:23 +00:00
PalmDevs
247a00f57f feat(bots/discord): delete and send sticky msg concurrently, add more logging 2025-04-14 21:00:24 +07:00
semantic-release-bot
0da3c989cd chore(release): 1.0.4 [skip ci]
## @revanced/discord-bot [1.0.4](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.0.3...@revanced/discord-bot@1.0.4) (2025-04-14)

### Bug Fixes

* **bots/discord:** fix sticky messages logic again ([aa7501c](aa7501c309))
* **bots/discord:** remove expired presets from db if unapplying is not possible ([9d705e5](9d705e580c))
2025-04-14 12:54:56 +00:00
PalmDevs
16d97f409c chore: format 2025-04-14 19:53:58 +07:00
PalmDevs
539025f2d4 chore(bots/discord): separate discord ready event handlers 2025-04-14 19:53:56 +07:00
PalmDevs
9d705e580c fix(bots/discord): remove expired presets from db if unapplying is not possible 2025-04-14 19:53:54 +07:00
PalmDevs
aa7501c309 fix(bots/discord): fix sticky messages logic again 2025-04-14 19:53:53 +07:00
semantic-release-bot
00118b4a1b chore(release): 1.0.3 [skip ci]
## @revanced/discord-bot [1.0.3](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.0.2...@revanced/discord-bot@1.0.3) (2025-04-09)

### Bug Fixes

* **bots/discord:** attempt to fix sticky messages one last time ([65288ec](65288ec424))
2025-04-09 14:06:27 +00:00
PalmDevs
65288ec424 fix(bots/discord): attempt to fix sticky messages one last time 2025-04-09 21:05:37 +07:00
PalmDevs
a5067889b2 chore: update monorepo README 2025-04-09 21:05:35 +07:00
semantic-release-bot
8efa9091a4 chore(release): 1.0.2 [skip ci]
## @revanced/discord-bot [1.0.2](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.0.1...@revanced/discord-bot@1.0.2) (2025-04-09)
2025-04-09 13:48:21 +00:00
semantic-release-bot
0e44bb5ffe chore(release): 1.0.1 [skip ci]
## @revanced/bot-websocket-api [1.0.1](https://github.com/revanced/revanced-bots/compare/@revanced/bot-websocket-api@1.0.0...@revanced/bot-websocket-api@1.0.1) (2025-04-09)

### Bug Fixes

* **bots/discord:** attempt to fix sticky messages again ([7564b1a](7564b1a8f0))
2025-04-09 13:47:36 +00:00
PalmDevs
8942d27453 build(Needs bump): fix webhook not triggering 2025-04-09 20:46:53 +07:00
semantic-release-bot
ca3ac64390 chore(release): 1.0.1 [skip ci]
## @revanced/discord-bot [1.0.1](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.0.0...@revanced/discord-bot@1.0.1) (2025-04-09)

### Bug Fixes

* **bots/discord:** attempt to fix sticky messages again ([7564b1a](7564b1a8f0))
2025-04-09 13:35:59 +00:00
semantic-release-bot
5c2429aed7 chore(release): 1.0.1 [skip ci]
## @revanced/bot-websocket-api [1.0.1](https://github.com/revanced/revanced-bots/compare/@revanced/bot-websocket-api@1.0.0...@revanced/bot-websocket-api@1.0.1) (2025-04-09)

### Bug Fixes

* **bots/discord:** attempt to fix sticky messages again ([7564b1a](7564b1a8f0))
2025-04-09 13:35:20 +00:00
PalmDevs
7564b1a8f0 fix(bots/discord): attempt to fix sticky messages again 2025-04-09 20:14:32 +07:00
Palm
5c9f4c6638 ci(release): specify correct permissions for job 2025-04-09 19:53:47 +07:00
Palm
69de750e6a ci(release): use secrets.GITHUB_TOKEN 2025-04-09 19:41:49 +07:00
semantic-release-bot
83f9780f9c chore(release): 1.0.0 [skip ci]
# @revanced/discord-bot 1.0.0 (2025-04-04)

### Bug Fixes

* **bot/discord:** start remove preset timeout for `role-preset` command ([cbf9116](cbf91162e2))
* **bots/discord/commands/eval:** evaluate in current context ([5925d90](5925d90209))
* **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/build:** check if dist dir exists before cleaning ([c06033e](c06033e573))
* **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/utils/duration:** fix specified default unit not working ([d138af4](d138af46d1))
* **bots/discord/utils/duration:** make second the default unit ([5d1af3c](5d1af3c31c))
* **bots/discord:** add GuildMember partial ([8e3946a](8e3946a666))
* **bots/discord:** allow access to `context` in `/eval` and await result ([99f65f0](99f65f07f5))
* **bots/discord:** always true check causing no messages to be scanned ([98ec37b](98ec37b5d1))
* **bots/discord:** apply active role presets if members rejoin ([f50b26b](f50b26b82d))
* **bots/discord:** attempt to fix stuck sticky message timeouts ([3ed5bd1](3ed5bd11ac))
* **bots/discord:** await when putting entries into db ([4da6175](4da6175cf5))
* **bots/discord:** broken regex when prefix set to special characters ([ab62e55](ab62e55e76))
* **bots/discord:** check token before connecting to bot api ([f3e4408](f3e4408aa2))
* **bots/discord:** ci issues causing database to not be auto generated ([673aa18](673aa189be))
* **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:** contextify object before sandboxing ([062735f](062735f6d5))
* **bots/discord:** correct permission check logic ([dd8872c](dd8872c027))
* **bots/discord:** correct sticky messages logic ([de8bef6](de8bef6520))
* **bots/discord:** correct timer active condition for sticky messages ([96065ff](96065ff175))
* **bots/discord:** correct whitelist logic ([49c29be](49c29bebfb))
* **bots/discord:** cross-device link build errors ([38c0699](38c06997b4))
* **bots/discord:** decrease length of an option in `ban` command ([22d3eea](22d3eea88d))
* **bots/discord:** delete expired appliedPresets entries after unapplying ([14c98e8](14c98e87df))
* **bots/discord:** deployment runtime errors due to minification ([a60c60c](a60c60c0f9))
* **bots/discord:** do decancer after resetting nickname ([0303fe3](0303fe3e36))
* **bots/discord:** do not remove unrelated reactions ([031fd26](031fd26b26))
* **bots/discord:** don't refresh timer if force timer is active for sticky messages ([4abac0c](4abac0c890))
* **bots/discord:** filter out text triggers correctly from image-only scans ([8c0dd67](8c0dd67d03))
* **bots/discord:** fix freeze on prod builds ([8efb549](8efb549453))
* **bots/discord:** fix get response logic ([3261294](3261294822))
* **bots/discord:** fix reload not working ([11582d5](11582d5034))
* **bots/discord:** follow-up if reply is already sent when error ([f75060b](f75060bc9c))
* **bots/discord:** give only removed roles for role presets ([522ad28](522ad28fd8))
* **bots/discord:** hanging process when disconnecting from API too many times ([d31616e](d31616ebcb))
* **bots/discord:** import `config` from context ([763ef25](763ef253f9))
* **bots/discord:** make `/eval` work ([eaa25f2](eaa25f2eb5))
* **bots/discord:** messed up file name for `unmute` command ([399dca7](399dca7153))
* **bots/discord:** only check for member permissions when specified while correcting responses ([b79a1c7](b79a1c7575))
* **bots/discord:** open database as read-write ([c366840](c36684091d))
* **bots/discord:** owners cannot bypass checks on some commands ([39cba97](39cba97341))
* **bots/discord:** parse larger units of durations, fix wrong timestamp in mod embed ([6c8dce0](6c8dce0593))
* **bots/discord:** persist changes in context for eval command ([5b4965d](5b4965dcc7))
* **bots/discord:** provide discord token for `reload` command ([dd21a5a](dd21a5abad))
* **bots/discord:** remove auto-generated files ([fb8af00](fb8af00866))
* **bots/discord:** remove bad text channel checks ([f5939e2](f5939e2528))
* **bots/discord:** remove redundant footer for response embeds ([412e003](412e00317d))
* **bots/discord:** remove usage of macros ([7f27c56](7f27c5607c))
* **bots/discord:** remove useless feature ([d830e48](d830e48bc2))
* **bots/discord:** replace duration parser with a library ([94c4fed](94c4fedc06))
* **bots/discord:** reset counter when reconnected to api, redo message scan filter logic ([d234d79](d234d79310))
* **bots/discord:** revert dist denesting, fixes config not found ([0d4898d](0d4898dae8))
* **bots/discord:** send right response for after regexes ([a7688fa](a7688fa9b9))
* **bots/discord:** set the `label` property correctly for message scans ([6d463df](6d463df586))
* **bots/discord:** set timeout for eligible mutes to unmute faster ([1f5c5a9](1f5c5a92a6))
* **bots/discord:** some configuration values not applying after running `/reload` ([a976dd2](a976dd2acc))
* **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))
* **bots/discord:** wrong database schema path ([875bd20](875bd209b2))
* 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))
* fix typings and formatting ([479812e](479812e199))
* ignore message if there's no content ([3cbebc2](3cbebc2842))
* move modules to `/bots` ([cd7156e](cd7156e792))
* other small issues ([bc437a5](bc437a5ec7))
* run projects with `--bun` ([bb2182e](bb2182e707))
* trainAI not using the bin location ([bd29943](bd2994388b))
* update repo url ([a21aa34](a21aa348d7))

### 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:** add `reload` command ([6875b32](6875b32fd0))
* **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 `replyToReplied` option in response config ([27662ed](27662ed91a))
* **bots/discord:** add `train` commands ([ee90ef2](ee90ef247b))
* **bots/discord:** add a better way to manage databases ([a68d726](a68d726875))
* **bots/discord:** add code to actually scan text files correctly ([80aeb19](80aeb19020))
* **bots/discord:** add default durations for moderation commands ([27d3b39](27d3b39209))
* **bots/discord:** add more fallbacks for decancering ([2e1e009](2e1e009b42))
* **bots/discord:** add more month aliases to duration parser ([c2009ca](c2009ca6d4))
* **bots/discord:** add more options for curing, fix default regex ([1a4ec1e](1a4ec1ece8))
* **bots/discord:** add source ([f9d50a0](f9d50a0a6b))
* **bots/discord:** add sticky messages ([bf66155](bf661556e1))
* **bots/discord:** add trigger to context for eval ([b5f4097](b5f4097538))
* **bots/discord:** allow admins to bypass permission checks ([620f933](620f9339f0))
* **bots/discord:** blacklist and whitelist for filters ([cdb6001](cdb6001955))
* **bots/discord:** cure on every event ([8ff6086](8ff6086028))
* **bots/discord:** don't nest builds in src directory, autogen db when missing ([4834685](4834685186))
* **bots/discord:** framework changes and new features ([646ec8d](646ec8da87))
* **bots/discord:** improve admin commands ([0346741](0346741188))
* **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))
* **bots/discord:** update example config file ([bc9951c](bc9951c9b5))
* **bots/discord:** update to newer command definition framework ([97f2795](97f2795df4))
* 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-bots/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
2025-04-04 17:24:04 +00:00
semantic-release-bot
5d862401a0 chore(release): 1.0.0 [skip ci]
# @revanced/bot-websocket-api 1.0.0 (2025-04-04)

### Bug Fixes

* **apis/websocket:** also include tesseract core files in build ([7dfbf6c](7dfbf6c92c))
* **apis/websocket:** attempt to fix missing remote address ([9b2888b](9b2888b944))
* **apis/websocket:** build and runtime issues ([89d8ab1](89d8ab1ee5))
* **apis/websocket:** builds not working due to dynamic import requirement ([fc7be22](fc7be22c6c))
* **apis/websocket:** don't bundle `tesseract.js` ([51a6fb6](51a6fb65f0))
* **apis/websocket:** fix forever stuck Promise ([168f40d](168f40def6))
* **apis/websocket:** fix undefined error ([2f03800](2f03800c61))
* **apis/websocket:** hardcoded paths in tesseract worker builds ([38e00eb](38e00eb4e5))
* **apis/websocket:** improve logging and error handling ([b6cbe9d](b6cbe9d64c))
* **bots/discord:** hanging process when disconnecting from API too many times ([d31616e](d31616ebcb))
* fix typings and formatting ([479812e](479812e199))
* other small issues ([bc437a5](bc437a5ec7))
* remove error cb handling for `socket.send()` calls ([29544d4](29544d4e01))
* run projects with `--bun` ([bb2182e](bb2182e707))
* **types:** fix issues with typings ([669e24c](669e24ca81))
* update repo url ([a21aa34](a21aa348d7))

### chore

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

### Features

* **apis/websocket:** clear old client sessions and instances ([43bd0a0](43bd0a021c))
* **apis/websocket:** return `true` for data on a `TrainedMessage` packet ([65add4d](65add4dfee))
* **packages/shared:** add logger factory ([17c6be7](17c6be7bee))

### 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
2025-04-04 17:23:29 +00:00
Palm
91bac934ab chore: merge dev to main 2025-04-05 00:22:22 +07:00
semantic-release-bot
d74fba4092 chore(release): 1.0.0-dev.38 [skip ci]
# @revanced/discord-bot [1.0.0-dev.38](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.0.0-dev.37...@revanced/discord-bot@1.0.0-dev.38) (2025-04-04)

### Bug Fixes

* run projects with `--bun` ([bb2182e](bb2182e707))
2025-04-04 16:56:56 +00:00
semantic-release-bot
ce76c5f08e chore(release): 1.0.0-dev.11 [skip ci]
# @revanced/bot-websocket-api [1.0.0-dev.11](https://github.com/revanced/revanced-bots/compare/@revanced/bot-websocket-api@1.0.0-dev.10...@revanced/bot-websocket-api@1.0.0-dev.11) (2025-04-04)

### Bug Fixes

* **apis/websocket:** attempt to fix missing remote address ([9b2888b](9b2888b944))
* run projects with `--bun` ([bb2182e](bb2182e707))
2025-04-04 16:56:18 +00:00
PalmDevs
bb2182e707 fix: run projects with --bun 2025-04-04 23:55:06 +07:00
PalmDevs
9b2888b944 fix(apis/websocket): attempt to fix missing remote address 2025-04-04 23:55:04 +07:00
PalmDevs
ba1a467e20 chore: update deps 2025-04-04 23:55:02 +07:00
semantic-release-bot
c97fffb32f chore(release): 1.0.0-dev.37 [skip ci]
# @revanced/discord-bot [1.0.0-dev.37](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.0.0-dev.36...@revanced/discord-bot@1.0.0-dev.37) (2025-03-08)

### Bug Fixes

* **bots/discord/utils/duration:** fix specified default unit not working ([d138af4](d138af46d1))
2025-03-08 23:34:30 +00:00
PalmDevs
d138af46d1 fix(bots/discord/utils/duration): fix specified default unit not working 2025-03-09 06:33:21 +07:00
semantic-release-bot
75a57b0e16 chore(release): 1.0.0-dev.36 [skip ci]
# @revanced/discord-bot [1.0.0-dev.36](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.0.0-dev.35...@revanced/discord-bot@1.0.0-dev.36) (2025-03-03)

### Bug Fixes

* **bots/discord/scripts/build:** check if dist dir exists before cleaning ([c06033e](c06033e573))
* **bots/discord/utils/duration:** make second the default unit ([5d1af3c](5d1af3c31c))
* **bots/discord:** add GuildMember partial ([8e3946a](8e3946a666))
* **bots/discord:** decrease length of an option in `ban` command ([22d3eea](22d3eea88d))
* **bots/discord:** delete expired appliedPresets entries after unapplying ([14c98e8](14c98e87df))
* fix typings and formatting ([479812e](479812e199))
* update repo url ([a21aa34](a21aa348d7))

### Features

* **bots/discord:** add more month aliases to duration parser ([c2009ca](c2009ca6d4))
2025-03-03 19:40:39 +00:00
PalmDevs
c06033e573 fix(bots/discord/scripts/build): check if dist dir exists before cleaning 2025-03-04 02:39:08 +07:00
semantic-release-bot
d290417ff3 chore(release): 1.0.0-dev.10 [skip ci]
# @revanced/bot-websocket-api [1.0.0-dev.10](https://github.com/revanced/revanced-bots/compare/@revanced/bot-websocket-api@1.0.0-dev.9...@revanced/bot-websocket-api@1.0.0-dev.10) (2025-03-03)

### Bug Fixes

* fix typings and formatting ([479812e](479812e199))
* update repo url ([a21aa34](a21aa348d7))
2025-03-03 19:36:29 +00:00
PalmDevs
a21aa348d7 fix: update repo url 2025-03-04 02:35:19 +07:00
PalmDevs
479812e199 fix: fix typings and formatting 2025-03-04 02:27:48 +07:00
PalmDevs
f6119946f8 chore: update deps 2025-03-04 02:19:06 +07:00
PalmDevs
5d1af3c31c fix(bots/discord/utils/duration): make second the default unit 2025-03-04 02:17:59 +07:00
PalmDevs
14c98e87df fix(bots/discord): delete expired appliedPresets entries after unapplying 2025-03-04 02:15:19 +07:00
PalmDevs
8e3946a666 fix(bots/discord): add GuildMember partial 2025-03-04 02:09:59 +07:00
PalmDevs
c2009ca6d4 feat(bots/discord): add more month aliases to duration parser 2024-10-30 18:56:54 +07:00
PalmDevs
22d3eea88d fix(bots/discord): decrease length of an option in ban command 2024-10-30 18:50:22 +07:00
semantic-release-bot
14d301eeb4 chore(release): 1.0.0-dev.35 [skip ci]
# @revanced/discord-bot [1.0.0-dev.35](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.34...@revanced/discord-bot@1.0.0-dev.35) (2024-10-17)

### Bug Fixes

* **bots/discord:** fix freeze on prod builds ([8efb549](8efb549453))
2024-10-17 18:34:04 +00:00
PalmDevs
8efb549453 fix(bots/discord): fix freeze on prod builds 2024-10-18 01:32:42 +07:00
PalmDevs
79fea8b286 fix: update patches for dependencies 2024-10-18 00:02:06 +07:00
semantic-release-bot
e798a9ef32 chore(release): 1.0.0-dev.34 [skip ci]
# @revanced/discord-bot [1.0.0-dev.34](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.33...@revanced/discord-bot@1.0.0-dev.34) (2024-10-17)

### Bug Fixes

* **bots/discord:** attempt to fix stuck sticky message timeouts ([3ed5bd1](3ed5bd11ac))
* **bots/discord:** fix reload not working ([11582d5](11582d5034))

### Features

* **bots/discord:** add default durations for moderation commands ([27d3b39](27d3b39209))
* **bots/discord:** cure on every event ([8ff6086](8ff6086028))
2024-10-17 16:56:34 +00:00
PalmDevs
7b5d4fa1a2 chore: update dependencies 2024-10-17 23:55:17 +07:00
PalmDevs
11582d5034 fix(bots/discord): fix reload not working 2024-10-17 23:20:02 +07:00
PalmDevs
488d37e65b fix(packages/shareed): add missing imports 2024-10-17 21:47:14 +07:00
PalmDevs
3ed5bd11ac fix(bots/discord): attempt to fix stuck sticky message timeouts 2024-10-17 21:40:41 +07:00
PalmDevs
8ff6086028 feat(bots/discord): cure on every event 2024-10-17 21:39:05 +07:00
PalmDevs
27d3b39209 feat(bots/discord): add default durations for moderation commands 2024-10-17 21:38:54 +07:00
semantic-release-bot
6e181c0e7f chore(release): 1.0.0-dev.33 [skip ci]
# @revanced/discord-bot [1.0.0-dev.33](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.32...@revanced/discord-bot@1.0.0-dev.33) (2024-09-25)

### Features

* **bots/discord:** add trigger to context for eval ([b5f4097](b5f4097538))
2024-09-25 06:02:32 +00:00
PalmDevs
b5f4097538 feat(bots/discord): add trigger to context for eval 2024-09-25 13:00:53 +07:00
semantic-release-bot
f6d2e25130 chore(release): 1.0.0-dev.32 [skip ci]
# @revanced/discord-bot [1.0.0-dev.32](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.31...@revanced/discord-bot@1.0.0-dev.32) (2024-09-25)

### Bug Fixes

* **bots/discord:** contextify object before sandboxing ([062735f](062735f6d5))
2024-09-25 05:50:49 +00:00
PalmDevs
062735f6d5 fix(bots/discord): contextify object before sandboxing 2024-09-25 12:49:29 +07:00
70 changed files with 2869 additions and 520 deletions

View File

@@ -12,8 +12,10 @@ jobs:
name: Release name: Release
runs-on: ubuntu-latest runs-on: ubuntu-latest
permissions: permissions:
contents: read contents: write # to be able to publish a GitHub release
packages: write issues: write # to be able to comment on released issues
pull-requests: write # to be able to comment on released pull requests
packages: write # to be able to publish GitHub packages
timeout-minutes: 10 timeout-minutes: 10
steps: steps:
- name: Checkout - name: Checkout
@@ -28,7 +30,7 @@ jobs:
uses: actions/cache@v4 uses: actions/cache@v4
with: with:
path: '**/node_modules' path: '**/node_modules'
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lockb') }} key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lock') }}
restore-keys: ${{ runner.os }}-bun- restore-keys: ${{ runner.os }}-bun-
- name: Setup Bun - name: Setup Bun
@@ -48,22 +50,11 @@ jobs:
- name: Setup Docker Buildx - name: Setup Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v3
- name: Build and release - name: Build, release, publish
env: env:
RELEASE_WORKFLOW_STEP: release GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.REPOSITORY_PUSH_ACCESS }}
DOCKER_REGISTRY_USER: ${{ github.repository_owner }} DOCKER_REGISTRY_USER: ${{ github.repository_owner }}
DOCKER_REGISTRY_PASSWORD: ${{ secrets.REPOSITORY_PUSH_ACCESS }} DOCKER_REGISTRY_PASSWORD: ${{ secrets.GITHUB_TOKEN }}
DEBUG: semantic-release:*
run: bunx multi-semantic-release --debug
# We call multi-semantic-release twice to publish in a different step
# An environment variable determines which plugins in the config to run
- name: Trigger Portainer webhooks
if: github.ref == 'refs/heads/main'
env:
RELEASE_WORKFLOW_STEP: publish
GITHUB_TOKEN: ${{ secrets.REPOSITORY_PUSH_ACCESS }}
WEBSOCKET_API_PORTAINER_WEBHOOK_URL: ${{ secrets.WEBSOCKET_API_PORTAINER_WEBHOOK_URL }} WEBSOCKET_API_PORTAINER_WEBHOOK_URL: ${{ secrets.WEBSOCKET_API_PORTAINER_WEBHOOK_URL }}
DISCORD_BOT_PORTAINER_WEBHOOK_URL: ${{ secrets.DISCORD_BOT_PORTAINER_WEBHOOK_URL }} DISCORD_BOT_PORTAINER_WEBHOOK_URL: ${{ secrets.DISCORD_BOT_PORTAINER_WEBHOOK_URL }}
run: bunx multi-semantic-release run: bunx multi-semantic-release

View File

@@ -58,7 +58,7 @@
Continuing the legacy of Vanced Continuing the legacy of Vanced
</p> </p>
# 🤖 ReVanced Helper # 🤖 ReVanced Bots
Bots assisting ReVanced on multiple platforms. Bots assisting ReVanced on multiple platforms.
@@ -67,4 +67,4 @@ Bots assisting ReVanced on multiple platforms.
Thank you for considering! This project is made in TypeScript and we use the [Bun](https://bun.sh) JavaScript runtime. Thank you for considering! This project is made in TypeScript and we use the [Bun](https://bun.sh) JavaScript runtime.
Please refer to the [documentation](./docs) for more information. Please refer to the [documentation](./docs) for more information.
You can find projects under the [`apis`](./apis/), [`bots`](./bots), and [`packages`](./packages/) directories. You can find projects under the [`apis`](./apis/), [`bots`](./bots), and [`packages`](./packages/) directories.

View File

@@ -1,32 +1,28 @@
import defineSubprojectReleaseConfig from '../../semantic-release-config.js' import defineSubprojectReleaseConfig from '../../semantic-release-config.js'
export default defineSubprojectReleaseConfig({ export default defineSubprojectReleaseConfig({
plugins: plugins: [
process.env.RELEASE_WORKFLOW_STEP === 'publish' [
? [ '@codedependant/semantic-release-docker',
[ {
'@semantic-release/exec', dockerImage: 'revanced-bot-websocket-api',
{ dockerRegistry: 'ghcr.io',
publishCmd: 'bun run scripts/trigger-portainer-webhook.ts', dockerProject: 'revanced',
}, dockerContext: '../..',
], dockerPlatform: ['linux/amd64', 'linux/arm64'],
] dockerBuildQuiet: false,
: [ dockerTags: [
[ '{{#if prerelease.[0]}}dev{{else}}main{{/if}}',
'@codedependant/semantic-release-docker', '{{#unless prerelease.[0]}}latest{{/unless}}',
{ '{{version}}',
dockerImage: 'revanced-bot-websocket-api', ],
dockerRegistry: 'ghcr.io', },
dockerProject: 'revanced', ],
dockerContext: '../..', [
dockerPlatform: ['linux/amd64', 'linux/arm64'], '@semantic-release/exec',
dockerBuildQuiet: false, {
dockerTags: [ successCmd: 'bun run scripts/trigger-portainer-webhook.ts',
'{{#if prerelease.[0]}}dev{{else}}main{{/if}}', },
'{{#unless prerelease.[0]}}latest{{/unless}}', ],
'{{version}}', ],
],
},
],
],
}) })

View File

@@ -1,3 +1,76 @@
## @revanced/bot-websocket-api [1.0.2](https://github.com/revanced/revanced-bots/compare/@revanced/bot-websocket-api@1.0.1...@revanced/bot-websocket-api@1.0.2) (2025-06-23)
## @revanced/bot-websocket-api [1.0.1](https://github.com/revanced/revanced-bots/compare/@revanced/bot-websocket-api@1.0.0...@revanced/bot-websocket-api@1.0.1) (2025-04-09)
### Bug Fixes
* **bots/discord:** attempt to fix sticky messages again ([7564b1a](https://github.com/revanced/revanced-bots/commit/7564b1a8f066183df390887ddfd4d73e0baa87ac))
## @revanced/bot-websocket-api [1.0.1](https://github.com/revanced/revanced-bots/compare/@revanced/bot-websocket-api@1.0.0...@revanced/bot-websocket-api@1.0.1) (2025-04-09)
### Bug Fixes
* **bots/discord:** attempt to fix sticky messages again ([7564b1a](https://github.com/revanced/revanced-bots/commit/7564b1a8f066183df390887ddfd4d73e0baa87ac))
# @revanced/bot-websocket-api 1.0.0 (2025-04-04)
### Bug Fixes
* **apis/websocket:** also include tesseract core files in build ([7dfbf6c](https://github.com/revanced/revanced-bots/commit/7dfbf6c92c49100954fa4aca471dce4ab9fd9565))
* **apis/websocket:** attempt to fix missing remote address ([9b2888b](https://github.com/revanced/revanced-bots/commit/9b2888b944ea1d61d31aa5df3536768e9a2dadf8))
* **apis/websocket:** build and runtime issues ([89d8ab1](https://github.com/revanced/revanced-bots/commit/89d8ab1ee58278a9a96cdc31c679d0a0a0d865af))
* **apis/websocket:** builds not working due to dynamic import requirement ([fc7be22](https://github.com/revanced/revanced-bots/commit/fc7be22c6c15974c7394790e93de2a23a6627153))
* **apis/websocket:** don't bundle `tesseract.js` ([51a6fb6](https://github.com/revanced/revanced-bots/commit/51a6fb65f0df3409eacffb297430840a0e326989))
* **apis/websocket:** fix forever stuck Promise ([168f40d](https://github.com/revanced/revanced-bots/commit/168f40def64ca213cd2b549f4bafed4c0e1e3695))
* **apis/websocket:** fix undefined error ([2f03800](https://github.com/revanced/revanced-bots/commit/2f03800c61c00e59e512567d273a195e605d6736))
* **apis/websocket:** hardcoded paths in tesseract worker builds ([38e00eb](https://github.com/revanced/revanced-bots/commit/38e00eb4e59c763bd74d27b9b9b482ea66e4dcf4))
* **apis/websocket:** improve logging and error handling ([b6cbe9d](https://github.com/revanced/revanced-bots/commit/b6cbe9d64c01ff11feab8351fb801bc1aee48325))
* **bots/discord:** hanging process when disconnecting from API too many times ([d31616e](https://github.com/revanced/revanced-bots/commit/d31616ebcba6f1dcd8bde183bcb8d1adb1501b61))
* fix typings and formatting ([479812e](https://github.com/revanced/revanced-bots/commit/479812e199b52cdb295a5746e0767306afab3413))
* other small issues ([bc437a5](https://github.com/revanced/revanced-bots/commit/bc437a5ec7ce1d339094d608e2a61ac5f460c163))
* remove error cb handling for `socket.send()` calls ([29544d4](https://github.com/revanced/revanced-bots/commit/29544d4e0127173465796b7e3c62161f4db59c8b))
* run projects with `--bun` ([bb2182e](https://github.com/revanced/revanced-bots/commit/bb2182e707fa40c555d56138972eeea28f1b3cf9))
* **types:** fix issues with typings ([669e24c](https://github.com/revanced/revanced-bots/commit/669e24ca8103ea051b4e61160dd0f978e36707ea))
* update repo url ([a21aa34](https://github.com/revanced/revanced-bots/commit/a21aa348d7f32cd0ee65b371e9594520c0a9d3f1))
### chore
* fix more build issues ([77fefb9](https://github.com/revanced/revanced-bots/commit/77fefb9bef286a22f40a4d76b79c64fcc5a2467f))
### Features
* **apis/websocket:** clear old client sessions and instances ([43bd0a0](https://github.com/revanced/revanced-bots/commit/43bd0a021cd885a3d74a1f307ec2935e81d17458))
* **apis/websocket:** return `true` for data on a `TrainedMessage` packet ([65add4d](https://github.com/revanced/revanced-bots/commit/65add4dfeed2fa067c2c8e2377f7d01d505ade54))
* **packages/shared:** add logger factory ([17c6be7](https://github.com/revanced/revanced-bots/commit/17c6be7bee5b5c24fd4a5279e73374b0bb7a6229))
### 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
# @revanced/bot-websocket-api [1.0.0-dev.11](https://github.com/revanced/revanced-bots/compare/@revanced/bot-websocket-api@1.0.0-dev.10...@revanced/bot-websocket-api@1.0.0-dev.11) (2025-04-04)
### Bug Fixes
* **apis/websocket:** attempt to fix missing remote address ([9b2888b](https://github.com/revanced/revanced-bots/commit/9b2888b944ea1d61d31aa5df3536768e9a2dadf8))
* run projects with `--bun` ([bb2182e](https://github.com/revanced/revanced-bots/commit/bb2182e707fa40c555d56138972eeea28f1b3cf9))
# @revanced/bot-websocket-api [1.0.0-dev.10](https://github.com/revanced/revanced-bots/compare/@revanced/bot-websocket-api@1.0.0-dev.9...@revanced/bot-websocket-api@1.0.0-dev.10) (2025-03-03)
### Bug Fixes
* fix typings and formatting ([479812e](https://github.com/revanced/revanced-bots/commit/479812e199b52cdb295a5746e0767306afab3413))
* update repo url ([a21aa34](https://github.com/revanced/revanced-bots/commit/a21aa348d7f32cd0ee65b371e9594520c0a9d3f1))
# @revanced/bot-websocket-api [1.0.0-dev.9](https://github.com/revanced/revanced-helper/compare/@revanced/bot-websocket-api@1.0.0-dev.8...@revanced/bot-websocket-api@1.0.0-dev.9) (2024-08-03) # @revanced/bot-websocket-api [1.0.0-dev.9](https://github.com/revanced/revanced-helper/compare/@revanced/bot-websocket-api@1.0.0-dev.8...@revanced/bot-websocket-api@1.0.0-dev.9) (2024-08-03)

View File

@@ -14,4 +14,4 @@ WORKDIR /app
COPY --from=build /build/apis/websocket/dist /app COPY --from=build /build/apis/websocket/dist /app
USER 1000:1000 USER 1000:1000
ENTRYPOINT [ "bun", "run", "index.js" ] ENTRYPOINT [ "bun", "--bun", "run", "index.js" ]

View File

@@ -2,7 +2,7 @@
"name": "@revanced/bot-websocket-api", "name": "@revanced/bot-websocket-api",
"type": "module", "type": "module",
"private": true, "private": true,
"version": "1.0.0-dev.9", "version": "1.0.2",
"description": "🧦 WebSocket API server for bots assisting ReVanced", "description": "🧦 WebSocket API server for bots assisting ReVanced",
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
@@ -13,7 +13,7 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/revanced/revanced-helper.git", "url": "git+https://github.com/revanced/revanced-bots.git",
"directory": "apis/websocket" "directory": "apis/websocket"
}, },
"author": "Palm <contact@palmdevs.me> (https://palmdevs.me)", "author": "Palm <contact@palmdevs.me> (https://palmdevs.me)",
@@ -23,18 +23,18 @@
], ],
"license": "GPL-3.0-or-later", "license": "GPL-3.0-or-later",
"bugs": { "bugs": {
"url": "https://github.com/revanced/revanced-helper/issues" "url": "https://github.com/revanced/revanced-bots/issues"
}, },
"homepage": "https://github.com/revanced/revanced-helper#readme", "homepage": "https://github.com/revanced/revanced-bots#readme",
"dependencies": { "dependencies": {
"@revanced/bot-shared": "workspace:*", "@revanced/bot-shared": "workspace:*",
"@sapphire/async-queue": "^1.5.2", "@sapphire/async-queue": "^1.5.5",
"chalk": "^5.3.0", "chalk": "^5.4.1",
"tesseract.js": "^5.1.0", "tesseract.js": "^6.0.1",
"ws": "^8.17.1" "ws": "^8.18.2"
}, },
"devDependencies": { "devDependencies": {
"@types/ws": "^8.5.10", "@types/ws": "^8.18.1",
"typed-emitter": "^2.1.0" "typed-emitter": "^2.1.0"
} }
} }

View File

@@ -1,10 +1,10 @@
import { createLogger } from '@revanced/bot-shared' import { createLogger } from '@revanced/bot-shared'
import { cp, rm } from 'fs/promises' import { cp, exists, rm } from 'fs/promises'
const logger = createLogger() const logger = createLogger()
logger.info('Cleaning previous build...') logger.info('Cleaning previous build...')
await rm('./dist', { recursive: true }) if (await exists('./dist')) await rm('./dist', { recursive: true })
logger.info('Building WebSocket API...') logger.info('Building WebSocket API...')
await Bun.build({ await Bun.build({

View File

@@ -1,15 +1,14 @@
import { EventEmitter } from 'events'
import { import {
ClientOperation, ClientOperation,
DisconnectReason, DisconnectReason,
type Packet,
ServerOperation,
deserializePacket, deserializePacket,
isClientPacket, isClientPacket,
type Packet,
ServerOperation,
serializePacket, serializePacket,
uncapitalize, uncapitalize,
} from '@revanced/bot-shared' } from '@revanced/bot-shared'
import { EventEmitter } from 'events'
import type TypedEmitter from 'typed-emitter' import type TypedEmitter from 'typed-emitter'
import type { RawData, WebSocket } from 'ws' import type { RawData, WebSocket } from 'ws'
@@ -100,7 +99,7 @@ export default class Client {
// @ts-expect-error TypeScript doesn't know that the above line will negate the type enough // @ts-expect-error TypeScript doesn't know that the above line will negate the type enough
packet, packet,
) )
} catch (e) { } catch (_e) {
// TODO: add error fields to sent packet so we can log what went wrong // TODO: add error fields to sent packet so we can log what went wrong
this.disconnect(DisconnectReason.InvalidPacket) this.disconnect(DisconnectReason.InvalidPacket)
} }
@@ -110,7 +109,7 @@ export default class Client {
protected _toBuffer(data: RawData) { protected _toBuffer(data: RawData) {
if (data instanceof Buffer) return data if (data instanceof Buffer) return data
if (data instanceof ArrayBuffer) return Buffer.from(data) if (data instanceof ArrayBuffer) return Buffer.from(data)
return Buffer.concat(data) return Buffer.concat(data as Uint8Array[])
} }
} }

View File

@@ -1,8 +1,7 @@
import { OEM, createWorker as createTesseractWorker } from 'tesseract.js'
import { join as joinPath } from 'path'
import { createLogger } from '@revanced/bot-shared' import { createLogger } from '@revanced/bot-shared'
import { exists as pathExists } from 'fs/promises' import { exists as pathExists } from 'fs/promises'
import { join as joinPath } from 'path'
import { createWorker as createTesseractWorker, OEM } from 'tesseract.js'
import { getConfig } from './utils/config' import { getConfig } from './utils/config'
export const config = getConfig() export const config = getConfig()

View File

@@ -1,12 +1,11 @@
import type { ClientOperation } from '@revanced/bot-shared' import type { ClientOperation, Logger } from '@revanced/bot-shared'
import type { Logger } from '@revanced/bot-shared'
import type { Worker as TesseractWorker } from 'tesseract.js' import type { Worker as TesseractWorker } from 'tesseract.js'
import type { ClientPacketObject } from '../classes/Client' import type { ClientPacketObject } from '../classes/Client'
import type { WitMessageResponse } from '../context' import type { WitMessageResponse } from '../context'
import type { Config } from '../utils/config' import type { Config } from '../utils/config'
export { default as parseTextEventHandler } from './parseText'
export { default as parseImageEventHandler } from './parseImage' export { default as parseImageEventHandler } from './parseImage'
export { default as parseTextEventHandler } from './parseText'
export { default as trainMessageEventHandler } from './trainMessage' export { default as trainMessageEventHandler } from './trainMessage'
export type EventHandler<POp extends ClientOperation> = ( export type EventHandler<POp extends ClientOperation> = (

View File

@@ -1,6 +1,5 @@
import { type ClientOperation, ServerOperation } from '@revanced/bot-shared' import { type ClientOperation, ServerOperation } from '@revanced/bot-shared'
import { AsyncQueue } from '@sapphire/async-queue' import { AsyncQueue } from '@sapphire/async-queue'
import type { EventHandler } from '.' import type { EventHandler } from '.'
const queue = new AsyncQueue() const queue = new AsyncQueue()

View File

@@ -1,5 +1,4 @@
import { type ClientOperation, ServerOperation } from '@revanced/bot-shared' import { type ClientOperation, ServerOperation } from '@revanced/bot-shared'
import type { EventHandler } from '.' import type { EventHandler } from '.'
const parseTextEventHandler: EventHandler<ClientOperation.ParseText> = async (packet, { wit, logger }) => { const parseTextEventHandler: EventHandler<ClientOperation.ParseText> = async (packet, { wit, logger }) => {

View File

@@ -1,5 +1,4 @@
import { type ClientOperation, ServerOperation } from '@revanced/bot-shared' import { type ClientOperation, ServerOperation } from '@revanced/bot-shared'
import type { EventHandler } from '.' import type { EventHandler } from '.'
const trainMessageEventHandler: EventHandler<ClientOperation.TrainMessage> = async (packet, { wit, logger }) => { const trainMessageEventHandler: EventHandler<ClientOperation.TrainMessage> = async (packet, { wit, logger }) => {

View File

@@ -1,14 +1,10 @@
import { inspect as inspectObject } from 'util'
import Client from './classes/Client'
import { type EventContext, parseImageEventHandler, parseTextEventHandler, trainMessageEventHandler } from './events'
import { DisconnectReason, HumanizedDisconnectReason } from '@revanced/bot-shared' import { DisconnectReason, HumanizedDisconnectReason } from '@revanced/bot-shared'
import { createServer } from 'http' import { createServer } from 'http'
import { inspect as inspectObject } from 'util'
import { type WebSocket, WebSocketServer } from 'ws' import { type WebSocket, WebSocketServer } from 'ws'
import Client from './classes/Client'
import { config, logger, tesseract, wit } from './context' import { config, logger, tesseract, wit } from './context'
import { type EventContext, parseImageEventHandler, parseTextEventHandler, trainMessageEventHandler } from './events'
// Load config, init logger, check environment // Load config, init logger, check environment
@@ -56,12 +52,13 @@ const wss = new WebSocketServer({
wss.on('connection', async (socket, request) => { wss.on('connection', async (socket, request) => {
try { try {
if (!request.socket.remoteAddress) { const addrInfo = request.socket.address()
if (!('address' in addrInfo)) {
socket.close() socket.close()
return logger.warn('Connection failed because client is missing remote address') return logger.warn('Connection failed because client is missing remote address. addrInfo =', addrInfo)
} }
const id = `${request.socket.remoteAddress}:${request.socket.remotePort}` const id = `${addrInfo.address}:${addrInfo.port}`
if (clientIds.has(id)) { if (clientIds.has(id)) {
logger.warn(`Client ${id} already connected, disconnecting old session`) logger.warn(`Client ${id} already connected, disconnecting old session`)

View File

@@ -1,6 +1,20 @@
{ {
"$schema": "https://biomejs.dev/schemas/1.8.2/schema.json", "$schema": "https://biomejs.dev/schemas/2.0.5/schema.json",
"organizeImports": { "assist": {
"actions": {
"source": {
"organizeImports": {
"level": "on",
"options": {
"groups": [
{
"type": false
}
]
}
}
}
},
"enabled": true "enabled": true
}, },
"linter": { "linter": {
@@ -24,7 +38,15 @@
}, },
"useNumberNamespace": { "useNumberNamespace": {
"level": "off" "level": "off"
} },
"noParameterAssign": "error",
"useAsConstAssertion": "error",
"useDefaultParameterLast": "error",
"useSelfClosingElements": "error",
"useSingleVarDeclarator": "error",
"noUnusedTemplateLiteral": "error",
"noInferrableTypes": "error",
"noUselessElse": "error"
} }
} }
}, },
@@ -54,7 +76,12 @@
}, },
"files": { "files": {
"ignoreUnknown": true, "ignoreUnknown": true,
"include": ["*.js", "*.json", "*.ts"], "includes": [
"ignore": ["dist/**/*", "node_modules/**/*"] "**/*.js",
"**/*.json",
"**/*.ts",
"!**/dist/**/*",
"!**/node_modules/**/*"
]
} }
} }

View File

@@ -1,32 +1,28 @@
import defineSubprojectReleaseConfig from '../../semantic-release-config.js' import defineSubprojectReleaseConfig from '../../semantic-release-config.js'
export default defineSubprojectReleaseConfig({ export default defineSubprojectReleaseConfig({
plugins: plugins: [
process.env.RELEASE_WORKFLOW_STEP === 'publish' [
? [ '@codedependant/semantic-release-docker',
[ {
'@semantic-release/exec', dockerImage: 'revanced-bot-discord',
{ dockerRegistry: 'ghcr.io',
publishCmd: 'bun run scripts/trigger-portainer-webhook.ts', dockerProject: 'revanced',
}, dockerContext: '../..',
], dockerPlatform: ['linux/amd64', 'linux/arm64'],
] dockerBuildQuiet: false,
: [ dockerTags: [
[ '{{#if prerelease.[0]}}dev{{else}}main{{/if}}',
'@codedependant/semantic-release-docker', '{{#unless prerelease.[0]}}latest{{/unless}}',
{ '{{version}}',
dockerImage: 'revanced-bot-discord', ],
dockerRegistry: 'ghcr.io', },
dockerProject: 'revanced', ],
dockerContext: '../..', [
dockerPlatform: ['linux/amd64', 'linux/arm64'], '@semantic-release/exec',
dockerBuildQuiet: false, {
dockerTags: [ successCmd: 'bun run scripts/trigger-portainer-webhook.ts',
'{{#if prerelease.[0]}}dev{{else}}main{{/if}}', },
'{{#unless prerelease.[0]}}latest{{/unless}}', ],
'{{version}}', ],
],
},
],
],
}) })

View File

@@ -1,3 +1,301 @@
## @revanced/discord-bot [1.2.2](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.2.1...@revanced/discord-bot@1.2.2) (2025-06-10)
### Bug Fixes
* **bots/discord:** use intervals for checking expired presets ([6e89b87](https://github.com/revanced/revanced-bots/commit/6e89b874cdfee8a1c215559271c741f43ba578ce))
## @revanced/discord-bot [1.2.1](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.2.0...@revanced/discord-bot@1.2.1) (2025-05-02)
### Bug Fixes
* **bots/discord:** fix timeout overflow check for role presets ([495f686](https://github.com/revanced/revanced-bots/commit/495f686292ebdcf51902c1dc75ac1510d7fdbd9c))
# @revanced/discord-bot [1.2.0](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.1.2...@revanced/discord-bot@1.2.0) (2025-05-02)
### Features
* **bots/discord:** switch duration parser to `@sapphire/duration` ([04ce825](https://github.com/revanced/revanced-bots/commit/04ce8252c05a23dbb4a91fded4f1a3d63b5c8a64))
## @revanced/discord-bot [1.1.2](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.1.1...@revanced/discord-bot@1.1.2) (2025-04-16)
### Bug Fixes
* **bots/discord/commands/admin/reload:** fix type error ([3908854](https://github.com/revanced/revanced-bots/commit/3908854fe090dda67b0d90225ab76f75e95db4c0))
* **bots/discord/commands/moderation:** check if timeout amount is safe in role-preset commands ([0c1382c](https://github.com/revanced/revanced-bots/commit/0c1382c55856ed1e54c9e53dbb37e9297c5da37c))
* **bots/discord:** replace use of deprecated `options.ephemeral` in replies ([31e5cf7](https://github.com/revanced/revanced-bots/commit/31e5cf7fc5c7cd0c6ca3b1f3b9410a88b95d8273))
## @revanced/discord-bot [1.1.1](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.1.0...@revanced/discord-bot@1.1.1) (2025-04-14)
### Bug Fixes
* **bots/discord:** fix sticky msg force timer always starting, add more logging ([cb4dc42](https://github.com/revanced/revanced-bots/commit/cb4dc42dfab8cf9821b03316cf56b405abd497ae))
# @revanced/discord-bot [1.1.0](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.0.4...@revanced/discord-bot@1.1.0) (2025-04-14)
### Features
* **bots/discord:** delete and send sticky msg concurrently, add more logging ([247a00f](https://github.com/revanced/revanced-bots/commit/247a00f57fc2a45fe828cc41e6f0e38e67e83a20))
## @revanced/discord-bot [1.0.4](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.0.3...@revanced/discord-bot@1.0.4) (2025-04-14)
### Bug Fixes
* **bots/discord:** fix sticky messages logic again ([aa7501c](https://github.com/revanced/revanced-bots/commit/aa7501c3097a790265e4ea624d07c4a9c3c1b908))
* **bots/discord:** remove expired presets from db if unapplying is not possible ([9d705e5](https://github.com/revanced/revanced-bots/commit/9d705e580c05d8b25df6f845d3aac747adaca116))
## @revanced/discord-bot [1.0.3](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.0.2...@revanced/discord-bot@1.0.3) (2025-04-09)
### Bug Fixes
* **bots/discord:** attempt to fix sticky messages one last time ([65288ec](https://github.com/revanced/revanced-bots/commit/65288ec4242b32d0b5e213b3d7af602bb9a829ca))
## @revanced/discord-bot [1.0.2](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.0.1...@revanced/discord-bot@1.0.2) (2025-04-09)
## @revanced/discord-bot [1.0.1](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.0.0...@revanced/discord-bot@1.0.1) (2025-04-09)
### Bug Fixes
* **bots/discord:** attempt to fix sticky messages again ([7564b1a](https://github.com/revanced/revanced-bots/commit/7564b1a8f066183df390887ddfd4d73e0baa87ac))
# @revanced/discord-bot 1.0.0 (2025-04-04)
### Bug Fixes
* **bot/discord:** start remove preset timeout for `role-preset` command ([cbf9116](https://github.com/revanced/revanced-bots/commit/cbf91162e27dd4c1ecb976927ab708f1d882abca))
* **bots/discord/commands/eval:** evaluate in current context ([5925d90](https://github.com/revanced/revanced-bots/commit/5925d902095acef5f6396ca03583a9cbb0862498))
* **bots/discord/commands/mute:** use existing `parseDuration` util function' ([3e07429](https://github.com/revanced/revanced-bots/commit/3e07429664f7dbb6ce653083e0adb1a232737fde))
* **bots/discord/commands/unmute:** fix option description and embeds ([7fdf8c0](https://github.com/revanced/revanced-bots/commit/7fdf8c0dc722e21fe5a3ad6ef8d3a306ef85f532))
* **bots/discord/commands:** minor issues ([3b2596e](https://github.com/revanced/revanced-bots/commit/3b2596e748cf2cde1500ef2ded55f0faabc2c272))
* **bots/discord/commands:** refactor and add checks ([a2bf3ea](https://github.com/revanced/revanced-bots/commit/a2bf3eade99b46f9ffb55d45b8caf1bcf3d22a9b))
* **bots/discord/database:** fix schema for role presets ([4aa138a](https://github.com/revanced/revanced-bots/commit/4aa138a9af8db7093ef637470fcfdea1f5341236))
* **bots/discord/scripts/build:** check if dist dir exists before cleaning ([c06033e](https://github.com/revanced/revanced-bots/commit/c06033e5730f82438e8052b9b519a8f8e2d25437))
* **bots/discord/scripts:** unintentional escaping on windows ([09dc706](https://github.com/revanced/revanced-bots/commit/09dc70632da0597fdb26677acee3f6fccbb2b9b5))
* **bots/discord/utils/discord/embeds:** set thumbnail on moderation embeds ([b056291](https://github.com/revanced/revanced-bots/commit/b056291ad0f2e2eac5eec8aa71f15dbc769aa0f9))
* **bots/discord/utils/discord/rolePresets:** correct property access for presets ([4c6ad11](https://github.com/revanced/revanced-bots/commit/4c6ad11be30c1d6af97c4ae40fc62d05fa7bdd57))
* **bots/discord/utils/discord:** add `moderation` module related functions ([7e8270f](https://github.com/revanced/revanced-bots/commit/7e8270f7d260322e1950e058b221ab088bd595d0))
* **bots/discord/utils/duration:** fix empty string returning with duration is 0 ([83c314e](https://github.com/revanced/revanced-bots/commit/83c314ef5f721abc355272db0e4c182dcfe5d943))
* **bots/discord/utils/duration:** fix specified default unit not working ([d138af4](https://github.com/revanced/revanced-bots/commit/d138af46d1f25a11b6f8ab3790ecaa70b1d716a9))
* **bots/discord/utils/duration:** make second the default unit ([5d1af3c](https://github.com/revanced/revanced-bots/commit/5d1af3c31c3379b6a13684dfb07583737908c8aa))
* **bots/discord:** add GuildMember partial ([8e3946a](https://github.com/revanced/revanced-bots/commit/8e3946a66602838715787090008c7bfaf72b67e9))
* **bots/discord:** allow access to `context` in `/eval` and await result ([99f65f0](https://github.com/revanced/revanced-bots/commit/99f65f07f5f8830c6e8ea4ae171e986af4d3f1f6))
* **bots/discord:** always true check causing no messages to be scanned ([98ec37b](https://github.com/revanced/revanced-bots/commit/98ec37b5d18cade85270ab83b0ed0abe41244dd9))
* **bots/discord:** apply active role presets if members rejoin ([f50b26b](https://github.com/revanced/revanced-bots/commit/f50b26b82d66c88fd1dbb8c07d77c177c0e781df))
* **bots/discord:** attempt to fix stuck sticky message timeouts ([3ed5bd1](https://github.com/revanced/revanced-bots/commit/3ed5bd11acc3b4fbd57b0d632c68eb9f77365b8a))
* **bots/discord:** await when putting entries into db ([4da6175](https://github.com/revanced/revanced-bots/commit/4da6175cf58b1fa6144bdc71ec806766d32c1025))
* **bots/discord:** broken regex when prefix set to special characters ([ab62e55](https://github.com/revanced/revanced-bots/commit/ab62e55e76005f5999d7413d1158e54053f28d1f))
* **bots/discord:** check token before connecting to bot api ([f3e4408](https://github.com/revanced/revanced-bots/commit/f3e4408aa28fb6a9d21365af8c1bea3d07b481de))
* **bots/discord:** ci issues causing database to not be auto generated ([673aa18](https://github.com/revanced/revanced-bots/commit/673aa189bef1009a3e32ba3b1291a5ee84f2def3))
* **bots/discord:** clear role presets after they expire ([faa81f4](https://github.com/revanced/revanced-bots/commit/faa81f4d887eaeae809651f5b68187d033a260f2))
* **bots/discord:** connect to discord API even if initial bot API connection fails ([6658b58](https://github.com/revanced/revanced-bots/commit/6658b582dbeba7e072a7a04c4efa255e7f634aef))
* **bots/discord:** contextify object before sandboxing ([062735f](https://github.com/revanced/revanced-bots/commit/062735f6d552890404d6192244c51a11b0709580))
* **bots/discord:** correct permission check logic ([dd8872c](https://github.com/revanced/revanced-bots/commit/dd8872c027c7e7e1a00f38d659b4d6e79274238c))
* **bots/discord:** correct sticky messages logic ([de8bef6](https://github.com/revanced/revanced-bots/commit/de8bef6520d53a1299f0478458320a7eb75c5e1d))
* **bots/discord:** correct timer active condition for sticky messages ([96065ff](https://github.com/revanced/revanced-bots/commit/96065ff17584ff99a56ca5008327863ca5a7852b))
* **bots/discord:** correct whitelist logic ([49c29be](https://github.com/revanced/revanced-bots/commit/49c29bebfbe348ae4e2cc1b3a83bfa41eb26ccd1))
* **bots/discord:** cross-device link build errors ([38c0699](https://github.com/revanced/revanced-bots/commit/38c06997b4d0f7bb3f1e62618a5e3f088c522e30))
* **bots/discord:** decrease length of an option in `ban` command ([22d3eea](https://github.com/revanced/revanced-bots/commit/22d3eea88d532792c1237d1a1ab18bc02e57816a))
* **bots/discord:** delete expired appliedPresets entries after unapplying ([14c98e8](https://github.com/revanced/revanced-bots/commit/14c98e87df1ec4fd762bbc48ca4c06470cb110a2))
* **bots/discord:** deployment runtime errors due to minification ([a60c60c](https://github.com/revanced/revanced-bots/commit/a60c60c0f994a4c256b7d0582e99a1731209cf49))
* **bots/discord:** do decancer after resetting nickname ([0303fe3](https://github.com/revanced/revanced-bots/commit/0303fe3e367c07e92f831365d5548ca5b03435b2))
* **bots/discord:** do not remove unrelated reactions ([031fd26](https://github.com/revanced/revanced-bots/commit/031fd26b2619ecafeff3964e50accacb87de6108))
* **bots/discord:** don't refresh timer if force timer is active for sticky messages ([4abac0c](https://github.com/revanced/revanced-bots/commit/4abac0c890c0548e14cb56723cae919353a8e726))
* **bots/discord:** filter out text triggers correctly from image-only scans ([8c0dd67](https://github.com/revanced/revanced-bots/commit/8c0dd67d03d5a1747993da08a5bf82a39de43789))
* **bots/discord:** fix freeze on prod builds ([8efb549](https://github.com/revanced/revanced-bots/commit/8efb549453a04fab1ac6414a7f7f8bf702df3c93))
* **bots/discord:** fix get response logic ([3261294](https://github.com/revanced/revanced-bots/commit/3261294822b0a9faec094536ed5be2d3e1d5e17b))
* **bots/discord:** fix reload not working ([11582d5](https://github.com/revanced/revanced-bots/commit/11582d50345cae9fb645a65ca4e621596de6a408))
* **bots/discord:** follow-up if reply is already sent when error ([f75060b](https://github.com/revanced/revanced-bots/commit/f75060bc9cda44902cf872def73c116a6df039d7))
* **bots/discord:** give only removed roles for role presets ([522ad28](https://github.com/revanced/revanced-bots/commit/522ad28fd83565e9ca411dbce86c8447574288fd))
* **bots/discord:** hanging process when disconnecting from API too many times ([d31616e](https://github.com/revanced/revanced-bots/commit/d31616ebcba6f1dcd8bde183bcb8d1adb1501b61))
* **bots/discord:** import `config` from context ([763ef25](https://github.com/revanced/revanced-bots/commit/763ef253f9d4ff70a8b79969a7f4f41cba7f3c59))
* **bots/discord:** make `/eval` work ([eaa25f2](https://github.com/revanced/revanced-bots/commit/eaa25f2eb58a9e2d25bb98633ad668485e099714))
* **bots/discord:** messed up file name for `unmute` command ([399dca7](https://github.com/revanced/revanced-bots/commit/399dca71538fe5c8831977694a97058254a17578))
* **bots/discord:** only check for member permissions when specified while correcting responses ([b79a1c7](https://github.com/revanced/revanced-bots/commit/b79a1c7575e94c3e62654c87775cac497be4a50a))
* **bots/discord:** open database as read-write ([c366840](https://github.com/revanced/revanced-bots/commit/c36684091dddf67880505dc459e4334a8a5492f4))
* **bots/discord:** owners cannot bypass checks on some commands ([39cba97](https://github.com/revanced/revanced-bots/commit/39cba973418027ba6ed67e1ae5ab5c6458807562))
* **bots/discord:** parse larger units of durations, fix wrong timestamp in mod embed ([6c8dce0](https://github.com/revanced/revanced-bots/commit/6c8dce059366a6ef85f5b8b1794c056515b9f5b6))
* **bots/discord:** persist changes in context for eval command ([5b4965d](https://github.com/revanced/revanced-bots/commit/5b4965dcc7285676b2b3b6756c249bd56eaf8485))
* **bots/discord:** provide discord token for `reload` command ([dd21a5a](https://github.com/revanced/revanced-bots/commit/dd21a5abad560f3d00b8c58912786d4b6bd520e9))
* **bots/discord:** remove auto-generated files ([fb8af00](https://github.com/revanced/revanced-bots/commit/fb8af008661bf37389e01cba19d64a8b4fc82139))
* **bots/discord:** remove bad text channel checks ([f5939e2](https://github.com/revanced/revanced-bots/commit/f5939e25288fea2022fdeec9085ecb9ffada6111))
* **bots/discord:** remove redundant footer for response embeds ([412e003](https://github.com/revanced/revanced-bots/commit/412e00317d1eaca23e9c1375e16f94a5f2fa8d86))
* **bots/discord:** remove usage of macros ([7f27c56](https://github.com/revanced/revanced-bots/commit/7f27c5607ceeeef56d67097e88f68caa1b8791b3))
* **bots/discord:** remove useless feature ([d830e48](https://github.com/revanced/revanced-bots/commit/d830e48bc2de7aa457eab3a5f96ae652a93178f9))
* **bots/discord:** replace duration parser with a library ([94c4fed](https://github.com/revanced/revanced-bots/commit/94c4fedc06e20051e4123508e3134b97eb84782a))
* **bots/discord:** reset counter when reconnected to api, redo message scan filter logic ([d234d79](https://github.com/revanced/revanced-bots/commit/d234d79310caed9c43e14a905f9ef46a110e071d))
* **bots/discord:** revert dist denesting, fixes config not found ([0d4898d](https://github.com/revanced/revanced-bots/commit/0d4898dae8b26f8466d3f6b8f62875866f581644))
* **bots/discord:** send right response for after regexes ([a7688fa](https://github.com/revanced/revanced-bots/commit/a7688fa9b91919a87f74071b502cd0a87cd1c1fa))
* **bots/discord:** set the `label` property correctly for message scans ([6d463df](https://github.com/revanced/revanced-bots/commit/6d463df586dee5dd8fe8d6cff1c5316f7809b32a))
* **bots/discord:** set timeout for eligible mutes to unmute faster ([1f5c5a9](https://github.com/revanced/revanced-bots/commit/1f5c5a92a639973b83a1204355538936e69a4454))
* **bots/discord:** some configuration values not applying after running `/reload` ([a976dd2](https://github.com/revanced/revanced-bots/commit/a976dd2accc4b74914651245acde0979c30c92f5))
* **bots/discord:** use `APIEmbed` for response config ([35b9448](https://github.com/revanced/revanced-bots/commit/35b944800a3943c187d5b0e0d3e465ad7d2056fe))
* **bots/discord:** use env for initializing database ([af3759c](https://github.com/revanced/revanced-bots/commit/af3759caf428fada3b3f4a51852543d6fb280018))
* **bots/discord:** wrong command file path being imported ([fa0159c](https://github.com/revanced/revanced-bots/commit/fa0159c3a8dd4dad8778ccdb75b9e7c02ebbb64f))
* **bots/discord:** wrong database schema path ([875bd20](https://github.com/revanced/revanced-bots/commit/875bd209b252566414bf89349839cabc01697e1c))
* config file not being read ([474a8be](https://github.com/revanced/revanced-bots/commit/474a8be4af4eb2bae6e80a893439d846ad4f7503))
* **discord-bot:** also execute slash commands ([f0d45b2](https://github.com/revanced/revanced-bots/commit/f0d45b2c926ed753e2d21f2e06e24d7e6c43880a))
* **discord-bot:** check for role position ([d332043](https://github.com/revanced/revanced-bots/commit/d332043b1a4bb7ac9698a2fc912832e184130b4b))
* **discord-bot:** check if the member has the role ([9bff68c](https://github.com/revanced/revanced-bots/commit/9bff68c8c40c692764e4dec15a058e35059efbc9))
* **discord-bot:** not executing slash commands ([aa08087](https://github.com/revanced/revanced-bots/commit/aa0808768b90844c5fbd3e75d9f2d01c723b0151))
* **discord-bot:** only send lowercased text ([7803758](https://github.com/revanced/revanced-bots/commit/78037580dc92883f5ca21157e45268850cb5db90))
* dislike button not working properly ([85eba55](https://github.com/revanced/revanced-bots/commit/85eba554247738066af72a8efd0de215ec1164dc))
* fix deprecation ([4373ede](https://github.com/revanced/revanced-bots/commit/4373ede855333f209676551162a525238656e1f8))
* fix the fiter for the interaction collector ([a9ff003](https://github.com/revanced/revanced-bots/commit/a9ff00394a73f68a6793c2b35ff184675ee5a72c))
* fix typings and formatting ([479812e](https://github.com/revanced/revanced-bots/commit/479812e199b52cdb295a5746e0767306afab3413))
* ignore message if there's no content ([3cbebc2](https://github.com/revanced/revanced-bots/commit/3cbebc284277808495e64cf0fb47c555924ad9c5))
* move modules to `/bots` ([cd7156e](https://github.com/revanced/revanced-bots/commit/cd7156e792e65777ad1ab5a6f5d828b9ef6a9754))
* other small issues ([bc437a5](https://github.com/revanced/revanced-bots/commit/bc437a5ec7ce1d339094d608e2a61ac5f460c163))
* run projects with `--bun` ([bb2182e](https://github.com/revanced/revanced-bots/commit/bb2182e707fa40c555d56138972eeea28f1b3cf9))
* trainAI not using the bin location ([bd29943](https://github.com/revanced/revanced-bots/commit/bd2994388bc65f720120ef49edb6ba8163260309))
* update repo url ([a21aa34](https://github.com/revanced/revanced-bots/commit/a21aa348d7f32cd0ee65b371e9594520c0a9d3f1))
### chore
* fix more build issues ([77fefb9](https://github.com/revanced/revanced-bots/commit/77fefb9bef286a22f40a4d76b79c64fcc5a2467f))
### Features
* add wit.ai support ([1909e2c](https://github.com/revanced/revanced-bots/commit/1909e2c42148d635dcd045c738d88f65c8be16e3))
* **bots/discord/commands/reply:** send stacktrace when failed ([9f1ac37](https://github.com/revanced/revanced-bots/commit/9f1ac379276c11da65235577a9c6717e01cb02eb))
* **bots/discord/commands:** add `ban` and `unban` commands ([dc4863d](https://github.com/revanced/revanced-bots/commit/dc4863dc208b3fede4d4def323306ab58daffe04))
* **bots/discord/commands:** add `eval` command ([e64d1da](https://github.com/revanced/revanced-bots/commit/e64d1da00cc2ba718da5a4b0da141fe86a0e48d2))
* **bots/discord/commands:** add `mute` and `unmute` commands ([c0fa2fe](https://github.com/revanced/revanced-bots/commit/c0fa2fe1c36acdc7c52cde277aa7da867065f55e))
* **bots/discord/commands:** add `purge` and `role-preset` commands ([fb01ce5](https://github.com/revanced/revanced-bots/commit/fb01ce57400130c93751a11573eb444c0ba103eb))
* **bots/discord/commands:** add `reload` command ([6875b32](https://github.com/revanced/revanced-bots/commit/6875b32fd0c6ce3034da9dc6c704d425afb26f2e))
* **bots/discord/commands:** allow process exception in `exception-test` ([ca47535](https://github.com/revanced/revanced-bots/commit/ca475356ad95fec86e8e8b5bf4bbf17b70add5fe))
* **bots/discord/utils/discord/embeds:** expose `applyCommonEmbedStyles` fn ([2d794ed](https://github.com/revanced/revanced-bots/commit/2d794ede7d7a208bd3616c45e8e6d2a2cd83e9ed))
* **bots/discord/utils/embeds:** make title parameter nullable ([ee885ca](https://github.com/revanced/revanced-bots/commit/ee885ca7585a55fdc31e137ae29dc13a37ce2fb2))
* **bots/discord/utils/fs:** use `recursive` option for listing files ([da21e1a](https://github.com/revanced/revanced-bots/commit/da21e1a6f76deaeb477203b04263bd170863825b))
* **bots/discord/utils:** add duration utility ([a9add9e](https://github.com/revanced/revanced-bots/commit/a9add9ea9affb42bdfcb17cf4b268feec5729854))
* **bots/discord/utils:** add functions for role presets ([fb32a04](https://github.com/revanced/revanced-bots/commit/fb32a04ad38be8d0836dc99259b6ef05a0825830))
* **bots/discord/utils:** allow loading commands from custom dir ([8b690b8](https://github.com/revanced/revanced-bots/commit/8b690b879bb5c6023c8fc863afbd9fd1d02719bb))
* **bots/discord:** add `api.disconnectRetryInterval` config ([2f86586](https://github.com/revanced/revanced-bots/commit/2f8658617923c07f6847cbf1fdfc5f5379d95b6c))
* **bots/discord:** add `moderation.roles` config to be used in `moderation` commands ([39d5b3a](https://github.com/revanced/revanced-bots/commit/39d5b3a479b4d856aabe12cc31177c24f88ae23e))
* **bots/discord:** add `ocrTriggers` resp config, embed footer scan mode ([744a56a](https://github.com/revanced/revanced-bots/commit/744a56a4fdc8844e37959a88bcf81ee39fe726ef))
* **bots/discord:** add `replyToReplied` option in response config ([27662ed](https://github.com/revanced/revanced-bots/commit/27662ed91a79bfac7d3f091834e859a7b57366ce))
* **bots/discord:** add `train` commands ([ee90ef2](https://github.com/revanced/revanced-bots/commit/ee90ef247b4bf2b3c0698606b947116f2dc1b868))
* **bots/discord:** add a better way to manage databases ([a68d726](https://github.com/revanced/revanced-bots/commit/a68d72687584332587455962b0202a306288057d))
* **bots/discord:** add code to actually scan text files correctly ([80aeb19](https://github.com/revanced/revanced-bots/commit/80aeb1902063140a2e78cfaed9424e5101ab03f1))
* **bots/discord:** add default durations for moderation commands ([27d3b39](https://github.com/revanced/revanced-bots/commit/27d3b392092141a1e3b4b0298131ff7817458dc1))
* **bots/discord:** add more fallbacks for decancering ([2e1e009](https://github.com/revanced/revanced-bots/commit/2e1e009b4272495798313bd3bd61f258875c62e1))
* **bots/discord:** add more month aliases to duration parser ([c2009ca](https://github.com/revanced/revanced-bots/commit/c2009ca6d42e4387bc5f375d76ecf72991b7fe32))
* **bots/discord:** add more options for curing, fix default regex ([1a4ec1e](https://github.com/revanced/revanced-bots/commit/1a4ec1ece80becd9156582cc490f6681cb2a1f39))
* **bots/discord:** add source ([f9d50a0](https://github.com/revanced/revanced-bots/commit/f9d50a0a6bef8beaa428a0a555bfa4f879f685f1))
* **bots/discord:** add sticky messages ([bf66155](https://github.com/revanced/revanced-bots/commit/bf661556e131bf0ef24e47f658fbcd701960e312))
* **bots/discord:** add trigger to context for eval ([b5f4097](https://github.com/revanced/revanced-bots/commit/b5f40975386677ffff343c42f8ffac21f847a0b7))
* **bots/discord:** allow admins to bypass permission checks ([620f933](https://github.com/revanced/revanced-bots/commit/620f9339f0737b79d72c66d90ffa42ea3f987710))
* **bots/discord:** blacklist and whitelist for filters ([cdb6001](https://github.com/revanced/revanced-bots/commit/cdb600195520dba33110c40841629259e317055e))
* **bots/discord:** cure on every event ([8ff6086](https://github.com/revanced/revanced-bots/commit/8ff6086028132cc4b49ee60846e8d6ef909f5a89))
* **bots/discord:** don't nest builds in src directory, autogen db when missing ([4834685](https://github.com/revanced/revanced-bots/commit/48346851864c4d4b6276388644dd24ce16222b3e))
* **bots/discord:** framework changes and new features ([646ec8d](https://github.com/revanced/revanced-bots/commit/646ec8da87617e6c8f48a89e8054e2cba91da549))
* **bots/discord:** improve admin commands ([0346741](https://github.com/revanced/revanced-bots/commit/03467411882b8598e2c06f389a09ef2e201bb43f))
* **bots/discord:** improve logs ([6abb740](https://github.com/revanced/revanced-bots/commit/6abb7409945c10bd3af451fb45ef4b4d4ebe9489))
* **bots/discord:** sanitize `BasicDatabase` inputs ([fd76e0a](https://github.com/revanced/revanced-bots/commit/fd76e0af72fe28b414ae3b5e8d3886e58561e57e))
* **bots/discord:** support nickname decancering ([1723e8c](https://github.com/revanced/revanced-bots/commit/1723e8cacf96e8c6bdee22cfd30e89524fdcef74))
* **bots/discord:** switch to `drizzle-orm` ([e204b7b](https://github.com/revanced/revanced-bots/commit/e204b7b7566fd7fa423baef32977a8575d44a9e0))
* **bots/discord:** update config ([197d2ac](https://github.com/revanced/revanced-bots/commit/197d2acea89c38e43858d52736508d449152e804))
* **bots/discord:** update example config file ([bc9951c](https://github.com/revanced/revanced-bots/commit/bc9951c9b5e007c3e1b3076aa0966ccf29bb18bc))
* **bots/discord:** update to newer command definition framework ([97f2795](https://github.com/revanced/revanced-bots/commit/97f2795df4ede4d12a08193dba453c1bc765a4c2))
* discord bot scanning messages ([d1bd3b2](https://github.com/revanced/revanced-bots/commit/d1bd3b2b7e4985a64e9b070ab006cc6f3508c46e))
* **discord-bot:** a way to train AI ([355a508](https://github.com/revanced/revanced-bots/commit/355a50803adc85b5579155b55ddbba4fa0449237))
* **discord-bot:** command handler and train cmd ([6aee8a4](https://github.com/revanced/revanced-bots/commit/6aee8a4c63eb108800fcb0a23ca61f200d8f1f2a))
* **discord-bot:** event handler ([0ad5ece](https://github.com/revanced/revanced-bots/commit/0ad5ece08593c0db111fa4a592b42c6e0348fd1c))
* GODEL AI ([0ba525c](https://github.com/revanced/revanced-bots/commit/0ba525c4a5802106d582c75f713728accf2f151a))
* initalize discord bot ([bb4a5a7](https://github.com/revanced/revanced-bots/commit/bb4a5a77eefbc7ac88536f73a111df1050b235e7))
* initialize helper client ([7f9ca77](https://github.com/revanced/revanced-bots/commit/7f9ca77e0331ec143160ee51ed7c3aa9e4e70b9c))
* message buttons for training ([6551ca9](https://github.com/revanced/revanced-bots/commit/6551ca9dadc2e3ddfe98875e80ed61f7d71a1651))
* platform specific responses ([18e57b0](https://github.com/revanced/revanced-bots/commit/18e57b0c320732a937bb60db11c5d6794ed11522))
* prettier and eslint ([1c27ccb](https://github.com/revanced/revanced-bots/commit/1c27ccb17c85f0f6982db45de426181d2c231d0e))
* refactor and new features ([#7](https://github.com/revanced/revanced-bots/issues/7)) ([8b9f45d](https://github.com/revanced/revanced-bots/commit/8b9f45dc22de29dc2ccb1cfab9a026db00457e25))
* run bots in one process ([d26d533](https://github.com/revanced/revanced-bots/commit/d26d53317440c64fb775cea609a87d29be6c8b40))
* training and replies changed ([715aa91](https://github.com/revanced/revanced-bots/commit/715aa918cf84213c9b19591a398d7532eb3f232a))
* **utils/discord/embeds:** allow adding extra fields for moderation embeds ([49ce9a7](https://github.com/revanced/revanced-bots/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
# @revanced/discord-bot [1.0.0-dev.38](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.0.0-dev.37...@revanced/discord-bot@1.0.0-dev.38) (2025-04-04)
### Bug Fixes
* run projects with `--bun` ([bb2182e](https://github.com/revanced/revanced-bots/commit/bb2182e707fa40c555d56138972eeea28f1b3cf9))
# @revanced/discord-bot [1.0.0-dev.37](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.0.0-dev.36...@revanced/discord-bot@1.0.0-dev.37) (2025-03-08)
### Bug Fixes
* **bots/discord/utils/duration:** fix specified default unit not working ([d138af4](https://github.com/revanced/revanced-bots/commit/d138af46d1f25a11b6f8ab3790ecaa70b1d716a9))
# @revanced/discord-bot [1.0.0-dev.36](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.0.0-dev.35...@revanced/discord-bot@1.0.0-dev.36) (2025-03-03)
### Bug Fixes
* **bots/discord/scripts/build:** check if dist dir exists before cleaning ([c06033e](https://github.com/revanced/revanced-bots/commit/c06033e5730f82438e8052b9b519a8f8e2d25437))
* **bots/discord/utils/duration:** make second the default unit ([5d1af3c](https://github.com/revanced/revanced-bots/commit/5d1af3c31c3379b6a13684dfb07583737908c8aa))
* **bots/discord:** add GuildMember partial ([8e3946a](https://github.com/revanced/revanced-bots/commit/8e3946a66602838715787090008c7bfaf72b67e9))
* **bots/discord:** decrease length of an option in `ban` command ([22d3eea](https://github.com/revanced/revanced-bots/commit/22d3eea88d532792c1237d1a1ab18bc02e57816a))
* **bots/discord:** delete expired appliedPresets entries after unapplying ([14c98e8](https://github.com/revanced/revanced-bots/commit/14c98e87df1ec4fd762bbc48ca4c06470cb110a2))
* fix typings and formatting ([479812e](https://github.com/revanced/revanced-bots/commit/479812e199b52cdb295a5746e0767306afab3413))
* update repo url ([a21aa34](https://github.com/revanced/revanced-bots/commit/a21aa348d7f32cd0ee65b371e9594520c0a9d3f1))
### Features
* **bots/discord:** add more month aliases to duration parser ([c2009ca](https://github.com/revanced/revanced-bots/commit/c2009ca6d42e4387bc5f375d76ecf72991b7fe32))
# @revanced/discord-bot [1.0.0-dev.35](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.34...@revanced/discord-bot@1.0.0-dev.35) (2024-10-17)
### Bug Fixes
* **bots/discord:** fix freeze on prod builds ([8efb549](https://github.com/revanced/revanced-helper/commit/8efb549453a04fab1ac6414a7f7f8bf702df3c93))
# @revanced/discord-bot [1.0.0-dev.34](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.33...@revanced/discord-bot@1.0.0-dev.34) (2024-10-17)
### Bug Fixes
* **bots/discord:** attempt to fix stuck sticky message timeouts ([3ed5bd1](https://github.com/revanced/revanced-helper/commit/3ed5bd11acc3b4fbd57b0d632c68eb9f77365b8a))
* **bots/discord:** fix reload not working ([11582d5](https://github.com/revanced/revanced-helper/commit/11582d50345cae9fb645a65ca4e621596de6a408))
### Features
* **bots/discord:** add default durations for moderation commands ([27d3b39](https://github.com/revanced/revanced-helper/commit/27d3b392092141a1e3b4b0298131ff7817458dc1))
* **bots/discord:** cure on every event ([8ff6086](https://github.com/revanced/revanced-helper/commit/8ff6086028132cc4b49ee60846e8d6ef909f5a89))
# @revanced/discord-bot [1.0.0-dev.33](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.32...@revanced/discord-bot@1.0.0-dev.33) (2024-09-25)
### Features
* **bots/discord:** add trigger to context for eval ([b5f4097](https://github.com/revanced/revanced-helper/commit/b5f40975386677ffff343c42f8ffac21f847a0b7))
# @revanced/discord-bot [1.0.0-dev.32](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.31...@revanced/discord-bot@1.0.0-dev.32) (2024-09-25)
### Bug Fixes
* **bots/discord:** contextify object before sandboxing ([062735f](https://github.com/revanced/revanced-helper/commit/062735f6d552890404d6192244c51a11b0709580))
# @revanced/discord-bot [1.0.0-dev.31](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.30...@revanced/discord-bot@1.0.0-dev.31) (2024-09-25) # @revanced/discord-bot [1.0.0-dev.31](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.30...@revanced/discord-bot@1.0.0-dev.31) (2024-09-25)

View File

@@ -15,4 +15,4 @@ COPY --from=build /build/bots/discord/dist /app
USER 1000:1000 USER 1000:1000
ENTRYPOINT [ "bun", "run", "src/index.js" ] ENTRYPOINT [ "bun", "--bun", "run", "src/index.js" ]

View File

@@ -19,8 +19,8 @@ export default {
}, },
timeout: 60000, timeout: 60000,
forceSendTimeout: 300000, forceSendTimeout: 300000,
} },
} },
}, },
moderation: { moderation: {
cure: { cure: {
@@ -77,7 +77,7 @@ export default {
attachments: { attachments: {
scanAttachments: true, scanAttachments: true,
allowedMimeTypes: ['image/jpeg', 'image/png', 'image/webp', 'text/plain'], allowedMimeTypes: ['image/jpeg', 'image/png', 'image/webp', 'text/plain'],
maxTextFileSize: 512000 maxTextFileSize: 512000,
}, },
responses: [ responses: [
{ {

View File

@@ -2,7 +2,7 @@
"name": "@revanced/discord-bot", "name": "@revanced/discord-bot",
"type": "module", "type": "module",
"private": true, "private": true,
"version": "1.0.0-dev.31", "version": "1.2.2",
"description": "🤖 Discord bot assisting ReVanced", "description": "🤖 Discord bot assisting ReVanced",
"main": "src/index.ts", "main": "src/index.ts",
"scripts": { "scripts": {
@@ -14,7 +14,7 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/revanced/revanced-helper.git", "url": "git+https://github.com/revanced/revanced-bots.git",
"directory": "bots/discord" "directory": "bots/discord"
}, },
"author": "Palm <contact@palmdevs.me> (https://palmdevs.me)", "author": "Palm <contact@palmdevs.me> (https://palmdevs.me)",
@@ -24,23 +24,23 @@
], ],
"license": "GPL-3.0-or-later", "license": "GPL-3.0-or-later",
"bugs": { "bugs": {
"url": "https://github.com/revanced/revanced-helper/issues" "url": "https://github.com/revanced/revanced-bots/issues"
}, },
"homepage": "https://github.com/revanced/revanced-helper#readme", "homepage": "https://github.com/revanced/revanced-bots#readme",
"dependencies": { "dependencies": {
"@discordjs/builders": "^1.8.2", "@discordjs/builders": "^1.11.2",
"@discordjs/rest": "^2.3.0", "@discordjs/rest": "^2.5.1",
"@revanced/bot-api": "workspace:*", "@revanced/bot-api": "workspace:*",
"@revanced/bot-shared": "workspace:*", "@revanced/bot-shared": "workspace:*",
"chalk": "^5.3.0", "@sapphire/duration": "^1.2.0",
"decancer": "^3.2.4", "chalk": "^5.4.1",
"discord.js": "^14.15.3", "decancer": "^3.3.2",
"drizzle-orm": "^0.31.4", "discord.js": "^14.20.0",
"parse-duration": "^1.1.0" "drizzle-orm": "^0.44.2"
}, },
"devDependencies": { "devDependencies": {
"@libsql/client": "^0.7.0", "@libsql/client": "^0.15.9",
"discord-api-types": "^0.37.97", "discord-api-types": "^0.38.13",
"drizzle-kit": "^0.22.8" "drizzle-kit": "^0.31.2"
} }
} }

View File

@@ -1,10 +1,10 @@
import { createLogger } from '@revanced/bot-shared' import { createLogger } from '@revanced/bot-shared'
import { cp, rm } from 'fs/promises' import { cp, exists, rm } from 'fs/promises'
const logger = createLogger() const logger = createLogger()
logger.warn('Cleaning previous build...') logger.warn('Cleaning previous build...')
await rm('./dist', { recursive: true }) if (await exists('./dist')) await rm('./dist', { recursive: true })
logger.info('Building bot...') logger.info('Building bot...')
await Bun.build({ await Bun.build({

View File

@@ -1,8 +1,7 @@
import { ApplicationCommandOptionType, ApplicationCommandType } from 'discord.js' import { ApplicationCommandOptionType, ApplicationCommandType } from 'discord.js'
import { config } from '../context'
import { isAdmin } from '../utils/discord/permissions' import { isAdmin } from '../utils/discord/permissions'
import CommandError, { CommandErrorType } from './CommandError' import CommandError, { CommandErrorType } from './CommandError'
import type { import type {
APIApplicationCommandChannelOption, APIApplicationCommandChannelOption,
CacheType, CacheType,
@@ -20,7 +19,6 @@ import type {
UserContextMenuCommandInteraction, UserContextMenuCommandInteraction,
UserResolvable, UserResolvable,
} from 'discord.js' } from 'discord.js'
import { config } from '../context'
export enum CommandType { export enum CommandType {
ChatGlobal = 1, ChatGlobal = 1,

View File

@@ -1,12 +1,11 @@
import { unlinkSync, writeFileSync } from 'fs'
import { join } from 'path'
import { inspect } from 'util'
import { runInContext } from 'vm'
import { ApplicationCommandOptionType } from 'discord.js'
import { AdminCommand } from '$/classes/Command' import { AdminCommand } from '$/classes/Command'
import { createSuccessEmbed } from '$/utils/discord/embeds' import { createSuccessEmbed } from '$/utils/discord/embeds'
import { parseDuration } from '$/utils/duration' import { parseDuration } from '$/utils/duration'
import { ApplicationCommandOptionType, MessageFlags } from 'discord.js'
import { unlinkSync, writeFileSync } from 'fs'
import { join } from 'path'
import { inspect } from 'util'
import { createContext, runInContext } from 'vm'
export default new AdminCommand({ export default new AdminCommand({
name: 'eval', name: 'eval',
@@ -43,10 +42,11 @@ export default new AdminCommand({
// to the bot while the bot is running, minus malicious actors getting the token to perform malicious actions // to the bot while the bot is running, minus malicious actors getting the token to perform malicious actions
const output = await runInContext( const output = await runInContext(
code, code,
{ createContext({
...globalThis, ...globalThis,
context, context,
}, trigger,
}),
{ {
timeout: parseDuration(timeout ?? '10s'), timeout: parseDuration(timeout ?? '10s'),
filename: 'eval', filename: 'eval',
@@ -84,8 +84,8 @@ export default new AdminCommand({
}) })
await trigger.reply({ await trigger.reply({
ephemeral: true,
embeds: [embed], embeds: [embed],
flags: MessageFlags.Ephemeral,
files, files,
}) })

View File

@@ -1,7 +1,6 @@
import { ApplicationCommandOptionType } from 'discord.js'
import { AdminCommand } from '$/classes/Command' import { AdminCommand } from '$/classes/Command'
import CommandError, { CommandErrorType } from '$/classes/CommandError' import CommandError, { CommandErrorType } from '$/classes/CommandError'
import { ApplicationCommandOptionType } from 'discord.js'
export default new AdminCommand({ export default new AdminCommand({
name: 'exception-test', name: 'exception-test',

View File

@@ -1,7 +1,5 @@
import { dirname, join } from 'path'
import { AdminCommand } from '$/classes/Command' import { AdminCommand } from '$/classes/Command'
import { type CommandInteraction, MessageFlags } from 'discord.js'
import type { Config } from 'config.schema'
export default new AdminCommand({ export default new AdminCommand({
name: 'reload', name: 'reload',
@@ -10,12 +8,11 @@ export default new AdminCommand({
const { api, logger, discord } = context const { api, logger, discord } = context
logger.info(`Reload triggered by ${context.executor.tag} (${context.executor.id})`) logger.info(`Reload triggered by ${context.executor.tag} (${context.executor.id})`)
// Apparently the query strings only work with non-Windows "URLs", otherwise it'd just infinitely hang logger.debug('Invalidating previous config...')
const path = `${Bun.pathToFileURL(join(dirname(Bun.main), '..', 'config.js')).toString()}?cache=${Date.now()}` context.config.invalidate()
logger.debug(`Reloading configuration from: ${path}`)
context.config = ((await import(path)) as { default: Config }).default
if ('deferReply' in trigger) await trigger.deferReply({ ephemeral: true }) if ((trigger as CommandInteraction).deferReply)
await (trigger as CommandInteraction).deferReply({ flags: MessageFlags.Ephemeral })
logger.info('Reinitializing API client to reload configuration...') logger.info('Reinitializing API client to reload configuration...')
await api.client.ws.setOptions( await api.client.ws.setOptions(
@@ -28,7 +25,7 @@ export default new AdminCommand({
api.client.disconnect(true) api.client.disconnect(true)
api.disconnectCount = 0 api.disconnectCount = 0
api.intentionallyDisconnecting = false api.intentionallyDisconnecting = false
await api.client.connect() api.client.connect()
logger.info('Reinitializing Discord client to reload configuration...') logger.info('Reinitializing Discord client to reload configuration...')
await discord.client.destroy() await discord.client.destroy()

View File

@@ -1,9 +1,7 @@
import { ApplicationCommandOptionType, Routes } from 'discord.js'
import { AdminCommand } from '$/classes/Command' import { AdminCommand } from '$/classes/Command'
import CommandError, { CommandErrorType } from '$/classes/CommandError' import CommandError, { CommandErrorType } from '$/classes/CommandError'
import { createSuccessEmbed } from '$/utils/discord/embeds' import { createSuccessEmbed } from '$/utils/discord/embeds'
import { ApplicationCommandOptionType, Routes } from 'discord.js'
const SubcommandOptions = { const SubcommandOptions = {
where: { where: {

View File

@@ -1,4 +1,5 @@
import { AdminCommand } from '$/classes/Command' import { AdminCommand } from '$/classes/Command'
import { MessageFlags } from 'discord.js'
export default new AdminCommand({ export default new AdminCommand({
name: 'stop', name: 'stop',
@@ -9,7 +10,7 @@ export default new AdminCommand({
logger.fatal('Stopping bot...') logger.fatal('Stopping bot...')
trigger.reply({ trigger.reply({
content: 'Stopping... (I will go offline once done)', content: 'Stopping... (I will go offline once done)',
ephemeral: true, flags: MessageFlags.Ephemeral,
}) })
if (!api.client.disconnected) api.client.disconnect() if (!api.client.disconnected) api.client.disconnect()

View File

@@ -1,7 +1,6 @@
import { EmbedBuilder } from 'discord.js'
import Command from '$/classes/Command' import Command from '$/classes/Command'
import { applyCommonEmbedStyles } from '$/utils/discord/embeds' import { applyCommonEmbedStyles } from '$/utils/discord/embeds'
import { EmbedBuilder, MessageFlags } from 'discord.js'
export default new Command({ export default new Command({
name: 'coinflip', name: 'coinflip',
@@ -18,6 +17,7 @@ export default new Command({
const reply = await trigger const reply = await trigger
.reply({ .reply({
embeds: [embed.toJSON()], embeds: [embed.toJSON()],
flags: MessageFlags.Ephemeral,
}) })
.then(it => it.fetch()) .then(it => it.fetch())

View File

@@ -1,5 +1,5 @@
import CommandError, { CommandErrorType } from '$/classes/CommandError' import CommandError, { CommandErrorType } from '$/classes/CommandError'
import { ApplicationCommandOptionType, Message } from 'discord.js' import { ApplicationCommandOptionType, Message, MessageFlags } from 'discord.js'
import { ModerationCommand } from '../../classes/Command' import { ModerationCommand } from '../../classes/Command'
export default new ModerationCommand({ export default new ModerationCommand({
@@ -40,7 +40,7 @@ export default new ModerationCommand({
await trigger.reply({ await trigger.reply({
content: 'OK!', content: 'OK!',
ephemeral: true, flags: MessageFlags.Ephemeral,
}) })
}, },
}) })

View File

@@ -18,13 +18,14 @@ export default new ModerationCommand({
required: false, required: false,
type: ModerationCommand.OptionType.String, type: ModerationCommand.OptionType.String,
}, },
dmd: { dmt: {
description: 'Duration to delete messages (must be from 0 to 7 days)', description:
'Time duration to delete messages (default time unit is days, must be from 0s to 7d, default is 0s)',
required: false, required: false,
type: ModerationCommand.OptionType.String, type: ModerationCommand.OptionType.String,
}, },
}, },
async execute({ logger, executor }, interaction, { user, reason, dmd }) { async execute({ logger, executor }, interaction, { user, reason, dmt }) {
const guild = await interaction.client.guilds.fetch(interaction.guildId) const guild = await interaction.client.guilds.fetch(interaction.guildId)
const member = await guild.members.fetch(user).catch(() => {}) const member = await guild.members.fetch(user).catch(() => {})
const moderator = await guild.members.fetch(executor.user) const moderator = await guild.members.fetch(executor.user)
@@ -40,7 +41,7 @@ export default new ModerationCommand({
) )
} }
const dms = Math.floor(dmd ? parseDuration(dmd) : 0 / 1000) const dms = Math.floor((dmt ? parseDuration(dmt, 'd') : 0) / 1000)
await interaction.guild!.members.ban(user, { await interaction.guild!.members.ban(user, {
reason: `Banned by moderator ${executor.user.tag} (${executor.id}): ${reason}`, reason: `Banned by moderator ${executor.user.tag} (${executor.id}): ${reason}`,
deleteMessageSeconds: dms, deleteMessageSeconds: dms,

View File

@@ -1,6 +1,7 @@
import { ModerationCommand } from '$/classes/Command' import { ModerationCommand } from '$/classes/Command'
import { createSuccessEmbed } from '$/utils/discord/embeds' import { createSuccessEmbed } from '$/utils/discord/embeds'
import { cureNickname } from '$/utils/discord/moderation' import { cureNickname } from '$/utils/discord/moderation'
import { MessageFlags } from 'discord.js'
export default new ModerationCommand({ export default new ModerationCommand({
name: 'cure', name: 'cure',
@@ -18,7 +19,7 @@ export default new ModerationCommand({
await cureNickname(member) await cureNickname(member)
await interaction.reply({ await interaction.reply({
embeds: [createSuccessEmbed(null, `Cured nickname for ${member.toString()}`)], embeds: [createSuccessEmbed(null, `Cured nickname for ${member.toString()}`)],
ephemeral: true, flags: MessageFlags.Ephemeral,
}) })
}, },
}) })

View File

@@ -3,7 +3,7 @@ import CommandError, { CommandErrorType } from '$/classes/CommandError'
import { createModerationActionEmbed } from '$/utils/discord/embeds' import { createModerationActionEmbed } from '$/utils/discord/embeds'
import { sendModerationReplyAndLogs } from '$/utils/discord/moderation' import { sendModerationReplyAndLogs } from '$/utils/discord/moderation'
import { applyRolePreset, removeRolePreset } from '$/utils/discord/rolePresets' import { applyRolePreset, removeRolePreset } from '$/utils/discord/rolePresets'
import { parseDuration } from '$/utils/duration' import { isSafeTimeoutDuration, parseDuration } from '$/utils/duration'
export default new ModerationCommand({ export default new ModerationCommand({
name: 'mute', name: 'mute',
@@ -14,13 +14,13 @@ export default new ModerationCommand({
required: true, required: true,
type: ModerationCommand.OptionType.User, type: ModerationCommand.OptionType.User,
}, },
reason: { duration: {
description: 'The reason for muting the member', description: 'The duration of the mute (default time unit is minutes)',
required: false, required: false,
type: ModerationCommand.OptionType.String, type: ModerationCommand.OptionType.String,
}, },
duration: { reason: {
description: 'The duration of the mute', description: 'The reason for muting the member',
required: false, required: false,
type: ModerationCommand.OptionType.String, type: ModerationCommand.OptionType.String,
}, },
@@ -33,7 +33,7 @@ export default new ModerationCommand({
const guild = await interaction.client.guilds.fetch(interaction.guildId) const guild = await interaction.client.guilds.fetch(interaction.guildId)
const member = await guild.members.fetch(user.id) const member = await guild.members.fetch(user.id)
const moderator = await guild.members.fetch(executor.id) const moderator = await guild.members.fetch(executor.id)
const duration = durationInput ? parseDuration(durationInput) : Infinity const duration = durationInput ? parseDuration(durationInput, 'm') : Infinity
if (Number.isInteger(duration) && duration! < 1) if (Number.isInteger(duration) && duration! < 1)
throw new CommandError( throw new CommandError(
@@ -63,7 +63,7 @@ export default new ModerationCommand({
createModerationActionEmbed('Muted', user, executor.user, reason, Math.ceil(expires / 1000)), createModerationActionEmbed('Muted', user, executor.user, reason, Math.ceil(expires / 1000)),
) )
if (duration) if (isSafeTimeoutDuration(duration))
setTimeout(() => { setTimeout(() => {
removeRolePreset(member, 'mute') removeRolePreset(member, 'mute')
}, duration) }, duration)

View File

@@ -1,8 +1,7 @@
import { EmbedBuilder } from 'discord.js'
import { ModerationCommand } from '$/classes/Command' import { ModerationCommand } from '$/classes/Command'
import CommandError, { CommandErrorType } from '$/classes/CommandError' import CommandError, { CommandErrorType } from '$/classes/CommandError'
import { applyCommonEmbedStyles } from '$/utils/discord/embeds' import { applyCommonEmbedStyles } from '$/utils/discord/embeds'
import { EmbedBuilder } from 'discord.js'
export default new ModerationCommand({ export default new ModerationCommand({
name: 'purge', name: 'purge',

View File

@@ -2,7 +2,7 @@ import { ModerationCommand } from '$/classes/Command'
import CommandError, { CommandErrorType } from '$/classes/CommandError' import CommandError, { CommandErrorType } from '$/classes/CommandError'
import { sendPresetReplyAndLogs } from '$/utils/discord/moderation' import { sendPresetReplyAndLogs } from '$/utils/discord/moderation'
import { applyRolePreset, removeRolePreset } from '$/utils/discord/rolePresets' import { applyRolePreset, removeRolePreset } from '$/utils/discord/rolePresets'
import { parseDuration } from '$/utils/duration' import { isSafeTimeoutDuration, parseDuration } from '$/utils/duration'
const SubcommandOptions = { const SubcommandOptions = {
member: { member: {
@@ -11,12 +11,12 @@ const SubcommandOptions = {
type: ModerationCommand.OptionType.User, type: ModerationCommand.OptionType.User,
}, },
preset: { preset: {
description: 'The preset to apply or remove', description: 'The preset to manage',
required: true, required: true,
type: ModerationCommand.OptionType.String, type: ModerationCommand.OptionType.String,
}, },
duration: { duration: {
description: 'The duration to apply the preset for (only for apply action)', description: 'The duration to apply the preset for (only for apply action, default time unit is minutes)',
required: false, required: false,
type: ModerationCommand.OptionType.String, type: ModerationCommand.OptionType.String,
}, },
@@ -53,7 +53,7 @@ export default new ModerationCommand({
throw new CommandError(CommandErrorType.Generic, 'This user cannot be managed by the bot.') throw new CommandError(CommandErrorType.Generic, 'This user cannot be managed by the bot.')
if (apply) { if (apply) {
const duration = durationInput ? parseDuration(durationInput) : Infinity const duration = durationInput ? parseDuration(durationInput, 'm') : Infinity
if (Number.isInteger(duration) && duration! < 1) if (Number.isInteger(duration) && duration! < 1)
throw new CommandError( throw new CommandError(
CommandErrorType.InvalidArgument, CommandErrorType.InvalidArgument,
@@ -78,11 +78,18 @@ export default new ModerationCommand({
) )
} }
if (expires) if (expires && isSafeTimeoutDuration(expires))
setTimeout(() => { setTimeout(() => {
removeRolePreset(member, preset) removeRolePreset(member, preset)
}, expires) }, expires)
await sendPresetReplyAndLogs(apply ? 'apply' : 'remove', trigger, executor, user, preset, expires ? Math.ceil(expires / 1000) : undefined) await sendPresetReplyAndLogs(
apply ? 'apply' : 'remove',
trigger,
executor,
user,
preset,
expires ? Math.ceil(expires / 1000) : undefined,
)
}, },
}) })

View File

@@ -1,8 +1,7 @@
import { createSuccessEmbed } from '$/utils/discord/embeds'
import { durationToString, parseDuration } from '$/utils/duration'
import { ModerationCommand } from '$/classes/Command' import { ModerationCommand } from '$/classes/Command'
import CommandError, { CommandErrorType } from '$/classes/CommandError' import CommandError, { CommandErrorType } from '$/classes/CommandError'
import { createSuccessEmbed } from '$/utils/discord/embeds'
import { durationToString, parseDuration } from '$/utils/duration'
import { ChannelType } from 'discord.js' import { ChannelType } from 'discord.js'
export default new ModerationCommand({ export default new ModerationCommand({
@@ -10,7 +9,7 @@ export default new ModerationCommand({
description: 'Set a slowmode for a channel', description: 'Set a slowmode for a channel',
options: { options: {
duration: { duration: {
description: 'The duration to set', description: 'The duration to set (default time unit is seconds)',
required: true, required: true,
type: ModerationCommand.OptionType.String, type: ModerationCommand.OptionType.String,
}, },
@@ -23,13 +22,10 @@ export default new ModerationCommand({
}, },
async execute({ logger, executor }, interaction, { duration: durationInput, channel: channelInput }) { async execute({ logger, executor }, interaction, { duration: durationInput, channel: channelInput }) {
const channel = channelInput ?? (await interaction.guild!.channels.fetch(interaction.channelId)) const channel = channelInput ?? (await interaction.guild!.channels.fetch(interaction.channelId))
const duration = parseDuration(durationInput) const duration = parseDuration(durationInput, 's')
if (!channel?.isTextBased() || channel.isDMBased()) if (!channel?.isTextBased() || channel.isDMBased())
throw new CommandError( throw new CommandError(CommandErrorType.InvalidArgument, 'The supplied channel is not a text channel.')
CommandErrorType.InvalidArgument,
'The supplied channel is not a text channel.',
)
if (Number.isNaN(duration)) throw new CommandError(CommandErrorType.InvalidArgument, 'Invalid duration.') if (Number.isNaN(duration)) throw new CommandError(CommandErrorType.InvalidArgument, 'Invalid duration.')
if (duration < 0 || duration > 36e4) if (duration < 0 || duration > 36e4)

View File

@@ -1,9 +1,9 @@
import Command from '$/classes/Command' import Command from '$/classes/Command'
import CommandError, { CommandErrorType } from '$/classes/CommandError' import CommandError, { CommandErrorType } from '$/classes/CommandError'
import { config } from '../../../context'
import type { FetchMessageOptions, MessageResolvable } from 'discord.js'
import type { ConfigMessageScanResponseLabelConfig } from 'config.schema'
import { createSuccessEmbed } from '$/utils/discord/embeds' import { createSuccessEmbed } from '$/utils/discord/embeds'
import { type FetchMessageOptions, MessageFlags, type MessageResolvable } from 'discord.js'
import { config } from '../../../context'
import type { ConfigMessageScanResponseLabelConfig } from 'config.schema'
const msRcConfig = config.messageScan?.humanCorrections?.allow const msRcConfig = config.messageScan?.humanCorrections?.allow
@@ -70,7 +70,7 @@ export default new Command({
`The provided message has been trained as \`${label}\`. Thank you for your contribution!`, `The provided message has been trained as \`${label}\`. Thank you for your contribution!`,
), ),
], ],
ephemeral: true, flags: MessageFlags.Ephemeral,
}) })
}, },
}) })

View File

@@ -1,7 +1,7 @@
import Command from '$/classes/Command' import Command from '$/classes/Command'
import CommandError, { CommandErrorType } from '$/classes/CommandError' import CommandError, { CommandErrorType } from '$/classes/CommandError'
import { type APIStringSelectComponent, ComponentType, MessageFlags } from 'discord.js'
import { config } from '../../../context' import { config } from '../../../context'
import { type APIStringSelectComponent, ComponentType } from 'discord.js'
import type { ConfigMessageScanResponseLabelConfig } from 'config.schema' import type { ConfigMessageScanResponseLabelConfig } from 'config.schema'
const msRcConfig = config.messageScan?.humanCorrections?.allow const msRcConfig = config.messageScan?.humanCorrections?.allow
@@ -44,7 +44,7 @@ export default new Command({
type: ComponentType.ActionRow, type: ComponentType.ActionRow,
}, },
], ],
ephemeral: true, flags: MessageFlags.Ephemeral,
}) })
}, },
}) })

View File

@@ -0,0 +1,28 @@
import { dirname, join } from 'path'
import _firstConfig from '../config.js'
let currentConfig = _firstConfig
// Other parts of the code will access properties of this proxy, they don't care what the target looks like
export const config = new Proxy(
{
INSPECTION_WARNING: 'Run `context.__getConfig()` to inspect the latest config.',
} as unknown as typeof currentConfig,
{
get(_, p, receiver) {
if (p === 'invalidate')
return async () => {
const path = join(dirname(Bun.main), '..', 'config.js')
Loader.registry.delete(path)
currentConfig = (await import(path)).default
}
return Reflect.get(currentConfig, p, receiver)
},
set(_, p, newValue, receiver) {
return Reflect.set(currentConfig, p, newValue, receiver)
},
},
) as typeof _firstConfig & { invalidate(): void }
export const __getConfig = () => currentConfig

View File

@@ -1,23 +1,21 @@
import { Database } from 'bun:sqlite' import { Database } from 'bun:sqlite'
import { existsSync, readFileSync, readdirSync } from 'fs'
import { join } from 'path'
import { Client as APIClient } from '@revanced/bot-api' import { Client as APIClient } from '@revanced/bot-api'
import { createLogger } from '@revanced/bot-shared' import { createLogger } from '@revanced/bot-shared'
import { Client as DiscordClient, type Message, Partials } from 'discord.js' import { Client as DiscordClient, type Message, Options, Partials } from 'discord.js'
import { drizzle } from 'drizzle-orm/bun-sqlite' import { drizzle } from 'drizzle-orm/bun-sqlite'
import { existsSync, readdirSync, readFileSync } from 'fs'
// Export some things first, as commands require them import { join } from 'path'
import config from '../config.js' import { __getConfig, config } from './config'
export { config } import * as schemas from './database/schemas'
import type { default as Command, CommandOptionsOptions, CommandType } from './classes/Command'
export { config, __getConfig }
export const logger = createLogger({ export const logger = createLogger({
level: config.logLevel === 'none' ? Number.MAX_SAFE_INTEGER : config.logLevel, level: config.logLevel === 'none' ? Number.MAX_SAFE_INTEGER : config.logLevel,
}) })
// Export a few things before we initialize commands
import * as commands from './commands' import * as commands from './commands'
import * as schemas from './database/schemas'
import type { default as Command, CommandOptionsOptions, CommandType } from './classes/Command'
export const api = { export const api = {
client: new APIClient({ client: new APIClient({
@@ -79,7 +77,52 @@ export const discord = {
parse: ['users'], parse: ['users'],
repliedUser: true, repliedUser: true,
}, },
partials: [Partials.Message, Partials.Reaction], sweepers: {
...Options.DefaultSweeperSettings,
messages: {
interval: 1_800, // Every 30m
lifetime: 3_600, // Remove messages older than 1h
},
},
makeCache: Options.cacheWithLimits({
...Options.DefaultMakeCacheSettings,
UserManager: 50,
GuildMemberManager: {
maxSize: 50,
// Always keep client guild member in cache
keepOverLimit: member => member.id === member.client.user.id,
},
ThreadManager: {
maxSize: 0,
// Always keep threads that are used for moderation logging
keepOverLimit: thread => config.moderation?.log?.thread === thread.id,
},
GuildMessageManager: {
maxSize: 0,
// Always keep messages posted by the client in cache
keepOverLimit: message => message.author.id === message.client.user.id,
},
// Unneeded cache
MessageManager: 0,
ReactionManager: 0,
VoiceStateManager: 0,
ThreadMemberManager: 0,
StageInstanceManager: 0,
ReactionUserManager: 0,
PresenceManager: 0,
GuildTextThreadManager: 0,
GuildStickerManager: 0,
DMMessageManager: 0,
GuildEmojiManager: 0,
GuildBanManager: 0,
GuildScheduledEventManager: 0,
EntitlementManager: 0,
AutoModerationRuleManager: 0,
GuildForumThreadManager: 0,
BaseGuildEmojiManager: 0,
GuildInviteManager: 0,
}),
partials: [Partials.Message, Partials.Reaction, Partials.GuildMember],
}), }),
commands: Object.fromEntries(Object.values(commands).map(cmd => [cmd.name, cmd])) as Record< commands: Object.fromEntries(Object.values(commands).map(cmd => [cmd.name, cmd])) as Record<
string, string,
@@ -100,7 +143,7 @@ export const discord = {
timerActive: boolean timerActive: boolean
timerMs: number timerMs: number
forceTimerMs?: number forceTimerMs?: number
send: (forced?: boolean) => Promise<void> send: () => Promise<void>
currentMessage?: Message<true> currentMessage?: Message<true>
timer?: NodeJS.Timeout timer?: NodeJS.Timeout
forceTimer?: NodeJS.Timeout forceTimer?: NodeJS.Timeout

View File

@@ -1,5 +1,5 @@
import type { InferSelectModel } from 'drizzle-orm'
import { integer, sqliteTable, text, uniqueIndex } from 'drizzle-orm/sqlite-core' import { integer, sqliteTable, text, uniqueIndex } from 'drizzle-orm/sqlite-core'
import type { InferSelectModel } from 'drizzle-orm'
export const responses = sqliteTable('responses', { export const responses = sqliteTable('responses', {
replyId: text('reply').primaryKey().notNull(), replyId: text('reply').primaryKey().notNull(),

View File

@@ -1,9 +1,9 @@
import { on } from '$/utils/discord/events' import { on } from '$/utils/discord/events'
import { cureNickname } from '$/utils/discord/moderation' import { cureNickname } from '$/utils/discord/moderation'
on('guildMemberUpdate', async (oldMember, newMember) => { on('guildMemberUpdate', (_, newMember) => {
if (newMember.user.bot) return if (newMember.user.bot) return
if (oldMember.displayName !== newMember.displayName) await cureNickname(newMember) cureNickname(newMember)
}) })
on('guildMemberAdd', member => { on('guildMemberAdd', member => {
@@ -11,7 +11,7 @@ on('guildMemberAdd', member => {
cureNickname(member) cureNickname(member)
}) })
on('messageCreate', async msg => { on('messageCreate', msg => {
if (msg.author.bot || !msg.member) return if (msg.author.bot || !msg.member) return
await cureNickname(msg.member) cureNickname(msg.member)
}) })

View File

@@ -1,6 +1,7 @@
import CommandError from '$/classes/CommandError' import CommandError from '$/classes/CommandError'
import { createStackTraceEmbed } from '$utils/discord/embeds' import { createStackTraceEmbed } from '$utils/discord/embeds'
import { on, withContext } from '$utils/discord/events' import { on, withContext } from '$utils/discord/events'
import { MessageFlags } from 'discord.js'
withContext(on, 'interactionCreate', async (context, interaction) => { withContext(on, 'interactionCreate', async (context, interaction) => {
if (!interaction.isChatInputCommand()) return if (!interaction.isChatInputCommand()) return
@@ -9,8 +10,7 @@ withContext(on, 'interactionCreate', async (context, interaction) => {
const command = discord.commands[interaction.commandName] const command = discord.commands[interaction.commandName]
logger.debug(`Command ${interaction.commandName} being invoked by ${interaction.user.tag} via chat`) logger.debug(`Command ${interaction.commandName} being invoked by ${interaction.user.tag} via chat`)
if (!command) if (!command) return void logger.error(`Chat command ${interaction.commandName} not implemented but registered!!!`)
return void logger.error(`Chat command ${interaction.commandName} not implemented but registered!!!`)
try { try {
logger.debug(`Command ${interaction.commandName} being executed via chat`) logger.debug(`Command ${interaction.commandName} being executed via chat`)
@@ -21,7 +21,7 @@ withContext(on, 'interactionCreate', async (context, interaction) => {
await interaction[interaction.replied ? 'followUp' : 'reply']({ await interaction[interaction.replied ? 'followUp' : 'reply']({
embeds: [err instanceof CommandError ? err.toEmbed() : createStackTraceEmbed(err)], embeds: [err instanceof CommandError ? err.toEmbed() : createStackTraceEmbed(err)],
ephemeral: true, flags: MessageFlags.Ephemeral,
}) })
// 100 and up are user errors // 100 and up are user errors

View File

@@ -1,6 +1,7 @@
import CommandError from '$/classes/CommandError' import CommandError from '$/classes/CommandError'
import { createStackTraceEmbed } from '$utils/discord/embeds' import { createStackTraceEmbed } from '$utils/discord/embeds'
import { on, withContext } from '$utils/discord/events' import { on, withContext } from '$utils/discord/events'
import { MessageFlags } from 'discord.js'
withContext(on, 'interactionCreate', async (context, interaction) => { withContext(on, 'interactionCreate', async (context, interaction) => {
if (!interaction.isContextMenuCommand()) return if (!interaction.isContextMenuCommand()) return
@@ -20,7 +21,7 @@ withContext(on, 'interactionCreate', async (context, interaction) => {
logger.error(`Error while executing command ${interaction.commandName}:`, err) logger.error(`Error while executing command ${interaction.commandName}:`, err)
await interaction[interaction.replied ? 'followUp' : 'reply']({ await interaction[interaction.replied ? 'followUp' : 'reply']({
embeds: [err instanceof CommandError ? err.toEmbed() : createStackTraceEmbed(err)], embeds: [err instanceof CommandError ? err.toEmbed() : createStackTraceEmbed(err)],
ephemeral: true, flags: MessageFlags.Ephemeral,
}) })
} }
}) })

View File

@@ -2,8 +2,12 @@ import { responses } from '$/database/schemas'
import { handleUserResponseCorrection } from '$/utils/discord/messageScan' import { handleUserResponseCorrection } from '$/utils/discord/messageScan'
import { createErrorEmbed, createStackTraceEmbed, createSuccessEmbed } from '$utils/discord/embeds' import { createErrorEmbed, createStackTraceEmbed, createSuccessEmbed } from '$utils/discord/embeds'
import { on, withContext } from '$utils/discord/events' import { on, withContext } from '$utils/discord/events'
import {
import type { ButtonInteraction, StringSelectMenuInteraction, TextBasedChannel } from 'discord.js' type ButtonInteraction,
MessageFlags,
type StringSelectMenuInteraction,
type TextBasedChannel,
} from 'discord.js'
import { eq } from 'drizzle-orm' import { eq } from 'drizzle-orm'
// No permission check required as it is already done when the user reacts to a bot response // No permission check required as it is already done when the user reacts to a bot response
@@ -26,7 +30,7 @@ withContext(on, 'interactionCreate', async (context, interaction) => {
if (!response) if (!response)
return void (await interaction.reply({ return void (await interaction.reply({
content: "I don't recall having sent this response, so I cannot correct it.", content: "I don't recall having sent this response, so I cannot correct it.",
ephemeral: true, flags: MessageFlags.Ephemeral,
})) }))
try { try {
@@ -91,7 +95,7 @@ withContext(on, 'interactionCreate', async (context, interaction) => {
logger.error('Failed to handle correct response interaction:', e) logger.error('Failed to handle correct response interaction:', e)
await interaction.reply({ await interaction.reply({
embeds: [createStackTraceEmbed(e)], embeds: [createStackTraceEmbed(e)],
ephemeral: true, flags: MessageFlags.Ephemeral,
}) })
} }
}) })

View File

@@ -1,7 +1,6 @@
import { createErrorEmbed, createStackTraceEmbed, createSuccessEmbed } from '$utils/discord/embeds' import { createErrorEmbed, createStackTraceEmbed, createSuccessEmbed } from '$utils/discord/embeds'
import { on, withContext } from '$utils/discord/events' import { on, withContext } from '$utils/discord/events'
import { MessageFlags, type TextBasedChannel } from 'discord.js'
import type { TextBasedChannel } from 'discord.js'
withContext(on, 'interactionCreate', async (context, interaction) => { withContext(on, 'interactionCreate', async (context, interaction) => {
const { const {
@@ -28,7 +27,7 @@ withContext(on, 'interactionCreate', async (context, interaction) => {
'Thank you for your contribution! Unfortunately, the message could not be found.', 'Thank you for your contribution! Unfortunately, the message could not be found.',
), ),
], ],
ephemeral: true, flags: MessageFlags.Ephemeral,
})) }))
const selectedLabel = interaction.values[0]! const selectedLabel = interaction.values[0]!
@@ -40,13 +39,13 @@ withContext(on, 'interactionCreate', async (context, interaction) => {
`Thank you for your contribution! The selected message is being trained as \`${selectedLabel}\`. 🎉`, `Thank you for your contribution! The selected message is being trained as \`${selectedLabel}\`. 🎉`,
), ),
], ],
ephemeral: true, flags: MessageFlags.Ephemeral,
}) })
} catch (e) { } catch (e) {
logger.error('Failed to handle train message interaction:', e) logger.error('Failed to handle train message interaction:', e)
await interaction.reply({ await interaction.reply({
embeds: [createStackTraceEmbed(e)], embeds: [createStackTraceEmbed(e)],
ephemeral: true, flags: MessageFlags.Ephemeral,
}) })
} }
}) })

View File

@@ -7,60 +7,22 @@ withContext(on, 'messageCreate', async ({ discord, logger }, msg) => {
const store = discord.stickyMessages[msg.guildId]?.[msg.channelId] const store = discord.stickyMessages[msg.guildId]?.[msg.channelId]
if (!store) return if (!store) return
// TODO: Fix this by fixing the logic below // Timer is already active from previous event, and force timer isn't active, so we start the latter
if (store.timerActive && store.forceTimerActive) { if (store.timerActive && store.forceTimerMs && !store.forceTimerActive) {
logger.error( logger.debug(
`Both timers are active in sticky message store: ${msg.guildId}.${msg.channelId}, this should not happen!`, `Channel ${msg.channelId} in guild ${msg.guildId} is very active, starting sticky message force timer`,
) )
logger.info('Clearing the timer and the restarting the force timer...')
clearTimeout(store.timer) // (Re)start the force timer
store.timerActive = false store.forceTimerActive = true
// If the force timer is active, it implies the force timer exists if (store.forceTimer) store.forceTimer.refresh()
store.forceTimer!.refresh() else store.forceTimer = setTimeout(store.send, store.forceTimerMs)
} }
const timerPreviouslyActive = store.timerActive logger.debug(`Channel ${msg.channelId} in guild ${msg.guildId} is active, starting sticky message timer`)
// If there isn't a timer, start it up
// (Re)start the timer
store.timerActive = true store.timerActive = true
if (!store.timer) store.timer = setTimeout(store.send, store.timerMs) as NodeJS.Timeout if (store.timer) store.timer.refresh()
else { else store.timer = setTimeout(store.send, store.timerMs) as NodeJS.Timeout
/*
If:
- (negate carried) There's a timer
- The timer is not active
- The force timer is not active
Then:
- Restart the timer
*/
if (!timerPreviouslyActive && !store.forceTimerActive) store.timer.refresh()
/*
If:
- Any of:
- (negate carried) The timer is active
- (negate carried) The force timer is active
- The force timer is not active
Then:
- Start the force timer and clear the existing timer
*/ else if (!store.forceTimerActive && store.forceTimerMs) {
logger.debug(
`Channel ${msg.channelId} in guild ${msg.guildId} is active, starting force send timer and clearing existing timer`,
)
// Clear the timer
clearTimeout(store.timer)
store.timerActive = false
// (Re)start the force timer
store.forceTimerActive = true
if (!store.forceTimer)
store.forceTimer = setTimeout(
() =>
store.send(true).then(() => {
store.forceTimerActive = false
}),
store.forceTimerMs,
) as NodeJS.Timeout
else store.forceTimer.refresh()
}
}
}) })

View File

@@ -1,7 +1,9 @@
import { MessageScanLabeledResponseReactions as Reactions } from '$/constants' import { MessageScanLabeledResponseReactions as Reactions } from '$/constants'
import { responses } from '$/database/schemas'
import { createErrorEmbed, createStackTraceEmbed, createSuccessEmbed } from '$/utils/discord/embeds' import { createErrorEmbed, createStackTraceEmbed, createSuccessEmbed } from '$/utils/discord/embeds'
import { on, withContext } from '$/utils/discord/events' import { on, withContext } from '$/utils/discord/events'
import { handleUserResponseCorrection } from '$/utils/discord/messageScan'
import { isAdmin } from '$/utils/discord/permissions'
import { import {
ActionRowBuilder, ActionRowBuilder,
ButtonBuilder, ButtonBuilder,
@@ -9,21 +11,17 @@ import {
StringSelectMenuBuilder, StringSelectMenuBuilder,
StringSelectMenuOptionBuilder, StringSelectMenuOptionBuilder,
} from 'discord.js' } from 'discord.js'
import type { ConfigMessageScanResponseLabelConfig } from '$/../config.schema'
import { responses } from '$/database/schemas'
import { handleUserResponseCorrection } from '$/utils/discord/messageScan'
import { isAdmin } from '$/utils/discord/permissions'
import { eq } from 'drizzle-orm' import { eq } from 'drizzle-orm'
import type { ConfigMessageScanResponseLabelConfig } from '$/../config.schema'
const PossibleReactions = Object.values(Reactions) as string[] const PossibleReactions = Object.values(Reactions) as string[]
withContext(on, 'messageReactionAdd', async (context, rct, user) => { withContext(on, 'messageReactionAdd', async (context, rct, user) => {
if (user.bot) return if (user.bot) return
const { database: db, logger, config } = context const { database: db, logger, config } = context
const { messageScan: msConfig } = config const { messageScan: msConfig } = config
// If there's no config, we can't do anything // If there's no config, we can't do anything
if (!msConfig?.humanCorrections) return if (!msConfig?.humanCorrections) return

View File

@@ -1,103 +0,0 @@
import { database, logger } from '$/context'
import { appliedPresets } from '$/database/schemas'
import { applyCommonEmbedStyles } from '$/utils/discord/embeds'
import { on, withContext } from '$/utils/discord/events'
import { removeRolePreset } from '$/utils/discord/rolePresets'
import { lt } from 'drizzle-orm'
import type { Client } from 'discord.js'
export default withContext(on, 'ready', async ({ config, discord, logger }, client) => {
logger.info(`Connected to Discord API, logged in as ${client.user.displayName} (@${client.user.tag})!`)
logger.info(`Bot is in ${client.guilds.cache.size} guilds`)
if (config.stickyMessages)
for (const [guildId, channels] of Object.entries(config.stickyMessages)) {
const guild = await client.guilds.fetch(guildId)
// In case of configuration refresh, this will not be nullable
const oldStore = discord.stickyMessages[guildId]
discord.stickyMessages[guildId] = {}
for (const [channelId, { message, timeout, forceSendTimeout }] of Object.entries(channels)) {
const channel = await guild.channels.fetch(channelId)
if (!channel?.isTextBased())
return void logger.warn(
`Channel ${channelId} in guild ${guildId} is not a text channel, sticky messages will not be sent`,
)
const send = async (forced = false) => {
try {
const msg = await channel.send({
...message,
embeds: message.embeds?.map(it => applyCommonEmbedStyles(it, true, true, true)),
})
const store = discord.stickyMessages[guildId]![channelId]
if (!store) return
await store.currentMessage?.delete().catch()
store.currentMessage = msg
// Clear any remaining timers
clearTimeout(store.timer)
clearTimeout(store.forceTimer)
store.forceTimerActive = store.timerActive = false
if (!forced)
logger.debug(
`Timeout ended for sticky message in channel ${channelId} in guild ${guildId}, channel is inactive`,
)
else
logger.debug(
`Forced send timeout for sticky message in channel ${channelId} in guild ${guildId} ended, channel is too active`,
)
logger.debug(`Sent sticky message to channel ${channelId} in guild ${guildId}`)
} catch (e) {
logger.error(
`Error while sending sticky message to channel ${channelId} in guild ${guildId}:`,
e,
)
}
}
// Set up the store
discord.stickyMessages[guildId]![channelId] = {
forceTimerActive: false,
timerActive: false,
forceTimerMs: forceSendTimeout,
timerMs: timeout,
send,
// If the store exists before the configuration refresh, take its current message
currentMessage: oldStore?.[channelId]?.currentMessage
}
// Send a new sticky message immediately, as well as deleting the old/outdated message, if it exists
await send()
}
}
if (config.rolePresets) {
removeExpiredPresets(client)
setTimeout(() => removeExpiredPresets(client), config.rolePresets.checkExpiredEvery)
}
})
const removeExpiredPresets = async (client: Client) => {
logger.debug('Checking for expired role presets...')
const expireds = await database.query.appliedPresets.findMany({
where: lt(appliedPresets.until, Math.floor(Date.now() / 1000)),
})
for (const expired of expireds)
try {
const guild = await client.guilds.fetch(expired.guildId)
const member = await guild.members.fetch(expired.memberId)
logger.debug(`Removing role preset for ${expired.memberId} in ${expired.guildId}`)
await removeRolePreset(member, expired.preset)
} catch (e) {
logger.error(`Error while removing role preset for ${expired.memberId} in ${expired.guildId}: ${e}`)
}
}

View File

@@ -0,0 +1,6 @@
import { on, withContext } from '$/utils/discord/events'
export default withContext(on, 'ready', async ({ logger }, client) => {
logger.info(`Connected to Discord API, logged in as ${client.user.displayName} (@${client.user.tag})!`)
logger.info(`Bot is in ${client.guilds.cache.size} guilds`)
})

View File

@@ -0,0 +1,42 @@
import { database, logger } from '$/context'
import { appliedPresets } from '$/database/schemas'
import { on, withContext } from '$/utils/discord/events'
import { removeRolePreset } from '$/utils/discord/rolePresets'
import { type Client, DiscordAPIError } from 'discord.js'
import { and, eq, lt } from 'drizzle-orm'
export default withContext(on, 'ready', async ({ config }, client) => {
if (config.rolePresets) {
removeExpiredPresets(client)
setInterval(() => removeExpiredPresets(client), config.rolePresets.checkExpiredEvery)
}
})
async function removeExpiredPresets(client: Client) {
logger.debug('Checking for expired role presets...')
const expireds = await database.query.appliedPresets.findMany({
where: lt(appliedPresets.until, Math.floor(Date.now() / 1000)),
})
for (const expired of expireds) {
try {
logger.debug(`Removing role preset for ${expired.memberId} in ${expired.guildId}`)
const guild = await client.guilds.fetch(expired.guildId)
const member = await guild.members.fetch(expired.memberId)
await removeRolePreset(member, expired.preset)
} catch (e) {
// Unknown Member: https://discord.com/developers/docs/topics/opcodes-and-status-codes#json
if (!(e instanceof DiscordAPIError) || e.code !== 10007) {
logger.error(`Error while removing role preset for ${expired.memberId} in ${expired.guildId}: ${e}`)
continue
}
}
await database
.delete(appliedPresets)
.where(and(eq(appliedPresets.guildId, expired.guildId), eq(appliedPresets.memberId, expired.memberId)))
}
}

View File

@@ -0,0 +1,68 @@
import { applyCommonEmbedStyles } from '$/utils/discord/embeds'
import { on, withContext } from '$/utils/discord/events'
export default withContext(on, 'ready', async ({ config, discord, logger }, client) => {
if (config.stickyMessages)
for (const [guildId, channels] of Object.entries(config.stickyMessages)) {
const guild = await client.guilds.fetch(guildId)
// In case of configuration refresh, this will not be nullable
const oldStore = discord.stickyMessages[guildId]
discord.stickyMessages[guildId] = {}
for (const [channelId, { message, timeout, forceSendTimeout }] of Object.entries(channels)) {
const channel = await guild.channels.fetch(channelId)
if (!channel?.isTextBased())
return void logger.warn(
`Channel ${channelId} in guild ${guildId} is not a text channel, sticky messages will not be sent`,
)
// Set up the store
// biome-ignore lint/suspicious/noAssignInExpressions: don't care
const store = (discord.stickyMessages[guildId]![channelId] = {
forceTimerActive: false,
timerActive: false,
forceTimerMs: forceSendTimeout,
timerMs: timeout,
async send() {
try {
await Promise.all([
channel
.send({
...message,
embeds: message.embeds?.map(it => applyCommonEmbedStyles(it, true, true, true)),
})
.then(msg => {
this.currentMessage = msg
logger.debug(`Sent sticky message to channel ${channelId} in guild ${guildId}`)
}),
this.currentMessage
?.delete()
?.then(() =>
logger.debug(
`Deleted old sticky message from channel ${channelId} in guild ${guildId}`,
),
),
])
} catch (e) {
logger.error(
`Error while managing sticky message of channel ${channelId} in guild ${guildId}:`,
e,
)
} finally {
// Clear any remaining timers
clearTimeout(this.timer)
clearTimeout(this.forceTimer)
this.forceTimerActive = this.timerActive = false
logger.debug(`Cleared sticky message timer for channel ${channelId} in guild ${guildId}`)
}
},
// If the store exists before the configuration refresh, take its current message
currentMessage: oldStore?.[channelId]?.currentMessage,
})
// Send a new sticky message immediately, as well as deleting the old/outdated message, if it exists
await store.send()
}
}
})

View File

@@ -1,5 +1,5 @@
import type { ClientWebSocketEvents } from '@revanced/bot-api'
import * as context from '../../context' import * as context from '../../context'
import type { ClientWebSocketEvents } from '@revanced/bot-api'
const { client } = context.api const { client } = context.api

View File

@@ -1,9 +1,9 @@
import { type Response, responses } from '$/database/schemas' import { type Response, responses } from '$/database/schemas'
import type { Config, ConfigMessageScanResponse, ConfigMessageScanResponseLabelConfig } from 'config.schema'
import { ButtonStyle, ComponentType } from 'discord.js' import { ButtonStyle, ComponentType } from 'discord.js'
import type { APIActionRowComponent, APIButtonComponent, Message, PartialUser, User } from 'discord.js'
import { eq } from 'drizzle-orm' import { eq } from 'drizzle-orm'
import { createMessageScanResponseEmbed } from './embeds' import { createMessageScanResponseEmbed } from './embeds'
import type { Config, ConfigMessageScanResponse, ConfigMessageScanResponseLabelConfig } from 'config.schema'
import type { APIActionRowComponent, APIButtonComponent, Message, PartialUser, User } from 'discord.js'
export const getResponseFromText = async ( export const getResponseFromText = async (
content: string, content: string,

View File

@@ -1,7 +1,7 @@
import { config, logger } from '$/context' import { config, logger } from '$/context'
import decancer from 'decancer' import decancer from 'decancer'
import type { CommandInteraction, EmbedBuilder, Guild, GuildMember, Message, User } from 'discord.js'
import { applyReferenceToModerationActionEmbed, createModerationActionEmbed } from './embeds' import { applyReferenceToModerationActionEmbed, createModerationActionEmbed } from './embeds'
import type { CommandInteraction, EmbedBuilder, Guild, GuildMember, Message, User } from 'discord.js'
const PresetLogAction = { const PresetLogAction = {
apply: 'Applied role preset to', apply: 'Applied role preset to',
@@ -57,7 +57,7 @@ export const cureNickname = async (member: GuildMember) => {
cured = cured =
member.user.username.length >= 3 member.user.username.length >= 3
? member.user.username ? member.user.username
: config.moderation?.cure?.defaultName ?? 'Server member' : (config.moderation?.cure?.defaultName ?? 'Server member')
if (cured.toLowerCase() === name.toLowerCase()) return if (cured.toLowerCase() === name.toLowerCase()) return

View File

@@ -1,7 +1,7 @@
import { config, database } from '$/context' import { config, database } from '$/context'
import { appliedPresets } from '$/database/schemas' import { appliedPresets } from '$/database/schemas'
import type { GuildMember } from 'discord.js'
import { and, eq } from 'drizzle-orm' import { and, eq } from 'drizzle-orm'
import type { GuildMember } from 'discord.js'
// TODO: Fix this type // TODO: Fix this type
type PresetKey = string type PresetKey = string

View File

@@ -1,16 +1,44 @@
import parse from 'parse-duration' import { Duration, DurationFormatter } from '@sapphire/duration'
export const parseDuration = (duration: string) => parse(duration, 'ms') ?? Number.NaN const fmt = new DurationFormatter({
year: {
DEFAULT: 'y',
},
month: {
DEFAULT: 'M',
},
week: {
DEFAULT: 'w',
},
day: {
DEFAULT: 'd',
},
hour: {
DEFAULT: 'h',
},
minute: {
DEFAULT: 'm',
},
second: {
DEFAULT: 's',
},
})
export const parseDuration = (duration: string, defaultUnit = 's') => {
// adds default unit to the end of the string if it doesn't have a unit
// 100 -> 100s
// 10m100 -> 10m100s
// biome-ignore lint/style/noParameterAssign: this is fine
if (/\d$/.test(duration)) duration += defaultUnit
return new Duration(duration).offset
}
export const durationToString = (duration: number) => { export const durationToString = (duration: number) => {
if (duration === 0) return '0s' return fmt.format(duration, undefined, {
left: '',
const days = Math.floor(duration / (24 * 60 * 60 * 1000)) })
const hours = Math.floor((duration % (24 * 60 * 60 * 1000)) / (60 * 60 * 1000)) }
const minutes = Math.floor((duration % (60 * 60 * 1000)) / (60 * 1000))
const seconds = Math.floor((duration % (60 * 1000)) / 1000) export function isSafeTimeoutDuration(duration: number) {
return duration > 0 && duration < 2 ** 31 - 1
return `${days ? `${days}d` : ''}${hours ? `${hours}h` : ''}${minutes ? `${minutes}m` : ''}${
seconds ? `${seconds}s` : ''
}`
} }

1884
bun.lock Normal file

File diff suppressed because it is too large Load Diff

BIN
bun.lockb

Binary file not shown.

View File

@@ -1,7 +1,7 @@
# 🏗️ Setting up the development environment # 🏗️ Setting up the development environment
> [!IMPORTANT] > [!IMPORTANT]
> **This project uses [Bun](https://bun.sh) to run and bundle the code.** > **This project uses [Bun](https://bun.sh) to run and bundle the code.**
> Compatibility with other runtimes (Node.js, Deno, ...) are not guaranteed and most package scripts won't work. > Compatibility with other runtimes (Node.js, Deno, ...) are not guaranteed and most package scripts won't work.
To start developing, you'll need to set up the development environment first. To start developing, you'll need to set up the development environment first.
@@ -11,8 +11,8 @@ To start developing, you'll need to set up the development environment first.
2. Clone the mono-repository 2. Clone the mono-repository
```sh ```sh
git clone https://github.com/revanced/revanced-helper.git && git clone https://github.com/revanced/revanced-bots.git &&
cd revanced-helper cd revanced-bots
``` ```
3. Install dependencies 3. Install dependencies

View File

@@ -1,12 +1,16 @@
{ {
"name": "revanced-helper", "name": "revanced-bots",
"description": "🤖 Bots assisting ReVanced on multiple platforms", "description": "🤖 Bots assisting ReVanced on multiple platforms",
"private": true, "private": true,
"version": "0.0.0", "version": "0.0.0",
"license": "GPL-3.0-or-later", "license": "GPL-3.0-or-later",
"type": "module", "type": "module",
"author": "Palm <contact@palmdevs.me> (https://palmdevs.me)", "author": "Palm <contact@palmdevs.me> (https://palmdevs.me)",
"workspaces": ["packages/*", "apis/*", "bots/*"], "workspaces": [
"packages/*",
"apis/*",
"bots/*"
],
"scripts": { "scripts": {
"build:all": "turbo run build", "build:all": "turbo run build",
"build:packages": "turbo build --filter=\"./packages/*\"", "build:packages": "turbo build --filter=\"./packages/*\"",
@@ -15,37 +19,37 @@
"flint:check": "biome check .", "flint:check": "biome check .",
"clint": "commitlint --edit" "clint": "commitlint --edit"
}, },
"homepage": "https://github.com/revanced/revanced-helper#readme", "homepage": "https://github.com/revanced/revanced-bots#readme",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/revanced/revanced-helper.git" "url": "git+https://github.com/revanced/revanced-bots.git"
}, },
"bugs": { "bugs": {
"url": "https://github.com/revanced/revanced-helper/issues" "url": "https://github.com/revanced/revanced-bots/issues"
}, },
"contributors": [ "contributors": [
"Palm <contact@palmdevs.me> (https://palmdevs.me)", "Palm <contact@palmdevs.me> (https://palmdevs.me)",
"ReVanced <nosupport@revanced.app> (https://revanced.app)" "ReVanced <nosupport@revanced.app> (https://revanced.app)"
], ],
"packageManager": "bun@1.1.20", "packageManager": "bun@1.2.17",
"devDependencies": { "devDependencies": {
"@anolilab/multi-semantic-release": "^1.1.3", "@anolilab/multi-semantic-release": "^2.0.0",
"@biomejs/biome": "^1.9.2", "@biomejs/biome": "^2.0.5",
"@codedependant/semantic-release-docker": "^5.0.3", "@codedependant/semantic-release-docker": "^5.1.1",
"@commitlint/cli": "^19.5.0", "@commitlint/cli": "^19.8.1",
"@commitlint/config-conventional": "^19.5.0", "@commitlint/config-conventional": "^19.8.1",
"@saithodev/semantic-release-backmerge": "^4.0.1", "@saithodev/semantic-release-backmerge": "^4.0.1",
"@semantic-release/changelog": "^6.0.3", "@semantic-release/changelog": "^6.0.3",
"@semantic-release/exec": "^6.0.3", "@semantic-release/exec": "^7.1.0",
"@semantic-release/git": "^10.0.1", "@semantic-release/git": "^10.0.1",
"@tsconfig/strictest": "^2.0.5", "@tsconfig/strictest": "^2.0.5",
"@types/bun": "^1.1.10", "@types/bun": "^1.2.17",
"conventional-changelog-conventionalcommits": "^7.0.2", "conventional-changelog-conventionalcommits": "^9.0.0",
"lefthook": "^1.7.15", "lefthook": "^1.11.14",
"portainer-service-webhook": "https://github.com/newarifrh/portainer-service-webhook#v1", "portainer-service-webhook": "https://github.com/newarifrh/portainer-service-webhook#v1",
"semantic-release": "^24.1.1", "semantic-release": "^24.2.5",
"turbo": "^2.1.2", "turbo": "^2.5.4",
"typescript": "^5.6.2" "typescript": "^5.8.3"
}, },
"trustedDependencies": [ "trustedDependencies": [
"@biomejs/biome", "@biomejs/biome",
@@ -56,6 +60,7 @@
"patchedDependencies": { "patchedDependencies": {
"@semantic-release/npm@12.0.1": "patches/@semantic-release%2Fnpm@12.0.1.patch", "@semantic-release/npm@12.0.1": "patches/@semantic-release%2Fnpm@12.0.1.patch",
"drizzle-kit@0.22.8": "patches/drizzle-kit@0.22.8.patch", "drizzle-kit@0.22.8": "patches/drizzle-kit@0.22.8.patch",
"decancer@3.2.3": "patches/decancer@3.2.3.patch" "decancer@3.2.4": "patches/decancer@3.2.4.patch",
"discord.js@14.18.0": "patches/discord.js@14.18.0.patch"
} }
} }

View File

@@ -13,7 +13,7 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/revanced/revanced-helper.git", "url": "git+https://github.com/revanced/revanced-bots.git",
"directory": "packages/api" "directory": "packages/api"
}, },
"author": "Palm <contact@palmdevs.me> (https://palmdevs.me)", "author": "Palm <contact@palmdevs.me> (https://palmdevs.me)",
@@ -23,15 +23,15 @@
], ],
"license": "GPL-3.0-or-later", "license": "GPL-3.0-or-later",
"bugs": { "bugs": {
"url": "https://github.com/revanced/revanced-helper/issues" "url": "https://github.com/revanced/revanced-bots/issues"
}, },
"homepage": "https://github.com/revanced/revanced-helper#readme", "homepage": "https://github.com/revanced/revanced-bots#readme",
"dependencies": { "dependencies": {
"@revanced/bot-shared": "workspace:*", "@revanced/bot-shared": "workspace:*",
"ws": "^8.17.1" "ws": "^8.18.2"
}, },
"devDependencies": { "devDependencies": {
"@types/ws": "^8.5.10", "@types/ws": "^8.18.1",
"typed-emitter": "^2.1.0" "typed-emitter": "^2.1.0"
} }
} }

View File

@@ -1,16 +1,16 @@
import { EventEmitter } from 'events'
import { import {
type ClientOperation, type ClientOperation,
DisconnectReason, DisconnectReason,
type Packet,
ServerOperation,
deserializePacket, deserializePacket,
isServerPacket, isServerPacket,
type Packet,
ServerOperation,
serializePacket, serializePacket,
uncapitalize, uncapitalize,
} from '@revanced/bot-shared' } from '@revanced/bot-shared'
import type TypedEmitter from 'typed-emitter' import { EventEmitter } from 'events'
import { type RawData, WebSocket } from 'ws' import { type RawData, WebSocket } from 'ws'
import type TypedEmitter from 'typed-emitter'
/** /**
* The class that handles the WebSocket connection to the server. * The class that handles the WebSocket connection to the server.
@@ -35,7 +35,7 @@ export class ClientWebSocketManager {
/** /**
* Sets the URL to connect to * Sets the URL to connect to
* *
* **Requires a reconnect to take effect** * **Requires a reconnect to take effect**
*/ */
async setOptions({ url, timeout }: Partial<ClientWebSocketManagerOptions>, autoReconnect = true) { async setOptions({ url, timeout }: Partial<ClientWebSocketManagerOptions>, autoReconnect = true) {
@@ -207,7 +207,7 @@ export class ClientWebSocketManager {
protected _toBuffer(data: RawData) { protected _toBuffer(data: RawData) {
if (data instanceof Buffer) return data if (data instanceof Buffer) return data
if (data instanceof ArrayBuffer) return Buffer.from(data) if (data instanceof ArrayBuffer) return Buffer.from(data)
return Buffer.concat(data) return Buffer.concat(data as Uint8Array[])
} }
} }

View File

@@ -1,3 +1,3 @@
export { default as Client } from './Client'
export * from './Client' export * from './Client'
export { default as Client } from './Client'
export * from './ClientWebSocket' export * from './ClientWebSocket'

View File

@@ -16,7 +16,7 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/revanced/revanced-helper.git", "url": "git+https://github.com/revanced/revanced-bots.git",
"directory": "packages/shared" "directory": "packages/shared"
}, },
"author": "Palm <contact@palmdevs.me> (https://palmdevs.me)", "author": "Palm <contact@palmdevs.me> (https://palmdevs.me)",
@@ -26,13 +26,13 @@
], ],
"license": "GPL-3.0-or-later", "license": "GPL-3.0-or-later",
"bugs": { "bugs": {
"url": "https://github.com/revanced/revanced-helper/issues" "url": "https://github.com/revanced/revanced-bots/issues"
}, },
"homepage": "https://github.com/revanced/revanced-helper#readme", "homepage": "https://github.com/revanced/revanced-bots#readme",
"dependencies": { "dependencies": {
"bson": "^6.7.0", "bson": "^6.10.4",
"chalk": "^5.3.0", "chalk": "^5.4.1",
"tracer": "^1.3.0", "tracer": "^1.3.0",
"valibot": "^0.30.0" "valibot": "^1.1.0"
} }
} }

View File

@@ -1,17 +1,18 @@
import { import {
type AnySchema, type AnySchema,
type NullSchema,
type ObjectSchema,
type Output,
type BooleanSchema,
array, array,
type BooleanSchema,
boolean,
custom,
enum_, enum_,
type InferOutput,
type NullSchema,
null_, null_,
type ObjectSchema,
object, object,
parse, parse,
special, pipe,
string, string,
boolean,
url, url,
// merge // merge
} from 'valibot' } from 'valibot'
@@ -21,7 +22,7 @@ import { ClientOperation, Operation, ServerOperation } from '../constants/Operat
/** /**
* Schema to validate packets * Schema to validate packets
*/ */
export const PacketSchema = special<Packet>(input => { export const PacketSchema = custom<Packet>(input => {
if ( if (
typeof input === 'object' && typeof input === 'object' &&
input && input &&
@@ -51,7 +52,7 @@ export const PacketDataSchemas = {
labels: array( labels: array(
object({ object({
name: string(), name: string(),
confidence: special<number>(input => typeof input === 'number' && input >= 0 && input <= 1), confidence: custom<number>(input => typeof input === 'number' && input >= 0 && input <= 1),
}), }),
), ),
}), }),
@@ -70,7 +71,7 @@ export const PacketDataSchemas = {
text: string(), text: string(),
}), }),
[ClientOperation.ParseImage]: object({ [ClientOperation.ParseImage]: object({
image_url: string([url()]), image_url: pipe(string(), url()),
}), }),
[ClientOperation.TrainMessage]: object({ [ClientOperation.TrainMessage]: object({
text: string(), text: string(),
@@ -79,7 +80,7 @@ export const PacketDataSchemas = {
} as const satisfies Record< } as const satisfies Record<
Operation, Operation,
// biome-ignore lint/suspicious/noExplicitAny: This is a schema, it's not possible to type it // biome-ignore lint/suspicious/noExplicitAny: This is a schema, it's not possible to type it
ObjectSchema<any> | AnySchema | NullSchema | BooleanSchema ObjectSchema<any, any> | AnySchema | NullSchema<any> | BooleanSchema<any>
> >
export type Packet<TOp extends Operation = Operation> = TOp extends ServerOperation export type Packet<TOp extends Operation = Operation> = TOp extends ServerOperation
@@ -88,6 +89,6 @@ export type Packet<TOp extends Operation = Operation> = TOp extends ServerOperat
type PacketWithSequenceNumber<TOp extends Operation> = { type PacketWithSequenceNumber<TOp extends Operation> = {
op: TOp op: TOp
d: Output<(typeof PacketDataSchemas)[TOp]> d: InferOutput<(typeof PacketDataSchemas)[TOp]>
s: number s: number
} }

View File

@@ -1,5 +1,5 @@
import { Chalk, supportsColor, supportsColorStderr } from 'chalk' import { Chalk, supportsColor, supportsColorStderr } from 'chalk'
import { type Tracer, colorConsole, console as uncoloredConsole } from 'tracer' import { colorConsole, type Tracer, console as uncoloredConsole } from 'tracer'
const chalk = new Chalk() const chalk = new Chalk()
const DefaultConfig = { const DefaultConfig = {

View File

@@ -1,7 +1,7 @@
import * as BSON from 'bson' import * as BSON from 'bson'
import { parse } from 'valibot' import { parse } from 'valibot'
import type { Operation } from '../constants'
import { type Packet, PacketSchema } from '../schemas' import { type Packet, PacketSchema } from '../schemas'
import type { Operation } from '../constants'
/** /**
* Compresses a packet into a buffer * Compresses a packet into a buffer
@@ -18,6 +18,6 @@ export function serializePacket<TOp extends Operation>(packet: Packet<TOp>) {
* @returns A packet * @returns A packet
*/ */
export function deserializePacket(buffer: Buffer) { export function deserializePacket(buffer: Buffer) {
const data = BSON.deserialize(buffer) const data = BSON.deserialize(buffer as Uint8Array)
return parse(PacketSchema, data) as Packet return parse(PacketSchema, data) as Packet
} }

View File

@@ -0,0 +1,17 @@
# Make Message#reply work with { flags: MessageFlags.Ephemeral } in typings
# So our Command system doesn't break
diff --git a/typings/index.d.mts b/typings/index.d.mts
index 645b870..fa93158 100644
--- a/typings/index.d.mts
+++ b/typings/index.d.mts
@@ -6764,8 +6764,8 @@ export interface MessageCreateOptions extends BaseMessageOptionsWithPoll {
stickers?: readonly StickerResolvable[];
flags?:
| BitFieldResolvable<
- Extract<MessageFlagsString, 'SuppressEmbeds' | 'SuppressNotifications'>,
- MessageFlags.SuppressEmbeds | MessageFlags.SuppressNotifications
+ Extract<MessageFlagsString, 'SuppressEmbeds' | 'SuppressNotifications' | 'Ephemeral'>,
+ MessageFlags.SuppressEmbeds | MessageFlags.SuppressNotifications | MessageFlags.Ephemeral
>
| undefined;
}

View File

@@ -11,55 +11,52 @@ const Options = {
prerelease: true, prerelease: true,
}, },
], ],
plugins: plugins: [
process.env['RELEASE_WORKFLOW_STEP'] !== 'publish' [
? [ '@semantic-release/commit-analyzer',
[ {
'@semantic-release/commit-analyzer', releaseRules: [{ type: 'build', scope: 'Needs bump', release: 'patch' }],
{ },
releaseRules: [{ type: 'build', scope: 'Needs bump', release: 'patch' }], ],
}, '@semantic-release/release-notes-generator',
], '@semantic-release/changelog',
'@semantic-release/release-notes-generator', [
'@semantic-release/changelog', '@semantic-release/npm',
[ {
'@semantic-release/npm', npmPublish: false,
{ },
npmPublish: false, ],
}, [
], '@semantic-release/git',
[ {
'@semantic-release/git', assets: ['CHANGELOG.md', 'package.json', '../../bun.lockb'],
{ },
assets: ['CHANGELOG.md', 'package.json', '../../bun.lockb'], ],
}, [
], '@semantic-release/github',
[ {
'@semantic-release/github', assets: [
{ {
assets: [ path: 'dist/*',
{ },
path: 'dist/*', ],
}, successComment: false,
], },
successComment: false, ],
}, // This unfortunately has to run multiple times, even though it needs to run only once.
], [
// This unfortunately has to run multiple times, even though it needs to run only once. '@saithodev/semantic-release-backmerge',
[ {
'@saithodev/semantic-release-backmerge', backmergeBranches: [
{ {
backmergeBranches: [ from: 'main',
{ to: 'dev',
from: 'main', },
to: 'dev', ],
}, clearWorkspace: true,
], },
clearWorkspace: true, ],
}, ],
],
]
: [],
} }
/** /**
@@ -70,6 +67,6 @@ export default function defineSubprojectReleaseConfig(subprojectOptions) {
return { return {
...Options, ...Options,
...subprojectOptions, ...subprojectOptions,
plugins: [...(subprojectOptions.plugins || []), ...(Options.plugins || [])], plugins: [...(Options.plugins || []), ...(subprojectOptions.plugins || [])],
} }
} }