diff --git a/apis/websocket/scripts/build.ts b/apis/websocket/scripts/build.ts index effc23d..cfdf7be 100644 --- a/apis/websocket/scripts/build.ts +++ b/apis/websocket/scripts/build.ts @@ -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({ diff --git a/apis/websocket/src/classes/Client.ts b/apis/websocket/src/classes/Client.ts index 291a621..2299fcd 100755 --- a/apis/websocket/src/classes/Client.ts +++ b/apis/websocket/src/classes/Client.ts @@ -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[]) } } diff --git a/bots/discord/config.js b/bots/discord/config.js index 66b1b14..1b04f24 100644 --- a/bots/discord/config.js +++ b/bots/discord/config.js @@ -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: [ { diff --git a/bots/discord/package.json b/bots/discord/package.json index 0718c78..50e7545 100644 --- a/bots/discord/package.json +++ b/bots/discord/package.json @@ -43,4 +43,4 @@ "discord-api-types": "^0.37.102", "drizzle-kit": "^0.22.8" } -} \ No newline at end of file +} diff --git a/bots/discord/src/commands/support/train/chat.ts b/bots/discord/src/commands/support/train/chat.ts index 572d8c5..45ae34c 100644 --- a/bots/discord/src/commands/support/train/chat.ts +++ b/bots/discord/src/commands/support/train/chat.ts @@ -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 diff --git a/bots/discord/src/commands/support/train/context-menu.ts b/bots/discord/src/commands/support/train/context-menu.ts index 50dab3f..cb343cd 100644 --- a/bots/discord/src/commands/support/train/context-menu.ts +++ b/bots/discord/src/commands/support/train/context-menu.ts @@ -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 diff --git a/bots/discord/src/events/discord/interactionCreate/chatCommand.ts b/bots/discord/src/events/discord/interactionCreate/chatCommand.ts index 8807d72..3ae139e 100644 --- a/bots/discord/src/events/discord/interactionCreate/chatCommand.ts +++ b/bots/discord/src/events/discord/interactionCreate/chatCommand.ts @@ -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`) diff --git a/bots/discord/src/events/discord/messageCreate/stickyMessageReset.ts b/bots/discord/src/events/discord/messageCreate/stickyMessageReset.ts index e55122b..8a7a4f5 100644 --- a/bots/discord/src/events/discord/messageCreate/stickyMessageReset.ts +++ b/bots/discord/src/events/discord/messageCreate/stickyMessageReset.ts @@ -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 } diff --git a/bots/discord/src/events/discord/messageReactionAdd/correctResponse.ts b/bots/discord/src/events/discord/messageReactionAdd/correctResponse.ts index 04b765c..23a536a 100644 --- a/bots/discord/src/events/discord/messageReactionAdd/correctResponse.ts +++ b/bots/discord/src/events/discord/messageReactionAdd/correctResponse.ts @@ -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 diff --git a/bots/discord/src/utils/discord/moderation.ts b/bots/discord/src/utils/discord/moderation.ts index f8a4ad0..64704fa 100644 --- a/bots/discord/src/utils/discord/moderation.ts +++ b/bots/discord/src/utils/discord/moderation.ts @@ -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 diff --git a/bots/discord/src/utils/duration.ts b/bots/discord/src/utils/duration.ts index 8e3074a..a9c1407 100644 --- a/bots/discord/src/utils/duration.ts +++ b/bots/discord/src/utils/duration.ts @@ -1,6 +1,6 @@ import parse from 'parse-duration' -parse[''] = parse['s'] +parse[''] = parse['s']! parse['mo'] = parse['M'] = parse['month']! const defaultUnitValue = parse['']! diff --git a/packages/api/src/classes/ClientWebSocket.ts b/packages/api/src/classes/ClientWebSocket.ts index 9495322..e4c55d9 100755 --- a/packages/api/src/classes/ClientWebSocket.ts +++ b/packages/api/src/classes/ClientWebSocket.ts @@ -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[]) } } diff --git a/packages/shared/src/utils/serialization.ts b/packages/shared/src/utils/serialization.ts index 59db862..5f9ba26 100755 --- a/packages/shared/src/utils/serialization.ts +++ b/packages/shared/src/utils/serialization.ts @@ -18,6 +18,6 @@ export function serializePacket(packet: Packet) { * @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 }