Compare commits

...

44 Commits

Author SHA1 Message Date
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
semantic-release-bot
8aefcdb2e8 chore(release): 1.0.0-dev.31 [skip ci]
# @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)

### Bug Fixes

* **bots/discord:** persist changes in context for eval command ([5b4965d](5b4965dcc7))
2024-09-25 05:46:18 +00:00
PalmDevs
5b4965dcc7 fix(bots/discord): persist changes in context for eval command 2024-09-25 12:43:42 +07:00
semantic-release-bot
37e64a2eb8 chore(release): 1.0.0-dev.30 [skip ci]
# @revanced/discord-bot [1.0.0-dev.30](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.29...@revanced/discord-bot@1.0.0-dev.30) (2024-09-24)

### Features

* **bots/discord:** improve admin commands ([0346741](0346741188))
2024-09-24 23:48:53 +00:00
PalmDevs
59dd803529 chore(bots/discord): temporarily fix timer statuses being both active 2024-09-25 06:47:15 +07:00
PalmDevs
2ef66fbc87 chore(bots/discord): add more debug logs on messageScan 2024-09-25 06:47:13 +07:00
PalmDevs
0346741188 feat(bots/discord): improve admin commands
- The reload command now properly reloads configuration changes by skipping the configuration cache
- The eval command now sends a file if the output is too long
- The eval command now restricts access to the bot token by removing it and sandboxing the input code execution
2024-09-25 06:45:52 +07:00
semantic-release-bot
e0e40237fa chore(release): 1.0.0-dev.29 [skip ci]
# @revanced/discord-bot [1.0.0-dev.29](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.28...@revanced/discord-bot@1.0.0-dev.29) (2024-09-21)

### Bug Fixes

* **bots/discord:** fix get response logic ([3261294](3261294822))
2024-09-21 21:03:36 +00:00
PalmDevs
d3c56222be chore: update dependencies 2024-09-22 04:02:20 +07:00
PalmDevs
3261294822 fix(bots/discord): fix get response logic 2024-09-22 04:01:36 +07:00
semantic-release-bot
f035994f9e chore(release): 1.0.0-dev.28 [skip ci]
# @revanced/discord-bot [1.0.0-dev.28](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.27...@revanced/discord-bot@1.0.0-dev.28) (2024-09-20)

### Bug Fixes

* **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))
2024-09-20 06:53:32 +00:00
PalmDevs
4abac0c890 fix(bots/discord): don't refresh timer if force timer is active for sticky messages 2024-09-20 13:51:56 +07:00
PalmDevs
8c0dd67d03 fix(bots/discord): filter out text triggers correctly from image-only scans 2024-09-20 13:49:38 +07:00
semantic-release-bot
7a379a2cae chore(release): 1.0.0-dev.27 [skip ci]
# @revanced/discord-bot [1.0.0-dev.27](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.26...@revanced/discord-bot@1.0.0-dev.27) (2024-09-05)

### Bug Fixes

* **bots/discord:** correct permission check logic ([dd8872c](dd8872c027))
* **bots/discord:** give only removed roles for role presets ([522ad28](522ad28fd8))
* **bots/discord:** replace duration parser with a library ([94c4fed](94c4fedc06))
2024-09-05 10:34:11 +00:00
Palm
dd8872c027 fix(bots/discord): correct permission check logic
Members were being previously treated as users and some requirements are passing by default when they must not.
2024-09-05 17:33:06 +07:00
semantic-release-bot
33a0e18e7b chore(release): 1.0.0-dev.27 [skip ci]
# @revanced/discord-bot [1.0.0-dev.27](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.26...@revanced/discord-bot@1.0.0-dev.27) (2024-08-23)

### Bug Fixes

* **bots/discord:** give only removed roles for role presets ([522ad28](522ad28fd8))
* **bots/discord:** replace duration parser with a library ([94c4fed](94c4fedc06))
2024-08-23 11:07:18 +00:00
PalmDevs
522ad28fd8 fix(bots/discord): give only removed roles for role presets 2024-08-23 18:05:48 +07:00
PalmDevs
94c4fedc06 fix(bots/discord): replace duration parser with a library 2024-08-23 17:59:02 +07:00
semantic-release-bot
e3dcbab508 chore(release): 1.0.0-dev.26 [skip ci]
# @revanced/discord-bot [1.0.0-dev.26](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.25...@revanced/discord-bot@1.0.0-dev.26) (2024-08-15)

### Bug Fixes

* **bots/discord:** correct timer active condition for sticky messages ([96065ff](96065ff175))
2024-08-15 15:34:29 +00:00
Palm
96065ff175 fix(bots/discord): correct timer active condition for sticky messages 2024-08-15 22:33:12 +07:00
semantic-release-bot
845dd5d914 chore(release): 1.0.0-dev.25 [skip ci]
# @revanced/discord-bot [1.0.0-dev.25](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.24...@revanced/discord-bot@1.0.0-dev.25) (2024-08-15)

### Bug Fixes

