diff --git a/bots/discord/src/constants.ts b/bots/discord/src/constants.ts index 7ab26d6..8e25126 100644 --- a/bots/discord/src/constants.ts +++ b/bots/discord/src/constants.ts @@ -4,12 +4,6 @@ export const MessageScanLabeledResponseReactions = { delete: '❌', } as const -export const MessageScanHumanizedMode = { - ocr: 'image recognition', - nlp: 'text analysis', - match: 'pattern matching', -} as const - export const DefaultEmbedColor = '#4E98F0' export const ReVancedLogoURL = 'https://media.discordapp.net/attachments/1095487869923119144/1115436493050224660/revanced-logo.png' diff --git a/bots/discord/src/events/discord/messageCreate/messageScan.ts b/bots/discord/src/events/discord/messageCreate/messageScan.ts index 6f0ce73..f56e7c3 100644 --- a/bots/discord/src/events/discord/messageCreate/messageScan.ts +++ b/bots/discord/src/events/discord/messageCreate/messageScan.ts @@ -36,7 +36,7 @@ withContext(on, 'messageCreate', async (context, msg) => { const toReply = respondToReply ? (msg.reference?.messageId ? await msg.fetchReference() : msg) : msg const reply = await toReply.reply({ ...response, - embeds: response.embeds?.map(it => createMessageScanResponseEmbed(it, label ? 'nlp' : 'match')), + embeds: response.embeds?.map(createMessageScanResponseEmbed), }) if (label) @@ -74,7 +74,7 @@ withContext(on, 'messageCreate', async (context, msg) => { logger.debug(`Response found for attachment: ${attachment.url}`) await msg.reply({ ...response, - embeds: response.embeds?.map(it => createMessageScanResponseEmbed(it, 'ocr')), + embeds: response.embeds?.map(createMessageScanResponseEmbed), }) break diff --git a/bots/discord/src/utils/discord/embeds.ts b/bots/discord/src/utils/discord/embeds.ts index a486bbb..453a3a8 100644 --- a/bots/discord/src/utils/discord/embeds.ts +++ b/bots/discord/src/utils/discord/embeds.ts @@ -1,4 +1,4 @@ -import { DefaultEmbedColor, MessageScanHumanizedMode, ReVancedLogoURL } from '$/constants' +import { DefaultEmbedColor, ReVancedLogoURL } from '$/constants' import { type APIEmbed, EmbedBuilder, type EmbedField, type JSONEncodable, type User } from 'discord.js' import type { ConfigMessageScanResponseMessage } from '../../../config.schema' @@ -25,12 +25,7 @@ export const createSuccessEmbed = (title: string | null, description?: string) = export const createMessageScanResponseEmbed = ( response: NonNullable[number], - mode: 'ocr' | 'nlp' | 'match', -) => - applyCommonEmbedStyles(response, true, true, true).setFooter({ - text: `ReVanced • Via ${MessageScanHumanizedMode[mode]}`, - iconURL: ReVancedLogoURL, - }) +) => applyCommonEmbedStyles(response, true, true, true) export const createModerationActionEmbed = ( action: string, diff --git a/bots/discord/src/utils/discord/messageScan.ts b/bots/discord/src/utils/discord/messageScan.ts index e1bb281..46c1274 100644 --- a/bots/discord/src/utils/discord/messageScan.ts +++ b/bots/discord/src/utils/discord/messageScan.ts @@ -64,23 +64,26 @@ export const getResponseFromText = async ( const matchedLabel = scan.labels[0]! logger.debug(`Message matched label with confidence: ${matchedLabel.name}, ${matchedLabel.confidence}`) - let triggerConfig: ConfigMessageScanResponseLabelConfig | undefined - const labelConfig = responses.find(x => { + let trigger: ConfigMessageScanResponseLabelConfig | undefined + const response = responses.find(x => { const config = x.triggers.text!.find( (x): x is ConfigMessageScanResponseLabelConfig => 'label' in x && x.label === matchedLabel.name, ) - if (config) triggerConfig = config + if (config) trigger = config return config }) - if (!labelConfig) { - logger.warn(`No label config found for label ${matchedLabel.name}`) + if (!response) { + logger.warn(`No response config found for label ${matchedLabel.name}`) + // This returns the default value set in line 17, which means no response matched return responseConfig } - if (matchedLabel.confidence >= triggerConfig!.threshold) { + responseConfig.label = trigger!.label + + if (matchedLabel.confidence >= trigger!.threshold) { logger.debug('Label confidence is enough') - responseConfig = labelConfig + responseConfig = response } } } @@ -158,7 +161,7 @@ export const handleUserResponseCorrection = async ( await reply.edit({ ...correctLabelResponse.response, - embeds: correctLabelResponse.response.embeds?.map(it => createMessageScanResponseEmbed(it, 'nlp')), + embeds: correctLabelResponse.response.embeds?.map(createMessageScanResponseEmbed), }) }