fix(bots/discord): remove redundant footer for response embeds

This commit is contained in:
PalmDevs
2024-08-02 18:36:17 +07:00
parent 8fe78e424e
commit 412e00317d
4 changed files with 15 additions and 23 deletions

View File

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

View File

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

View File

@@ -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<ConfigMessageScanResponseMessage['embeds']>[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,

View File

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