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

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