mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-11 13:56:15 +00:00
feat(bots/discord)!: allow message scan response to be message payloads
This commit is contained in:
@@ -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',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -43,4 +43,4 @@
|
||||
"discord-api-types": "^0.37.92",
|
||||
"drizzle-kit": "^0.22.8"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}`,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -24,16 +24,19 @@ export const createSuccessEmbed = (title: string | null, description?: string) =
|
||||
)
|
||||
|
||||
export const createMessageScanResponseEmbed = (
|
||||
response: ConfigMessageScanResponseMessage,
|
||||
response: NonNullable<ConfigMessageScanResponseMessage['embeds']>[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,
|
||||
})
|
||||
|
||||
|
||||
@@ -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')),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user