Compare commits

...

13 Commits

Author SHA1 Message Date
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
26 changed files with 2015 additions and 81 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,9 +23,9 @@
],
"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.3",
@@ -37,4 +37,4 @@
"@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,28 @@
# @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)

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.35",
"version": "1.0.0-dev.37",
"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,9 +24,9 @@
],
"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.9.0",
"@discordjs/rest": "^2.4.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.warn('Cleaning previous build...')
await rm('./dist', { recursive: true })
if (await exists('./dist')) await rm('./dist', { recursive: true })
logger.info('Building bot...')
await Bun.build({

View File

@@ -20,7 +20,7 @@ export default new ModerationCommand({
},
dmt: {
description:
'Time duration to delete messages (default time unit is days, must be from 0s to 7d, default value is 0s)',
'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,
},

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

@@ -80,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

@@ -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

@@ -8,28 +8,34 @@ withContext(on, 'messageCreate', async ({ discord, logger }, msg) => {
if (!store) return
if (store.timerActive) {
if (!store.forceTimerActive && store.forceTimerMs) {
logger.debug(
`Channel ${msg.channelId} in guild ${msg.guildId} is active, starting force send timer and clearing existing timer`,
)
// 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
// 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()
// (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'
@@ -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

@@ -57,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

@@ -1,14 +1,14 @@
import parse from 'parse-duration'
const defaultUnitValue = parse['']!
parse[''] = parse['s']!
parse['mo'] = parse['M'] = parse['month']!
export const parseDuration = (duration: string, defaultUnit?: parse.Units) => {
const defaultUnitValue = parse['']!
if (defaultUnit) parse[''] = parse[defaultUnit]!
return (
// 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
)
const result = parse(duration, 'ms') ?? Number.NaN
parse[''] = defaultUnitValue
return result
}
export const durationToString = (duration: number) => {

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.9.3",
"@codedependant/semantic-release-docker": "^5.0.3",
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"@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.11",
"@types/bun": "^1.2.4",
"conventional-changelog-conventionalcommits": "^7.0.2",
"lefthook": "^1.7.21",
"lefthook": "^1.11.2",
"portainer-service-webhook": "https://github.com/newarifrh/portainer-service-webhook#v1",
"semantic-release": "^24.1.2",
"turbo": "^2.1.3",
"typescript": "^5.6.3"
"semantic-release": "^24.2.3",
"turbo": "^2.4.4",
"typescript": "^5.8.2"
},
"trustedDependencies": [
"@biomejs/biome",

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,9 +23,9 @@
],
"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.18.0"

View File

@@ -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,9 +26,9 @@
],
"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.8.0",
"chalk": "^5.3.0",

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
}