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: '❌', delete: '❌',
} as const } as const
export const MessageScanHumanizedMode = {
ocr: 'image recognition',
nlp: 'text analysis',
match: 'pattern matching',
} as const
export const DefaultEmbedColor = '#4E98F0' export const DefaultEmbedColor = '#4E98F0'
export const ReVancedLogoURL = export const ReVancedLogoURL =
'https://media.discordapp.net/attachments/1095487869923119144/1115436493050224660/revanced-logo.png' '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 toReply = respondToReply ? (msg.reference?.messageId ? await msg.fetchReference() : msg) : msg
const reply = await toReply.reply({ const reply = await toReply.reply({
...response, ...response,
embeds: response.embeds?.map(it => createMessageScanResponseEmbed(it, label ? 'nlp' : 'match')), embeds: response.embeds?.map(createMessageScanResponseEmbed),
}) })
if (label) if (label)
@@ -74,7 +74,7 @@ withContext(on, 'messageCreate', async (context, msg) => {
logger.debug(`Response found for attachment: ${attachment.url}`) logger.debug(`Response found for attachment: ${attachment.url}`)
await msg.reply({ await msg.reply({
...response, ...response,
embeds: response.embeds?.map(it => createMessageScanResponseEmbed(it, 'ocr')), embeds: response.embeds?.map(createMessageScanResponseEmbed),
}) })
break 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 APIEmbed, EmbedBuilder, type EmbedField, type JSONEncodable, type User } from 'discord.js'
import type { ConfigMessageScanResponseMessage } from '../../../config.schema' import type { ConfigMessageScanResponseMessage } from '../../../config.schema'
@@ -25,12 +25,7 @@ export const createSuccessEmbed = (title: string | null, description?: string) =
export const createMessageScanResponseEmbed = ( export const createMessageScanResponseEmbed = (
response: NonNullable<ConfigMessageScanResponseMessage['embeds']>[number], response: NonNullable<ConfigMessageScanResponseMessage['embeds']>[number],
mode: 'ocr' | 'nlp' | 'match', ) => applyCommonEmbedStyles(response, true, true, true)
) =>
applyCommonEmbedStyles(response, true, true, true).setFooter({
text: `ReVanced • Via ${MessageScanHumanizedMode[mode]}`,
iconURL: ReVancedLogoURL,
})
export const createModerationActionEmbed = ( export const createModerationActionEmbed = (
action: string, action: string,

View File

@@ -64,23 +64,26 @@ export const getResponseFromText = async (
const matchedLabel = scan.labels[0]! const matchedLabel = scan.labels[0]!
logger.debug(`Message matched label with confidence: ${matchedLabel.name}, ${matchedLabel.confidence}`) logger.debug(`Message matched label with confidence: ${matchedLabel.name}, ${matchedLabel.confidence}`)
let triggerConfig: ConfigMessageScanResponseLabelConfig | undefined let trigger: ConfigMessageScanResponseLabelConfig | undefined
const labelConfig = responses.find(x => { const response = responses.find(x => {
const config = x.triggers.text!.find( const config = x.triggers.text!.find(
(x): x is ConfigMessageScanResponseLabelConfig => 'label' in x && x.label === matchedLabel.name, (x): x is ConfigMessageScanResponseLabelConfig => 'label' in x && x.label === matchedLabel.name,
) )
if (config) triggerConfig = config if (config) trigger = config
return config return config
}) })
if (!labelConfig) { if (!response) {
logger.warn(`No label config found for label ${matchedLabel.name}`) 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 return responseConfig
} }
if (matchedLabel.confidence >= triggerConfig!.threshold) { responseConfig.label = trigger!.label
if (matchedLabel.confidence >= trigger!.threshold) {
logger.debug('Label confidence is enough') logger.debug('Label confidence is enough')
responseConfig = labelConfig responseConfig = response
} }
} }
} }
@@ -158,7 +161,7 @@ export const handleUserResponseCorrection = async (
await reply.edit({ await reply.edit({
...correctLabelResponse.response, ...correctLabelResponse.response,
embeds: correctLabelResponse.response.embeds?.map(it => createMessageScanResponseEmbed(it, 'nlp')), embeds: correctLabelResponse.response.embeds?.map(createMessageScanResponseEmbed),
}) })
} }