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 }],
|
text: [/^regexp?$/, { label: 'label', threshold: 0.85 }],
|
||||||
},
|
},
|
||||||
response: {
|
response: {
|
||||||
title: 'Embed title',
|
embeds: [
|
||||||
description: 'Embed description',
|
|
||||||
fields: [
|
|
||||||
{
|
{
|
||||||
name: 'Field name',
|
title: 'Embed title',
|
||||||
value: 'Field value',
|
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 = {
|
export type Config = {
|
||||||
owners: string[]
|
owners: string[]
|
||||||
@@ -70,4 +70,4 @@ export type ConfigMessageScanResponseLabelConfig = {
|
|||||||
threshold: number
|
threshold: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ConfigMessageScanResponseMessage = APIEmbed
|
export type ConfigMessageScanResponseMessage = BaseMessageOptions
|
||||||
|
|||||||
@@ -43,4 +43,4 @@
|
|||||||
"discord-api-types": "^0.37.92",
|
"discord-api-types": "^0.37.92",
|
||||||
"drizzle-kit": "^0.22.8"
|
"drizzle-kit": "^0.22.8"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,9 +60,10 @@ export default {
|
|||||||
createModerationActionEmbed('Muted', user, interaction.user, reason, durationMs),
|
createModerationActionEmbed('Muted', user, interaction.user, reason, durationMs),
|
||||||
)
|
)
|
||||||
|
|
||||||
if (durationMs) setTimeout(() => {
|
if (durationMs)
|
||||||
removeRolePreset(member, 'mute')
|
setTimeout(() => {
|
||||||
}, durationMs)
|
removeRolePreset(member, 'mute')
|
||||||
|
}, durationMs)
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
`Moderator ${interaction.user.tag} (${interaction.user.id}) muted ${user.tag} (${user.id}) until ${expires} because ${reason}`,
|
`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')
|
logger.debug('Response found')
|
||||||
|
|
||||||
const reply = await msg.reply({
|
const reply = await msg.reply({
|
||||||
embeds: [createMessageScanResponseEmbed(response, label ? 'nlp' : 'match')],
|
...response,
|
||||||
|
embeds: response.embeds?.map(it => createMessageScanResponseEmbed(it, label ? 'nlp' : 'match')),
|
||||||
})
|
})
|
||||||
|
|
||||||
if (label)
|
if (label)
|
||||||
@@ -64,7 +65,8 @@ withContext(on, 'messageCreate', async (context, msg) => {
|
|||||||
if (response) {
|
if (response) {
|
||||||
logger.debug(`Response found for attachment: ${attachment.url}`)
|
logger.debug(`Response found for attachment: ${attachment.url}`)
|
||||||
await msg.reply({
|
await msg.reply({
|
||||||
embeds: [createMessageScanResponseEmbed(response, 'ocr')],
|
...response,
|
||||||
|
embeds: response.embeds?.map(it => createMessageScanResponseEmbed(it, 'ocr')),
|
||||||
})
|
})
|
||||||
|
|
||||||
break
|
break
|
||||||
|
|||||||
@@ -46,7 +46,12 @@ withContext(on, 'messageReactionAdd', async (context, rct, user) => {
|
|||||||
const member = await reactionMessage.guild.members.fetch(user.id)
|
const member = await reactionMessage.guild.members.fetch(user.id)
|
||||||
const { permissions, roles } = allowedMembers
|
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
|
return
|
||||||
} else if (allowedUsers) {
|
} else if (allowedUsers) {
|
||||||
if (!allowedUsers.includes(user.id)) return
|
if (!allowedUsers.includes(user.id)) return
|
||||||
|
|||||||
@@ -24,16 +24,19 @@ export const createSuccessEmbed = (title: string | null, description?: string) =
|
|||||||
)
|
)
|
||||||
|
|
||||||
export const createMessageScanResponseEmbed = (
|
export const createMessageScanResponseEmbed = (
|
||||||
response: ConfigMessageScanResponseMessage,
|
response: NonNullable<ConfigMessageScanResponseMessage['embeds']>[number],
|
||||||
mode: 'ocr' | 'nlp' | 'match',
|
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)
|
const embed = new EmbedBuilder().setTitle(response.title ?? null)
|
||||||
|
|
||||||
if (response.description) embed.setDescription(response.description)
|
if (response.description) embed.setDescription(response.description)
|
||||||
if (response.fields) embed.addFields(response.fields)
|
if (response.fields) embed.addFields(response.fields)
|
||||||
|
|
||||||
embed.setFooter({
|
embed.setFooter({
|
||||||
text: `ReVanced • Done via ${MessageScanHumanizedMode[mode]}`,
|
text: `ReVanced • Via ${MessageScanHumanizedMode[mode]}`,
|
||||||
iconURL: ReVancedLogoURL,
|
iconURL: ReVancedLogoURL,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -158,8 +158,10 @@ export const handleUserResponseCorrection = async (
|
|||||||
correctedById: user.id,
|
correctedById: user.id,
|
||||||
})
|
})
|
||||||
.where(eq(responses.replyId, response.replyId))
|
.where(eq(responses.replyId, response.replyId))
|
||||||
|
|
||||||
await reply.edit({
|
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