diff --git a/bots/discord/config.js b/bots/discord/config.js index fb05c8e..16d79b4 100644 --- a/bots/discord/config.js +++ b/bots/discord/config.js @@ -55,12 +55,16 @@ export default { text: [/^regexp?$/, { label: 'label', threshold: 0.85 }], }, response: { - title: 'Embed title', - description: 'Embed description', - fields: [ + embeds: [ { - name: 'Field name', - value: 'Field value', + title: 'Embed title', + description: 'Embed description', + fields: [ + { + name: 'Field name', + value: 'Field value', + }, + ], }, ], }, diff --git a/bots/discord/config.schema.ts b/bots/discord/config.schema.ts index e631e1d..23b2fb9 100644 --- a/bots/discord/config.schema.ts +++ b/bots/discord/config.schema.ts @@ -1,4 +1,4 @@ -import type { APIEmbed } from 'discord.js' +import type { BaseMessageOptions } from 'discord.js' export type Config = { owners: string[] @@ -70,4 +70,4 @@ export type ConfigMessageScanResponseLabelConfig = { threshold: number } -export type ConfigMessageScanResponseMessage = APIEmbed +export type ConfigMessageScanResponseMessage = BaseMessageOptions diff --git a/bots/discord/package.json b/bots/discord/package.json index 32b0156..5ffcf21 100644 --- a/bots/discord/package.json +++ b/bots/discord/package.json @@ -43,4 +43,4 @@ "discord-api-types": "^0.37.92", "drizzle-kit": "^0.22.8" } -} \ No newline at end of file +} diff --git a/bots/discord/src/commands/moderation/mute.ts b/bots/discord/src/commands/moderation/mute.ts index eccaf12..fededd2 100644 --- a/bots/discord/src/commands/moderation/mute.ts +++ b/bots/discord/src/commands/moderation/mute.ts @@ -60,9 +60,10 @@ export default { createModerationActionEmbed('Muted', user, interaction.user, reason, durationMs), ) - if (durationMs) setTimeout(() => { - removeRolePreset(member, 'mute') - }, durationMs) + if (durationMs) + setTimeout(() => { + removeRolePreset(member, 'mute') + }, durationMs) logger.info( `Moderator ${interaction.user.tag} (${interaction.user.id}) muted ${user.tag} (${user.id}) until ${expires} because ${reason}`, diff --git a/bots/discord/src/events/discord/messageCreate/messageScanRequired.ts b/bots/discord/src/events/discord/messageCreate/messageScanRequired.ts index 1ba7ef6..45d9f79 100644 --- a/bots/discord/src/events/discord/messageCreate/messageScanRequired.ts +++ b/bots/discord/src/events/discord/messageCreate/messageScanRequired.ts @@ -27,7 +27,8 @@ withContext(on, 'messageCreate', async (context, msg) => { logger.debug('Response found') const reply = await msg.reply({ - embeds: [createMessageScanResponseEmbed(response, label ? 'nlp' : 'match')], + ...response, + embeds: response.embeds?.map(it => createMessageScanResponseEmbed(it, label ? 'nlp' : 'match')), }) if (label) @@ -64,7 +65,8 @@ withContext(on, 'messageCreate', async (context, msg) => { if (response) { logger.debug(`Response found for attachment: ${attachment.url}`) await msg.reply({ - embeds: [createMessageScanResponseEmbed(response, 'ocr')], + ...response, + embeds: response.embeds?.map(it => createMessageScanResponseEmbed(it, 'ocr')), }) break diff --git a/bots/discord/src/events/discord/messageReactionAdd/correctResponse.ts b/bots/discord/src/events/discord/messageReactionAdd/correctResponse.ts index 701ad2f..74a700d 100644 --- a/bots/discord/src/events/discord/messageReactionAdd/correctResponse.ts +++ b/bots/discord/src/events/discord/messageReactionAdd/correctResponse.ts @@ -46,7 +46,12 @@ withContext(on, 'messageReactionAdd', async (context, rct, user) => { const member = await reactionMessage.guild.members.fetch(user.id) const { permissions, roles } = allowedMembers - if (!((permissions ? member.permissions.has(permissions) : false) || roles?.some(role => member.roles.cache.has(role)))) + if ( + !( + (permissions ? member.permissions.has(permissions) : false) || + roles?.some(role => member.roles.cache.has(role)) + ) + ) return } else if (allowedUsers) { if (!allowedUsers.includes(user.id)) return diff --git a/bots/discord/src/utils/discord/embeds.ts b/bots/discord/src/utils/discord/embeds.ts index 6248bef..cb584cd 100644 --- a/bots/discord/src/utils/discord/embeds.ts +++ b/bots/discord/src/utils/discord/embeds.ts @@ -24,16 +24,19 @@ export const createSuccessEmbed = (title: string | null, description?: string) = ) export const createMessageScanResponseEmbed = ( - response: ConfigMessageScanResponseMessage, + response: NonNullable[number], mode: 'ocr' | 'nlp' | 'match', ) => { + // biome-ignore lint/style/noParameterAssign: While this is confusing, it is fine for this purpose + if ('toJSON' in response) response = response.toJSON() + const embed = new EmbedBuilder().setTitle(response.title ?? null) if (response.description) embed.setDescription(response.description) if (response.fields) embed.addFields(response.fields) embed.setFooter({ - text: `ReVanced • Done via ${MessageScanHumanizedMode[mode]}`, + text: `ReVanced • Via ${MessageScanHumanizedMode[mode]}`, iconURL: ReVancedLogoURL, }) diff --git a/bots/discord/src/utils/discord/messageScan.ts b/bots/discord/src/utils/discord/messageScan.ts index 41f6f18..fa86ce5 100644 --- a/bots/discord/src/utils/discord/messageScan.ts +++ b/bots/discord/src/utils/discord/messageScan.ts @@ -158,8 +158,10 @@ export const handleUserResponseCorrection = async ( correctedById: user.id, }) .where(eq(responses.replyId, response.replyId)) + await reply.edit({ - embeds: [createMessageScanResponseEmbed(correctLabelResponse.response, 'nlp')], + ...correctLabelResponse.response, + embeds: correctLabelResponse.response.embeds?.map(it => createMessageScanResponseEmbed(it, 'nlp')), }) }