fix: fix typings and formatting

This commit is contained in:
PalmDevs
2025-03-04 02:27:48 +07:00
parent f6119946f8
commit 479812e199
13 changed files with 43 additions and 38 deletions

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

@@ -110,7 +110,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

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

@@ -43,4 +43,4 @@
"discord-api-types": "^0.37.102", "discord-api-types": "^0.37.102",
"drizzle-kit": "^0.22.8" "drizzle-kit": "^0.22.8"
} }
} }

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

View File

@@ -1,8 +1,8 @@
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 APIStringSelectComponent, ComponentType } from 'discord.js'
import type { ConfigMessageScanResponseLabelConfig } from 'config.schema' import type { ConfigMessageScanResponseLabelConfig } from 'config.schema'
import { type APIStringSelectComponent, ComponentType } from 'discord.js'
import { config } from '../../../context'
const msRcConfig = config.messageScan?.humanCorrections?.allow const msRcConfig = config.messageScan?.humanCorrections?.allow

View File

@@ -9,8 +9,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`)

View File

@@ -8,28 +8,34 @@ withContext(on, 'messageCreate', async ({ discord, logger }, msg) => {
if (!store) return if (!store) return
if (store.timerActive) { if (store.timerActive) {
if (!store.forceTimerActive && store.forceTimerMs) { // Timer is already active, so we try to start the force timer
logger.debug( if (store.forceTimerMs) {
`Channel ${msg.channelId} in guild ${msg.guildId} is active, starting force send timer and clearing existing timer`, // 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 // Clear the timer
clearTimeout(store.timer) clearTimeout(store.timer)
store.timerActive = false store.timerActive = false
// (Re)start the force timer // (Re)start the force timer
store.forceTimerActive = true store.forceTimerActive = true
if (!store.forceTimer) if (!store.forceTimer)
store.forceTimer = setTimeout( store.forceTimer = setTimeout(
() => () =>
store.send(true).then(() => { store.send(true).then(() => {
store.forceTimerActive = false store.forceTimerActive = false
}), }),
store.forceTimerMs, store.forceTimerMs,
) as NodeJS.Timeout ) as NodeJS.Timeout
else store.forceTimer.refresh() else store.forceTimer.refresh()
// Force timer is already active, so we force send
} else store.send()
} }
} else if (!store.forceTimerActive) { } else if (!store.forceTimerActive) {
// Both timers aren't active, so we 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 = 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) => { 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

@@ -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,6 +1,6 @@
import parse from 'parse-duration' import parse from 'parse-duration'
parse[''] = parse['s'] parse[''] = parse['s']!
parse['mo'] = parse['M'] = parse['month']! parse['mo'] = parse['M'] = parse['month']!
const defaultUnitValue = parse['']! const defaultUnitValue = parse['']!

View File

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

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