* **bots/discord:** allow access to `context` in `/eval` and await result ([99f65f0](99f65f07f5))
2024-08-15 05:11:31 +00:00
Palm
99f65f07f5 fix(bots/discord): allow access to context in /eval and await result 2024-08-15 12:10:04 +07:00
41 changed files with 2344 additions and 204 deletions

View File

@@ -1,3 +1,11 @@
# @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)

View File

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

View File

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

View File

@@ -110,7 +110,7 @@ export default class Client {
protected _toBuffer(data: RawData) {
if (data instanceof Buffer) return data
if (data instanceof ArrayBuffer) return Buffer.from(data)
return Buffer.concat(data)
return Buffer.concat(data as Uint8Array[])
}
}

View File

@@ -1,3 +1,98 @@
# @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)
### Bug Fixes
* **bots/discord:** persist changes in context for eval command ([5b4965d](https://github.com/revanced/revanced-helper/commit/5b4965dcc7285676b2b3b6756c249bd56eaf8485))
# @revanced/discord-bot [1.0.0-dev.30](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.29...@revanced/discord-bot@1.0.0-dev.30) (2024-09-24)
### Features
* **bots/discord:** improve admin commands ([0346741](https://github.com/revanced/revanced-helper/commit/03467411882b8598e2c06f389a09ef2e201bb43f))
# @revanced/discord-bot [1.0.0-dev.29](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.28...@revanced/discord-bot@1.0.0-dev.29) (2024-09-21)
### Bug Fixes
* **bots/discord:** fix get response logic ([3261294](https://github.com/revanced/revanced-helper/commit/3261294822b0a9faec094536ed5be2d3e1d5e17b))
# @revanced/discord-bot [1.0.0-dev.28](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.27...@revanced/discord-bot@1.0.0-dev.28) (2024-09-20)
### Bug Fixes
* **bots/discord:** don't refresh timer if force timer is active for sticky messages ([4abac0c](https://github.com/revanced/revanced-helper/commit/4abac0c890c0548e14cb56723cae919353a8e726))
* **bots/discord:** filter out text triggers correctly from image-only scans ([8c0dd67](https://github.com/revanced/revanced-helper/commit/8c0dd67d03d5a1747993da08a5bf82a39de43789))
# @revanced/discord-bot [1.0.0-dev.27](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.26...@revanced/discord-bot@1.0.0-dev.27) (2024-09-05)
### Bug Fixes
* **bots/discord:** correct permission check logic ([dd8872c](https://github.com/revanced/revanced-helper/commit/dd8872c027c7e7e1a00f38d659b4d6e79274238c))
* **bots/discord:** give only removed roles for role presets ([522ad28](https://github.com/revanced/revanced-helper/commit/522ad28fd83565e9ca411dbce86c8447574288fd))
* **bots/discord:** replace duration parser with a library ([94c4fed](https://github.com/revanced/revanced-helper/commit/94c4fedc06e20051e4123508e3134b97eb84782a))
# @revanced/discord-bot [1.0.0-dev.27](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.26...@revanced/discord-bot@1.0.0-dev.27) (2024-08-23)
### Bug Fixes
* **bots/discord:** give only removed roles for role presets ([522ad28](https://github.com/revanced/revanced-helper/commit/522ad28fd83565e9ca411dbce86c8447574288fd))
* **bots/discord:** replace duration parser with a library ([94c4fed](https://github.com/revanced/revanced-helper/commit/94c4fedc06e20051e4123508e3134b97eb84782a))
# @revanced/discord-bot [1.0.0-dev.26](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.25...@revanced/discord-bot@1.0.0-dev.26) (2024-08-15)
### Bug Fixes
* **bots/discord:** correct timer active condition for sticky messages ([96065ff](https://github.com/revanced/revanced-helper/commit/96065ff17584ff99a56ca5008327863ca5a7852b))
# @revanced/discord-bot [1.0.0-dev.25](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.24...@revanced/discord-bot@1.0.0-dev.25) (2024-08-15)
### Bug Fixes
* **bots/discord:** allow access to `context` in `/eval` and await result ([99f65f0](https://github.com/revanced/revanced-helper/commit/99f65f07f5f8830c6e8ea4ae171e986af4d3f1f6))
# @revanced/discord-bot [1.0.0-dev.24](https://github.com/revanced/revanced-helper/compare/@revanced/discord-bot@1.0.0-dev.23...@revanced/discord-bot@1.0.0-dev.24) (2024-08-14)

View File

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

View File

@@ -2,7 +2,7 @@
"name": "@revanced/discord-bot",
"type": "module",
"private": true,
"version": "1.0.0-dev.24",
"version": "1.0.0-dev.35",
"description": "🤖 Discord bot assisting ReVanced",
"main": "src/index.ts",
"scripts": {
@@ -14,7 +14,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/revanced/revanced-helper.git",
"url": "git+https://github.com/revanced/revanced-bots.git",
"directory": "bots/discord"
},
"author": "Palm <contact@palmdevs.me> (https://palmdevs.me)",
@@ -24,22 +24,23 @@
],
"license": "GPL-3.0-or-later",
"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": {
"@discordjs/builders": "^1.8.2",
"@discordjs/rest": "^2.3.0",
"@discordjs/builders": "^1.9.0",
"@discordjs/rest": "^2.4.0",
"@revanced/bot-api": "workspace:*",
"@revanced/bot-shared": "workspace:*",
"chalk": "^5.3.0",
"decancer": "^3.2.3",
"discord.js": "^14.15.3",
"drizzle-orm": "^0.31.4"
"decancer": "^3.2.4",
"discord.js": "^14.16.3",
"drizzle-orm": "^0.31.4",
"parse-duration": "^1.1.0"
},
"devDependencies": {
"@libsql/client": "^0.7.0",
"discord-api-types": "^0.37.92",
"discord-api-types": "^0.37.102",
"drizzle-kit": "^0.22.8"
}
}
}

View File

@@ -373,7 +373,7 @@ export default class Command<
memberRequirementsForUsers = 'pass',
} = this.requirements
const member = this.isGuildSpecific() ? null : (executor as GuildMember)
const member = this.isGuildSpecific() ? (executor as GuildMember) : null
const boolDefaultCondition = defaultCondition !== 'fail'
const boolMemberRequirementsForUsers = memberRequirementsForUsers !== 'fail'

View File

@@ -1,8 +1,12 @@
import { unlinkSync, writeFileSync } from 'fs'
import { join } from 'path'
import { inspect } from 'util'
import { createContext, runInContext } from 'vm'
import { ApplicationCommandOptionType } from 'discord.js'
import { AdminCommand } from '$/classes/Command'
import { createSuccessEmbed } from '$/utils/discord/embeds'
import { parseDuration } from '$/utils/duration'
export default new AdminCommand({
name: 'eval',
@@ -18,23 +22,74 @@ export default new AdminCommand({
type: ApplicationCommandOptionType.Boolean,
required: false,
},
['inspect-depth']: {
description: 'How many times to recurse while formatting the object (default: 1)',
type: ApplicationCommandOptionType.Integer,
required: false,
},
timeout: {
description: 'Timeout for the evaluation (default: 10s)',
type: ApplicationCommandOptionType.String,
required: false,
},
},
async execute(_, trigger, { code, 'show-hidden': showHidden }) {
async execute(context, trigger, { code, 'show-hidden': showHidden, timeout, ['inspect-depth']: inspectDepth }) {
const currentToken = context.discord.client.token
const currentEnvToken = process.env['DISCORD_TOKEN']
context.discord.client.token = null
process.env['DISCORD_TOKEN'] = undefined
// This allows developers to access and modify the context object to apply changes
// to the bot while the bot is running, minus malicious actors getting the token to perform malicious actions
const output = await runInContext(
code,
createContext({
...globalThis,
context,
trigger,
}),
{
timeout: parseDuration(timeout ?? '10s'),
filename: 'eval',
displayErrors: true,
},
)
context.discord.client.token = currentToken
process.env['DISCORD_TOKEN'] = currentEnvToken
const inspectedOutput = inspect(output, {
depth: inspectDepth ?? 1,
showHidden,
getters: showHidden,
numericSeparator: true,
showProxy: showHidden,
})
const embed = createSuccessEmbed('Evaluate', `\`\`\`js\n${code}\`\`\``)
const files: string[] = []
const filepath = join(Bun.main, '..', `output-eval-${Date.now()}.js`)
if (inspectedOutput.length > 1000) {
writeFileSync(filepath, inspectedOutput)
files.push(filepath)
embed.addFields({
name: 'Result',
value: '```js\n// (output too long, file uploaded)```',
})
} else
embed.addFields({
name: 'Result',
value: `\`\`\`js\n${inspectedOutput}\`\`\``,
})
await trigger.reply({
ephemeral: true,
embeds: [
createSuccessEmbed('Evaluate', `\`\`\`js\n${code}\`\`\``).addFields({
name: 'Result',
// biome-ignore lint/security/noGlobalEval: This is fine as it's an admin command
value: `\`\`\`js\n${inspect(eval(code), {
depth: 1,
showHidden,
getters: true,
numericSeparator: true,
showProxy: true,
})}\`\`\``,
}),
],
embeds: [embed],
files,
})
if (files.length) unlinkSync(filepath)
},
})

View File

@@ -11,7 +11,10 @@ export default new AdminCommand({
description: 'The type of exception to throw',
type: ApplicationCommandOptionType.String,
required: true,
choices: Object.keys(CommandErrorType).map(k => ({ name: k, value: k })),
choices: [
{ name: 'Process', value: 'Process' },
...Object.keys(CommandErrorType).map(k => ({ name: k, value: k })),
],
},
},
async execute(_, __, { type }) {

View File

@@ -1,14 +1,14 @@
import { AdminCommand } from '$/classes/Command'
import { join, dirname } from 'path'
import type { Config } from 'config.schema'
export default new AdminCommand({
name: 'reload',
description: 'Reload configuration',
async execute(context, trigger) {
const { api, logger, discord } = context
context.config = ((await import(join(dirname(Bun.main), '..', 'config.js'))) as { default: Config }).default
logger.info(`Reload triggered by ${context.executor.tag} (${context.executor.id})`)
logger.debug('Invalidating previous config...')
context.config.invalidate()
if ('deferReply' in trigger) await trigger.deferReply({ ephemeral: true })
@@ -23,7 +23,7 @@ export default new AdminCommand({
api.client.disconnect(true)
api.disconnectCount = 0
api.intentionallyDisconnecting = false
await api.client.connect()
api.client.connect()
logger.info('Reinitializing Discord client to reload configuration...')
await discord.client.destroy()
@@ -32,6 +32,6 @@ export default new AdminCommand({
await discord.client.login(process.env['DISCORD_TOKEN'])
// @ts-expect-error: TypeScript dum
await trigger[('deferReply' in trigger ? 'editReply' : 'reply')]({ content: 'Reloaded configuration' })
await trigger['deferReply' in trigger ? 'editReply' : 'reply']({ content: 'Reloaded configuration' })
},
})

View File

@@ -18,13 +18,14 @@ export default new ModerationCommand({
required: false,
type: ModerationCommand.OptionType.String,
},
dmd: {
description: 'Duration to delete messages (must be from 0 to 7 days)',
dmt: {
description:
'Time duration to delete messages (default time unit is days, must be from 0s to 7d, default is 0s)',
required: false,
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 member = await guild.members.fetch(user).catch(() => {})
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, {
reason: `Banned by moderator ${executor.user.tag} (${executor.id}): ${reason}`,
deleteMessageSeconds: dms,

View File

@@ -14,13 +14,13 @@ export default new ModerationCommand({
required: true,
type: ModerationCommand.OptionType.User,
},
reason: {
description: 'The reason for muting the member',
duration: {
description: 'The duration of the mute (default time unit is minutes)',
required: false,
type: ModerationCommand.OptionType.String,
},
duration: {
description: 'The duration of the mute',
reason: {
description: 'The reason for muting the member',
required: false,
type: ModerationCommand.OptionType.String,
},
@@ -33,7 +33,7 @@ export default new ModerationCommand({
const guild = await interaction.client.guilds.fetch(interaction.guildId)
const member = await guild.members.fetch(user.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)
throw new CommandError(

View File

@@ -11,12 +11,12 @@ const SubcommandOptions = {
type: ModerationCommand.OptionType.User,
},
preset: {
description: 'The preset to apply or remove',
description: 'The preset to manage',
required: true,
type: ModerationCommand.OptionType.String,
},
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,
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.')
if (apply) {
const duration = durationInput ? parseDuration(durationInput) : Infinity
const duration = durationInput ? parseDuration(durationInput, 'm') : Infinity
if (Number.isInteger(duration) && duration! < 1)
throw new CommandError(
CommandErrorType.InvalidArgument,
@@ -83,6 +83,13 @@ export default new ModerationCommand({
removeRolePreset(member, preset)
}, 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

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

View File

@@ -1,9 +1,9 @@
import Command from '$/classes/Command'
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 type { ConfigMessageScanResponseLabelConfig } from 'config.schema'
import type { FetchMessageOptions, MessageResolvable } from 'discord.js'
import { config } from '../../../context'
const msRcConfig = config.messageScan?.humanCorrections?.allow

View File

@@ -1,8 +1,8 @@
import Command from '$/classes/Command'
import CommandError, { CommandErrorType } from '$/classes/CommandError'
import { config } from '../../../context'
import { type APIStringSelectComponent, ComponentType } from 'discord.js'
import type { ConfigMessageScanResponseLabelConfig } from 'config.schema'
import { type APIStringSelectComponent, ComponentType } from 'discord.js'
import { config } from '../../../context'
const msRcConfig = config.messageScan?.humanCorrections?.allow

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

@@ -6,18 +6,19 @@ import { createLogger } from '@revanced/bot-shared'
import { Client as DiscordClient, type Message, Partials } from 'discord.js'
import { drizzle } from 'drizzle-orm/bun-sqlite'
// Export some things first, as commands require them
import config from '../config.js'
export { config }
import * as schemas from './database/schemas'
import type { default as Command, CommandOptionsOptions, CommandType } from './classes/Command'
import { __getConfig, config } from './config'
export { config, __getConfig }
export const logger = createLogger({
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 schemas from './database/schemas'
import type { default as Command, CommandOptionsOptions, CommandType } from './classes/Command'
export const api = {
client: new APIClient({
@@ -79,7 +80,7 @@ export const discord = {
parse: ['users'],
repliedUser: true,
},
partials: [Partials.Message, Partials.Reaction],
partials: [Partials.Message, Partials.Reaction, Partials.GuildMember],
}),
commands: Object.fromEntries(Object.values(commands).map(cmd => [cmd.name, cmd])) as Record<
string,

View File

@@ -16,6 +16,7 @@ export const appliedPresets = sqliteTable(
{
memberId: text('member').notNull(),
guildId: text('guild').notNull(),
removedRoles: text('roles', { mode: 'json' }).notNull().$type<string[]>().default([]),
preset: text('preset').notNull(),
until: integer('until'),
},

View File

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

View File

@@ -12,5 +12,5 @@ withContext(on, 'guildMemberAdd', async ({ database }, member) => {
),
})
for (const { preset } of applieds) await applyRolesUsingPreset(preset, member, true)
for (const { preset } of applieds) await applyRolesUsingPreset(preset, member)
})

View File

@@ -9,8 +9,7 @@ withContext(on, 'interactionCreate', async (context, interaction) => {
const command = discord.commands[interaction.commandName]
logger.debug(`Command ${interaction.commandName} being invoked by ${interaction.user.tag} via chat`)
if (!command)
return void logger.error(`Chat command ${interaction.commandName} not implemented but registered!!!`)
if (!command) return void logger.error(`Chat command ${interaction.commandName} not implemented but registered!!!`)
try {
logger.debug(`Command ${interaction.commandName} being executed via chat`)

View File

@@ -1,4 +1,3 @@
import { MessageScanLabeledResponseReactions } from '$/constants'
import { responses } from '$/database/schemas'
import { getResponseFromText, messageMatchesFilter } from '$/utils/discord/messageScan'
import { createMessageScanResponseEmbed } from '$utils/discord/embeds'
@@ -22,7 +21,7 @@ withContext(on, 'messageCreate', async (context, msg) => {
if (msg.content.length) {
try {
logger.debug(`Classifying message ${msg.id}`)
logger.debug(`Classifying message ${msg.id}, possible responses is ${filteredResponses.length}`)
const { response, label, respondToReply } = await getResponseFromText(
msg.content,
@@ -48,10 +47,6 @@ withContext(on, 'messageCreate', async (context, msg) => {
label,
content: msg.content,
})
for (const reaction of Object.values(MessageScanLabeledResponseReactions)) {
await reply.react(reaction)
}
}
}
} catch (e) {
@@ -60,16 +55,13 @@ withContext(on, 'messageCreate', async (context, msg) => {
}
if (msg.attachments.size && config.attachments?.scanAttachments) {
logger.debug(`Classifying message attachments for ${msg.id}`)
logger.debug(`Classifying message attachments for ${msg.id}, possible responses is ${filteredResponses.length}`)
for (const attachment of msg.attachments.values()) {
const mimeType = attachment.contentType?.split(';')?.[0]
if (!mimeType) return void logger.warn(`No MIME type for attachment: ${attachment.url}`)
if (
config.attachments.allowedMimeTypes &&
!config.attachments.allowedMimeTypes.includes(mimeType)
) {
if (config.attachments.allowedMimeTypes && !config.attachments.allowedMimeTypes.includes(mimeType)) {
logger.debug(`Disallowed MIME type for attachment: ${attachment.url}, ${mimeType}`)
continue
}
@@ -86,10 +78,14 @@ withContext(on, 'messageCreate', async (context, msg) => {
if (isTextFile) {
const content = await (await fetch(attachment.url)).text()
response = await getResponseFromText(content, filteredResponses, context, { skipApiRequest: true }).then(it => it.response)
response = await getResponseFromText(content, filteredResponses, context, {
textRegexesOnly: true,
}).then(it => it.response)
} else {
const { text: content } = await api.client.parseImage(attachment.url)
response = await getResponseFromText(content, filteredResponses, context, { onlyImageTriggers: true }).then(it => it.response)
response = await getResponseFromText(content, filteredResponses, context, {
imageTriggersOnly: true,
}).then(it => it.response)
}
if (response) {

View File

@@ -7,31 +7,36 @@ withContext(on, 'messageCreate', async ({ discord, logger }, msg) => {
const store = discord.stickyMessages[msg.guildId]?.[msg.channelId]
if (!store) return
// If there isn't a timer, start it up
store.timerActive = true
if (!store.timer) store.timer = setTimeout(store.send, store.timerMs) as NodeJS.Timeout
else {
// If there is a timer, but it isn't active, restart it
if (!store.timerActive) store.timer.refresh()
// If there is a timer and it is active, but the force timer isn't active...
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`)
if (store.timerActive) {
// Timer is already active, so we try to start the force timer
if (store.forceTimerMs) {
// Force timer isn't active, so we start it
if (!store.forceTimerActive) {
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
store.forceTimerActive = true
// Clear the timer
clearTimeout(store.timer)
store.timerActive = false
// (Re)start the force timer
if (!store.forceTimer)
store.forceTimer = setTimeout(
() =>
store.send(true).then(() => {
store.forceTimerActive = false
}),
store.forceTimerMs,
) as NodeJS.Timeout
else store.forceTimer.refresh()
// (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()
// Force timer is already active, so we force send
} else store.send()
}
} else if (!store.forceTimerActive) {
// Both timers aren't active, so we start the timer
store.timerActive = true
if (!store.timer) store.timer = setTimeout(store.send, store.timerMs) as NodeJS.Timeout
}
})

View File

@@ -20,10 +20,10 @@ const PossibleReactions = Object.values(Reactions) as string[]
withContext(on, 'messageReactionAdd', async (context, rct, user) => {
if (user.bot) return
const { database: db, logger, config } = context
const { messageScan: msConfig } = config
// If there's no config, we can't do anything
if (!msConfig?.humanCorrections) return

View File

@@ -3,7 +3,7 @@ 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 { and, eq, lt } from 'drizzle-orm'
import type { Client } from 'discord.js'
@@ -60,7 +60,7 @@ export default withContext(on, 'ready', async ({ config, discord, logger }, clie
)
}
}
// Set up the store
discord.stickyMessages[guildId]![channelId] = {
forceTimerActive: false,
@@ -69,7 +69,7 @@ export default withContext(on, 'ready', async ({ config, discord, logger }, clie
timerMs: timeout,
send,
// If the store exists before the configuration refresh, take its current message
currentMessage: oldStore?.[channelId]?.currentMessage
currentMessage: oldStore?.[channelId]?.currentMessage,
}
// Send a new sticky message immediately, as well as deleting the old/outdated message, if it exists
@@ -92,11 +92,15 @@ const removeExpiredPresets = async (client: Client) => {
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)
logger.debug(`Removing role preset for ${expired.memberId} in ${expired.guildId}`)
await removeRolePreset(member, expired.preset)
await database
.delete(appliedPresets)
.where(and(eq(appliedPresets.guildId, expired.guildId), eq(appliedPresets.memberId, expired.memberId)))
} catch (e) {
logger.error(`Error while removing role preset for ${expired.memberId} in ${expired.guildId}: ${e}`)
}

View File

@@ -1,6 +1,7 @@
import { type Response, responses } from '$/database/schemas'
import type { Config, ConfigMessageScanResponse, ConfigMessageScanResponseLabelConfig } from 'config.schema'
import type { Message, PartialUser, User } 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 { createMessageScanResponseEmbed } from './embeds'
@@ -9,7 +10,7 @@ export const getResponseFromText = async (
responses: ConfigMessageScanResponse[],
// Just to be safe that we will never use data from the context parameter
{ api, logger }: Omit<typeof import('src/context'), 'config'>,
flags: { onlyImageTriggers?: boolean; skipApiRequest?: boolean } = {}
flags: { imageTriggersOnly?: boolean; textRegexesOnly?: boolean } = {},
): Promise<
Omit<ConfigMessageScanResponse, 'triggers'> & { label?: string; triggers?: ConfigMessageScanResponse['triggers'] }
> => {
@@ -31,7 +32,7 @@ export const getResponseFromText = async (
triggers: { text: textTriggers, image: imageTriggers },
} = trigger
if (flags.onlyImageTriggers) {
if (flags.imageTriggersOnly) {
if (imageTriggers)
for (const regex of imageTriggers)
if (regex.test(content)) {
@@ -39,7 +40,7 @@ export const getResponseFromText = async (
responseConfig = trigger
break
}
} else
} else {
for (let j = 0; j < textTriggers!.length; j++) {
const regex = textTriggers![j]!
@@ -54,10 +55,11 @@ export const getResponseFromText = async (
break
}
}
}
}
// If none of the regexes match, we can search for labels immediately
if (!responseConfig.triggers && !flags.onlyImageTriggers && !flags.skipApiRequest) {
if (!responseConfig.triggers && !flags.textRegexesOnly) {
logger.debug('No match from before regexes, doing NLP')
const scan = await api.client.parseText(content)
if (scan.labels.length) {
@@ -87,7 +89,7 @@ export const getResponseFromText = async (
}
// If we still don't have a response config, we can match all regexes after the initial label trigger
if (!responseConfig.triggers && flags.onlyImageTriggers) {
if (!responseConfig.triggers && !flags.imageTriggersOnly) {
logger.debug('No match from NLP, doing after regexes')
for (let i = 0; i < responses.length; i++) {
const {
@@ -159,14 +161,41 @@ export const handleUserResponseCorrection = async (
})
.where(eq(responses.replyId, response.replyId))
await reply.edit({
return void (await reply.edit({
...correctLabelResponse.response,
embeds: correctLabelResponse.response.embeds?.map(createMessageScanResponseEmbed),
})
components: [],
}))
}
await api.client.trainMessage(response.content, label)
logger.debug(`User ${user.id} trained message ${response.replyId} as ${label} (positive)`)
await reply.reactions.removeAll()
await reply.edit({
components: [],
})
}
export const createMessageScanResponseComponents = (reply: Message<true>) => [
{
type: ComponentType.ActionRow,
components: [
{
type: ComponentType.Button,
style: ButtonStyle.Secondary,
emoji: {
id: '👍',
},
custom_id: `train:${reply.id}`,
},
{
type: ComponentType.Button,
style: ButtonStyle.Secondary,
emoji: {
id: '🔧',
},
custom_id: `edit:${reply.id}`,
},
],
} as APIActionRowComponent<APIButtonComponent>,
]

View File

@@ -23,10 +23,7 @@ export const sendPresetReplyAndLogs = (
]),
)
export const sendModerationReplyAndLogs = async (
interaction: CommandInteraction | Message,
embed: EmbedBuilder,
) => {
export const sendModerationReplyAndLogs = async (interaction: CommandInteraction | Message, embed: EmbedBuilder) => {
const reply = await interaction.reply({ embeds: [embed] }).then(it => it.fetch())
const logChannel = await getLogChannel(interaction.guild!)
await logChannel?.send({ embeds: [applyReferenceToModerationActionEmbed(embed, reply.url)] })
@@ -60,7 +57,7 @@ export const cureNickname = async (member: GuildMember) => {
cured =
member.user.username.length >= 3
? member.user.username
: config.moderation?.cure?.defaultName ?? 'Server member'
: (config.moderation?.cure?.defaultName ?? 'Server member')
if (cured.toLowerCase() === name.toLowerCase()) return

View File

@@ -7,7 +7,7 @@ import { and, eq } from 'drizzle-orm'
type PresetKey = string
export const applyRolePreset = async (member: GuildMember, presetName: PresetKey, expires: number) => {
const afterInsert = await applyRolesUsingPreset(presetName, member, true)
const { removed, callback } = await applyRolesUsingPreset(presetName, member)
const until = expires === Infinity ? null : Math.ceil(expires / 1000)
await database
@@ -16,39 +16,60 @@ export const applyRolePreset = async (member: GuildMember, presetName: PresetKey
memberId: member.id,
guildId: member.guild.id,
preset: presetName,
removedRoles: removed,
until,
})
.onConflictDoUpdate({
target: [appliedPresets.memberId, appliedPresets.preset, appliedPresets.guildId],
set: { until },
})
.then(afterInsert)
.then(callback)
}
export const removeRolePreset = async (member: GuildMember, presetName: PresetKey) => {
const afterDelete = await applyRolesUsingPreset(presetName, member, false)
const where = and(
eq(appliedPresets.memberId, member.id),
eq(appliedPresets.preset, presetName),
eq(appliedPresets.guildId, member.guild.id),
)
await database
.delete(appliedPresets)
.where(
and(
eq(appliedPresets.memberId, member.id),
eq(appliedPresets.preset, presetName),
eq(appliedPresets.guildId, member.guild.id),
),
)
.execute()
.then(afterDelete)
const data = await database.query.appliedPresets.findFirst({ where })
if (!data) return false
const { callback } = await applyRolesUsingPreset(presetName, member, data.removedRoles)
await database.delete(appliedPresets).where(where).execute().then(callback)
return true
}
export const applyRolesUsingPreset = async (presetName: string, member: GuildMember, applying: boolean) => {
export const applyRolesUsingPreset = async (
presetName: string,
member: GuildMember,
removePresetGiveRoles?: string[],
) => {
const preset = config.rolePresets?.guilds[member.guild.id]?.[presetName]
if (!preset) throw new Error(`The preset "${presetName}" does not exist for this server`)
const roles = new Set(member.roles.cache.keys())
const removed: string[] = []
for (const role of preset.give) roles[applying ? 'add' : 'delete'](role)
for (const role of preset.take) roles[applying ? 'delete' : 'add'](role)
// If removePresetGiveRoles is not provided, we're applying a preset
if (!removePresetGiveRoles) {
for (const role of preset.give) roles.add(role)
for (const role of preset.take) {
if (roles.has(role)) {
roles.delete(role)
removed.push(role)
}
}
} else {
const guildRoles = await member.guild.roles.fetch()
for (const role of preset.give) roles.delete(role)
for (const role of removePresetGiveRoles) if (guildRoles.has(role)) roles.add(role)
}
return () => member.roles.set(Array.from(roles))
return {
removed,
callback: () => member.roles.set(Array.from(roles)),
}
}

View File

@@ -1,16 +1,16 @@
export const parseDuration = (duration: string) => {
if (!duration.length) return Number.NaN
const matches = duration.match(/(?:(\d+y)?(\d+M)?(\d+w)?(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s?)/)!
import parse from 'parse-duration'
const [, years, months, weeks, days, hours, minutes, seconds] = matches.map(Number)
parse[''] = parse['s']!
parse['mo'] = parse['M'] = parse['month']!
const defaultUnitValue = parse['']!
export const parseDuration = (duration: string, defaultUnit?: parse.Units) => {
if (defaultUnit) parse[''] = parse[defaultUnit]!
return (
(years || 0) * 290304e5 +
(months || 0) * 24192e5 +
(weeks || 0) * 6048e5 +
(days || 0) * 864e5 +
(hours || 0) * 36e5 +
(minutes || 0) * 6e4 +
(seconds || 0) * 1e3
// biome-ignore lint/suspicious/noAssignInExpressions: Expression is ignored
// biome-ignore lint/style/noCommaOperator: The last expression (parse call) is returned, it is not confusing
(parse[''] = defaultUnitValue), parse(duration, 'ms') ?? Number.NaN
)
}

1892
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
> [!IMPORTANT]
> **This project uses [Bun](https://bun.sh) to run and bundle the code.**
> [!IMPORTANT]
> **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.
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
```sh
git clone https://github.com/revanced/revanced-helper.git &&
cd revanced-helper
git clone https://github.com/revanced/revanced-bots.git &&
cd revanced-bots
```
3. Install dependencies

View File

@@ -1,5 +1,5 @@
{
"name": "revanced-helper",
"name": "revanced-bots",
"description": "🤖 Bots assisting ReVanced on multiple platforms",
"private": true,
"version": "0.0.0",
@@ -15,13 +15,13 @@
"flint:check": "biome check .",
"clint": "commitlint --edit"
},
"homepage": "https://github.com/revanced/revanced-helper#readme",
"homepage": "https://github.com/revanced/revanced-bots#readme",
"repository": {
"type": "git",
"url": "git+https://github.com/revanced/revanced-helper.git"
"url": "git+https://github.com/revanced/revanced-bots.git"
},
"bugs": {
"url": "https://github.com/revanced/revanced-helper/issues"
"url": "https://github.com/revanced/revanced-bots/issues"
},
"contributors": [
"Palm <contact@palmdevs.me> (https://palmdevs.me)",
@@ -29,23 +29,23 @@
],
"packageManager": "bun@1.1.20",
"devDependencies": {
"@anolilab/multi-semantic-release": "^1.1.3",
"@biomejs/biome": "^1.8.3",
"@codedependant/semantic-release-docker": "^5.0.3",
"@commitlint/cli": "^19.3.0",
"@commitlint/config-conventional": "^19.2.2",
"@anolilab/multi-semantic-release": "^1.1.10",
"@biomejs/biome": "^1.9.4",
"@codedependant/semantic-release-docker": "^5.1.0",
"@commitlint/cli": "^19.7.1",
"@commitlint/config-conventional": "^19.7.1",
"@saithodev/semantic-release-backmerge": "^4.0.1",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/exec": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"@tsconfig/strictest": "^2.0.5",
"@types/bun": "^1.1.6",
"@types/bun": "^1.2.4",
"conventional-changelog-conventionalcommits": "^7.0.2",
"lefthook": "^1.7.5",
"lefthook": "^1.11.2",
"portainer-service-webhook": "https://github.com/newarifrh/portainer-service-webhook#v1",
"semantic-release": "^24.0.0",
"turbo": "^2.0.9",
"typescript": "^5.5.4"
"semantic-release": "^24.2.3",
"turbo": "^2.4.4",
"typescript": "^5.8.2"
},
"trustedDependencies": [
"@biomejs/biome",
@@ -56,6 +56,6 @@
"patchedDependencies": {
"@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",
"decancer@3.2.3": "patches/decancer@3.2.3.patch"
"decancer@3.2.4": "patches/decancer@3.2.4.patch"
}
}

View File

@@ -13,7 +13,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/revanced/revanced-helper.git",
"url": "git+https://github.com/revanced/revanced-bots.git",
"directory": "packages/api"
},
"author": "Palm <contact@palmdevs.me> (https://palmdevs.me)",
@@ -23,15 +23,15 @@
],
"license": "GPL-3.0-or-later",
"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": {
"@revanced/bot-shared": "workspace:*",
"ws": "^8.17.1"
"ws": "^8.18.0"
},
"devDependencies": {
"@types/ws": "^8.5.10",
"@types/ws": "^8.5.12",
"typed-emitter": "^2.1.0"
}
}

View File

@@ -35,7 +35,7 @@ export class ClientWebSocketManager {
/**
* Sets the URL to connect to
*
*
* **Requires a reconnect to take effect**
*/
async setOptions({ url, timeout }: Partial<ClientWebSocketManagerOptions>, autoReconnect = true) {
@@ -207,7 +207,7 @@ export class ClientWebSocketManager {
protected _toBuffer(data: RawData) {
if (data instanceof Buffer) return data
if (data instanceof ArrayBuffer) return Buffer.from(data)
return Buffer.concat(data)
return Buffer.concat(data as Uint8Array[])
}
}

View File

@@ -16,7 +16,7 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/revanced/revanced-helper.git",
"url": "git+https://github.com/revanced/revanced-bots.git",
"directory": "packages/shared"
},
"author": "Palm <contact@palmdevs.me> (https://palmdevs.me)",
@@ -26,11 +26,11 @@
],
"license": "GPL-3.0-or-later",
"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": {
"bson": "^6.7.0",
"bson": "^6.8.0",
"chalk": "^5.3.0",
"tracer": "^1.3.0",
"valibot": "^0.30.0"

View File

@@ -1,18 +1,18 @@
import {
url,
type AnySchema,
type BooleanSchema,
type NullSchema,
type ObjectSchema,
type Output,
type BooleanSchema,
array,
boolean,
enum_,
null_,
object,
parse,
special,
string,
boolean,
url,
// merge
} from 'valibot'
import DisconnectReason from '../constants/DisconnectReason'

View File

@@ -18,6 +18,6 @@ export function serializePacket<TOp extends Operation>(packet: Packet<TOp>) {
* @returns A packet
*/
export function deserializePacket(buffer: Buffer) {
const data = BSON.deserialize(buffer)
const data = BSON.deserialize(buffer as Uint8Array)
return parse(PacketSchema, data) as Packet
}