mirror of
https://github.com/ReVanced/revanced-bots.git
synced 2026-01-17 16:23:58 +00:00
Compare commits
6 Commits
@revanced/
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dfa08397d4 | ||
|
|
9626c4d9ba | ||
|
|
5f74f2dcf8 | ||
|
|
77626c9aed | ||
|
|
2c8740e489 | ||
|
|
6fe15301a2 |
@@ -1,3 +1,17 @@
|
||||
## @revanced/discord-bot [1.5.3](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.5.2...@revanced/discord-bot@1.5.3) (2026-01-17)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **bots/discord:** more logging during apply role preset on member join ([77626c9](https://github.com/revanced/revanced-bots/commit/77626c9aeddceb25c2f0d418bf764efc66669baf))
|
||||
|
||||
## @revanced/discord-bot [1.5.2](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.5.1...@revanced/discord-bot@1.5.2) (2025-09-25)
|
||||
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* **bots/discord:** correct `respondToReply` logic ([6fe1530](https://github.com/revanced/revanced-bots/commit/6fe15301a21fdc196fded8d6fb13236a7bb826f5))
|
||||
|
||||
## @revanced/discord-bot [1.5.1](https://github.com/revanced/revanced-bots/compare/@revanced/discord-bot@1.5.0...@revanced/discord-bot@1.5.1) (2025-09-13)
|
||||
|
||||
|
||||
|
||||
@@ -66,6 +66,7 @@ export default {
|
||||
},
|
||||
},
|
||||
humanCorrections: {
|
||||
falsePositiveLabel: 'false_positive',
|
||||
allow: {
|
||||
members: {
|
||||
permissions: 8n,
|
||||
|
||||
@@ -36,6 +36,7 @@ export type Config = {
|
||||
blacklist?: Filter
|
||||
}
|
||||
humanCorrections: {
|
||||
falsePositiveLabel: string
|
||||
allow?: {
|
||||
users?: string[]
|
||||
members?: {
|
||||
@@ -71,7 +72,7 @@ export type ConfigMessageScanResponse = {
|
||||
image?: Array<RegExp>
|
||||
}
|
||||
filterOverride?: NonNullable<Config['messageScan']>['filter']
|
||||
response: ConfigMessageScanResponseMessage
|
||||
response: ConfigMessageScanResponseMessage | null
|
||||
respondToReply?: boolean | 'only_regex' | 'only_labeled'
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
"name": "@revanced/discord-bot",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"version": "1.5.1",
|
||||
"version": "1.5.3",
|
||||
"description": "🤖 Discord bot assisting ReVanced",
|
||||
"main": "src/index.ts",
|
||||
"scripts": {
|
||||
|
||||
@@ -9,7 +9,7 @@ const msRcConfig = config.messageScan?.humanCorrections?.allow
|
||||
|
||||
export default new Command({
|
||||
name: 'train',
|
||||
description: 'Train a specific message to a specific label',
|
||||
description: 'Train a specific message or text to a specific label',
|
||||
type: Command.Type.ChatGuild,
|
||||
requirements: {
|
||||
users: msRcConfig?.users,
|
||||
@@ -26,9 +26,9 @@ export default new Command({
|
||||
required: true,
|
||||
},
|
||||
label: {
|
||||
description: 'The label to train the message as (leave empty for out of scope)',
|
||||
description: 'The label to train the message as',
|
||||
type: Command.OptionType.String,
|
||||
required: false,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
allowMessageCommand: true,
|
||||
@@ -49,7 +49,7 @@ export default new Command({
|
||||
'This command can only be used in or on text channels',
|
||||
)
|
||||
|
||||
if (label && !labels.includes(label))
|
||||
if (!labels.includes(label))
|
||||
throw new CommandError(
|
||||
CommandErrorType.InvalidArgument,
|
||||
`The provided label is invalid.\nValid labels are:${labels.map(l => `\n- \`${l}\``).join('')}`,
|
||||
@@ -60,14 +60,14 @@ export default new Command({
|
||||
)
|
||||
if (!refMsg) throw new CommandError(CommandErrorType.InvalidArgument, 'The provided message does not exist.')
|
||||
|
||||
logger.debug(`User ${context.executor.id} is training message ${refMsg?.id} as ${label ?? 'out of scope'}`)
|
||||
logger.debug(`User ${context.executor.id} is training message ${refMsg?.id} as ${label}`)
|
||||
|
||||
await context.api.client.trainMessage(refMsg.content, label)
|
||||
await trigger.reply({
|
||||
embeds: [
|
||||
createSuccessEmbed(
|
||||
'Message trained',
|
||||
`The provided message has been trained as ${label ? `\`${label}\`` : 'out of scope'}. Thank you for your contribution!`,
|
||||
`The provided message has been trained as \`${label}\`. Thank you for your contribution!`,
|
||||
),
|
||||
],
|
||||
flags: MessageFlags.Ephemeral,
|
||||
|
||||
@@ -37,10 +37,7 @@ export default new Command({
|
||||
components: [
|
||||
{
|
||||
custom_id: `tr_${trigger.targetMessage.channelId}_${trigger.targetId}`,
|
||||
options: [
|
||||
...labels.map(label => ({ label, value: label })),
|
||||
{ label: 'Out of scope', value: OutOfScopeLabel, emoji: { name: '❌' } },
|
||||
],
|
||||
options: labels.map(label => ({ label, value: label })),
|
||||
type: ComponentType.StringSelect,
|
||||
} satisfies APIStringSelectComponent,
|
||||
],
|
||||
@@ -51,5 +48,3 @@ export default new Command({
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
export const OutOfScopeLabel = '<out of scope>'
|
||||
|
||||
@@ -2,6 +2,7 @@ import { and, eq, gt } from 'drizzle-orm'
|
||||
import { appliedPresets } from '$/database/schemas'
|
||||
import { on, withContext } from '$/utils/discord/events'
|
||||
import { applyRolesUsingPreset } from '$/utils/discord/rolePresets'
|
||||
import { logger } from '$/context'
|
||||
|
||||
withContext(on, 'guildMemberAdd', async ({ database }, member) => {
|
||||
const applieds = await database.query.appliedPresets.findMany({
|
||||
@@ -12,5 +13,12 @@ withContext(on, 'guildMemberAdd', async ({ database }, member) => {
|
||||
),
|
||||
})
|
||||
|
||||
if (!applieds.length) return
|
||||
|
||||
logger.info(
|
||||
`Re-applying role presets for member ${member.id} in guild ${member.guild.id}:`,
|
||||
applieds.map(x => x.preset),
|
||||
)
|
||||
|
||||
for (const { preset } of applieds) await applyRolesUsingPreset(preset, member)
|
||||
})
|
||||
|
||||
@@ -58,8 +58,8 @@ withContext(on, 'interactionCreate', async (context, interaction) => {
|
||||
|
||||
const editMessage = (content: string, description?: string) =>
|
||||
editInteractionMessage(interaction, msg.url, content, description)
|
||||
const handleCorrection = (label?: string) =>
|
||||
handleUserResponseCorrection(context, response, msg, interaction.user, label)
|
||||
const handleCorrection = (label: string) =>
|
||||
handleUserResponseCorrection(context, response, msg, label, interaction.user)
|
||||
|
||||
if (response.correctedById)
|
||||
return await editMessage(
|
||||
@@ -82,7 +82,7 @@ withContext(on, 'interactionCreate', async (context, interaction) => {
|
||||
await editMessage('Canceled', 'You canceled this interaction. 😞')
|
||||
break
|
||||
case 'delete':
|
||||
await handleCorrection()
|
||||
await handleCorrection(msConfig.humanCorrections.falsePositiveLabel)
|
||||
await editMessage(
|
||||
'Marked as false positive',
|
||||
'The response has been deleted and marked as a false positive. Thank you for your feedback. 🎉',
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import { MessageFlags, type TextBasedChannel } from 'discord.js'
|
||||
import { OutOfScopeLabel } from '$/commands/support/train/context-menu'
|
||||
import { createErrorEmbed, createStackTraceEmbed, createSuccessEmbed } from '$utils/discord/embeds'
|
||||
import { on, withContext } from '$utils/discord/events'
|
||||
|
||||
@@ -31,11 +30,8 @@ withContext(on, 'interactionCreate', async (context, interaction) => {
|
||||
flags: MessageFlags.Ephemeral,
|
||||
}))
|
||||
|
||||
const selectedLabel = interaction.values[0]
|
||||
await context.api.client.trainMessage(
|
||||
msg.content,
|
||||
selectedLabel === OutOfScopeLabel ? undefined : selectedLabel,
|
||||
)
|
||||
const selectedLabel = interaction.values[0]!
|
||||
await context.api.client.trainMessage(msg.content, selectedLabel)
|
||||
await interaction.reply({
|
||||
embeds: [
|
||||
createSuccessEmbed(
|
||||
|
||||
@@ -33,14 +33,12 @@ withContext(on, 'messageCreate', async (context, msg) => {
|
||||
if (response) {
|
||||
logger.debug('Response found')
|
||||
|
||||
const toReply = msg.reference?.messageId && (
|
||||
respondToReply === true
|
||||
? true
|
||||
: (respondToReply === 'only_labeled' && label !== undefined) ||
|
||||
(respondToReply === 'only_regex' && label === undefined)
|
||||
)
|
||||
? await msg.fetchReference()
|
||||
: msg
|
||||
const toReply =
|
||||
msg.reference?.messageId &&
|
||||
(respondToReply === true ||
|
||||
(label === undefined ? respondToReply === 'only_regex' : respondToReply === 'only_labeled'))
|
||||
? await msg.fetchReference()
|
||||
: msg
|
||||
|
||||
const reply = await toReply.reply({
|
||||
...response,
|
||||
|
||||
@@ -63,8 +63,8 @@ withContext(on, 'messageReactionAdd', async (context, rct, user) => {
|
||||
|
||||
logger.debug(`User ${user.id} is trying to correct the response ${rct.message.id}`)
|
||||
|
||||
const handleCorrection = (label?: string) =>
|
||||
handleUserResponseCorrection(context, response, reactionMessage, user, label)
|
||||
const handleCorrection = (label: string) =>
|
||||
handleUserResponseCorrection(context, response, reactionMessage, label, user)
|
||||
|
||||
try {
|
||||
if (reaction.emoji.name === Reactions.train) {
|
||||
@@ -106,7 +106,7 @@ withContext(on, 'messageReactionAdd', async (context, rct, user) => {
|
||||
.setCustomId(`${componentPrefix}_cancel`),
|
||||
new ButtonBuilder()
|
||||
.setEmoji(Reactions.delete)
|
||||
.setLabel('Delete (mark as out of scope)')
|
||||
.setLabel('Delete (mark as false positive)')
|
||||
.setStyle(ButtonStyle.Danger)
|
||||
.setCustomId(`${componentPrefix}_delete`),
|
||||
),
|
||||
@@ -117,8 +117,8 @@ withContext(on, 'messageReactionAdd', async (context, rct, user) => {
|
||||
components: rows,
|
||||
})
|
||||
} else if (reaction.emoji.name === Reactions.delete) {
|
||||
await handleCorrection()
|
||||
await user.send({ content: 'The response has been deleted and marked as out of scope.' })
|
||||
await handleCorrection(msConfig.humanCorrections.falsePositiveLabel)
|
||||
await user.send({ content: 'The response has been deleted and marked as a false positive.' })
|
||||
}
|
||||
} catch (e) {
|
||||
logger.error('Failed to correct response:', e)
|
||||
|
||||
@@ -17,7 +17,7 @@ export const getResponseFromText = async (
|
||||
type ResponseConfig = Awaited<ReturnType<typeof getResponseFromText>>
|
||||
let responseConfig: Omit<ResponseConfig, 'triggers'> & { triggers?: ResponseConfig['triggers'] } = {
|
||||
triggers: undefined,
|
||||
response: null!,
|
||||
response: null,
|
||||
}
|
||||
|
||||
const firstLabelIndexes: number[] = []
|
||||
@@ -143,22 +143,15 @@ export const handleUserResponseCorrection = async (
|
||||
{ api, database: db, config: { messageScan: msConfig }, logger }: typeof import('$/context'),
|
||||
response: Response,
|
||||
reply: Message,
|
||||
label: string,
|
||||
user: User | PartialUser,
|
||||
label?: string,
|
||||
) => {
|
||||
if (!label) {
|
||||
await Promise.all([reply.delete(), api.client.trainMessage(response.content, label)]).finally(() =>
|
||||
logger.debug(`User ${user.id} trained message ${response.replyId} as out of scope`),
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const correctLabelResponse = msConfig!.responses!.find(r =>
|
||||
r.triggers.text!.some(t => 'label' in t && t.label === label),
|
||||
)
|
||||
|
||||
if (!correctLabelResponse) throw new Error('Cannot find label config for the selected label')
|
||||
if (!correctLabelResponse.response) return void (await reply.delete())
|
||||
|
||||
if (response.label !== label) {
|
||||
db.update(responses)
|
||||
@@ -175,12 +168,12 @@ export const handleUserResponseCorrection = async (
|
||||
}))
|
||||
}
|
||||
|
||||
await Promise.all([
|
||||
api.client.trainMessage(response.content, label),
|
||||
reply.edit({
|
||||
components: [],
|
||||
}),
|
||||
]).finally(() => logger.debug(`User ${user.id} trained message ${response.replyId} as ${label}`))
|
||||
await api.client.trainMessage(response.content, label)
|
||||
logger.debug(`User ${user.id} trained message ${response.replyId} as ${label} (positive)`)
|
||||
|
||||
await reply.edit({
|
||||
components: [],
|
||||
})
|
||||
}
|
||||
|
||||
export const createMessageScanResponseComponents = (reply: Message<true>) => [
|
||||
|
||||
Reference in New Issue
Block a user