diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/moderation/evidence.ts | 67 | ||||
-rw-r--r-- | src/listeners/commands/commandError.ts | 3 | ||||
-rw-r--r-- | src/listeners/commands/commandStarted.ts | 3 | ||||
-rw-r--r-- | src/listeners/commands/slashStarted.ts | 3 | ||||
-rw-r--r-- | src/listeners/contextCommands/contextCommandError.ts | 3 | ||||
-rw-r--r-- | src/listeners/contextCommands/contextCommandStarted.ts | 3 | ||||
-rw-r--r-- | src/listeners/other/promiseRejection.ts | 3 | ||||
-rw-r--r-- | src/listeners/other/uncaughtException.ts | 3 | ||||
-rw-r--r-- | src/listeners/other/warning.ts | 3 |
9 files changed, 60 insertions, 31 deletions
diff --git a/src/commands/moderation/evidence.ts b/src/commands/moderation/evidence.ts index d60a5b0..9b63189 100644 --- a/src/commands/moderation/evidence.ts +++ b/src/commands/moderation/evidence.ts @@ -1,8 +1,8 @@ import { BushCommand, ModLog, OptArgType, type BushMessage, type BushSlashMessage } from '#lib'; import assert from 'assert'; import { ArgumentGeneratorReturn } from 'discord-akairo'; -import { ArgumentTypeCasterReturn } from 'discord-akairo/dist/src/struct/commands/arguments/Argument.js'; -import { ApplicationCommandOptionType, PermissionFlagsBits } from 'discord.js'; +import { Argument, ArgumentTypeCasterReturn } from 'discord-akairo/dist/src/struct/commands/arguments/Argument.js'; +import { ApplicationCommandOptionType, PermissionFlagsBits, User } from 'discord.js'; export default class EvidenceCommand extends BushCommand { public constructor() { @@ -10,8 +10,8 @@ export default class EvidenceCommand extends BushCommand { aliases: ['evidence'], category: 'moderation', description: 'Add evidence to a modlog case.', - usage: ['evidence <caseId> <evidence>'], - examples: ['evidence IgQvFpzgIKJ77mZ62TEuG was spamming in #general'], + usage: ['evidence <target> <evidence>'], + examples: ['evidence IgQvFpzgIKJ77mZ62TEuG was spamming in #general', 'evidence @IRONMOON too much mod abuse'], args: [ { id: 'case_id', @@ -19,7 +19,17 @@ export default class EvidenceCommand extends BushCommand { type: 'string', prompt: 'What case would you like to modify the evidence of?', slashType: ApplicationCommandOptionType.String, - only: 'slash' + only: 'slash', + optional: true + }, + { + id: 'user', + description: 'The user to modify the evidence of the latest modlog of.', + type: 'user', + prompt: "What user's latest modlog would you like to modify the evidence of?", + slashType: ApplicationCommandOptionType.User, + only: 'slash', + optional: true }, { id: 'evidence', @@ -27,7 +37,8 @@ export default class EvidenceCommand extends BushCommand { type: 'string', prompt: 'What would you like to modify the evidence to?', slashType: ApplicationCommandOptionType.String, - only: 'slash' + only: 'slash', + optional: true } ], slash: true, @@ -38,12 +49,12 @@ export default class EvidenceCommand extends BushCommand { } public override *args(message: BushMessage): ArgumentGeneratorReturn { - const case_id: ArgumentTypeCasterReturn<'string'> = yield { - id: 'case_id', - type: 'string', + const target: ArgumentTypeCasterReturn<'string'> | ArgumentTypeCasterReturn<'snowflake'> = yield { + id: 'target', + type: Argument.union('snowflake', 'string'), prompt: { - start: 'What case would you like to modify the evidence of?', - retry: '{error} Pick a valid case to modify the evidence of.', + start: 'What case or user would you like to modify the evidence of?', + retry: '{error} Pick a valid case id or user to modify the evidence of.', optional: false } }; @@ -59,16 +70,40 @@ export default class EvidenceCommand extends BushCommand { } }; - return { case_id, evidence }; + return { target, evidence }; } public override async exec( message: BushMessage | BushSlashMessage, - { case_id: caseID, evidence }: { case_id: string; evidence: OptArgType<'string'> } + { + case_id: caseID, + user, + target: messageCommandTarget, + evidence + }: { case_id?: string; user?: User; target: string | User; evidence: OptArgType<'string'> } ) { assert(message.inGuild()); - const entry = await ModLog.findByPk(caseID); + if (message.interaction && !caseID && !user) + return message.util.send(`${util.emojis.error} You must provide either a user or a case ID.`); + + const entry = messageCommandTarget + ? typeof messageCommandTarget == 'string' + ? await ModLog.findByPk(messageCommandTarget) + : await ModLog.findOne({ + where: { + user: messageCommandTarget.id + }, + order: [['createdAt', 'DESC']] + }) + : caseID + ? await ModLog.findByPk(caseID) + : await ModLog.findOne({ + where: { + user: user!.id + }, + order: [['createdAt', 'DESC']] + }); if (!entry || entry.pseudo) return message.util.send(`${util.emojis.error} Invalid modlog entry.`); if (entry.guild !== message.guild.id) return message.util.reply(`${util.emojis.error} This modlog is from another server.`); @@ -82,7 +117,9 @@ export default class EvidenceCommand extends BushCommand { client.emit('bushUpdateModlog', message.member!, entry.id, 'evidence', oldEntry, entry.evidence); - return message.util.reply(`${util.emojis.success} Successfully updated the evidence for case ${util.format.input(caseID)}.`); + return message.util.reply( + `${util.emojis.success} Successfully updated the evidence for case ${util.format.input(entry.id)}.` + ); } public static getEvidence(message: BushMessage | BushSlashMessage, evidenceArg: OptArgType<'string'>): null | string { diff --git a/src/listeners/commands/commandError.ts b/src/listeners/commands/commandError.ts index 3768c05..57802bd 100644 --- a/src/listeners/commands/commandError.ts +++ b/src/listeners/commands/commandError.ts @@ -1,5 +1,4 @@ import { type BushCommandHandlerEvents } from '#lib'; -import { Severity } from '@sentry/types'; import { type AkairoMessage, type Command } from 'discord-akairo'; import { EmbedBuilder, Formatters, GuildTextBasedChannel, type Message } from 'discord.js'; import { BushListener } from '../../lib/extensions/discord-akairo/BushListener.js'; @@ -27,7 +26,7 @@ export default class CommandErrorListener extends BushListener { const command = _command ?? message.util.parsed?.command; client.sentry.captureException(error, { - level: Severity.Error, + level: 'error', user: { id: message.author.id, username: message.author.tag }, extra: { 'command.name': command?.id, diff --git a/src/listeners/commands/commandStarted.ts b/src/listeners/commands/commandStarted.ts index 63b906b..02a0b75 100644 --- a/src/listeners/commands/commandStarted.ts +++ b/src/listeners/commands/commandStarted.ts @@ -1,5 +1,4 @@ import { BushListener, type BushCommandHandlerEvents } from '#lib'; -import { Severity } from '@sentry/types'; import { ChannelType } from 'discord.js'; export default class CommandStartedListener extends BushListener { @@ -14,7 +13,7 @@ export default class CommandStartedListener extends BushListener { public override exec(...[message, command]: BushCommandHandlerEvents['commandStarted']): void { client.sentry.addBreadcrumb({ message: `[commandStarted] The ${command.id} was started by ${message.author.tag}.`, - level: Severity.Info, + level: 'info', timestamp: Date.now(), data: { 'command.name': command?.id, diff --git a/src/listeners/commands/slashStarted.ts b/src/listeners/commands/slashStarted.ts index 3e945a9..3d8334d 100644 --- a/src/listeners/commands/slashStarted.ts +++ b/src/listeners/commands/slashStarted.ts @@ -1,5 +1,4 @@ import { BushListener, type BushCommandHandlerEvents } from '#lib'; -import { Severity } from '@sentry/types'; import { ChannelType } from 'discord.js'; export default class SlashStartedListener extends BushListener { @@ -14,7 +13,7 @@ export default class SlashStartedListener extends BushListener { public override async exec(...[message, command]: BushCommandHandlerEvents['slashStarted']) { client.sentry.addBreadcrumb({ message: `[slashStarted] The ${command.id} was started by ${message.author.tag}.`, - level: Severity.Info, + level: 'info', timestamp: Date.now(), data: { 'command.name': command?.id, diff --git a/src/listeners/contextCommands/contextCommandError.ts b/src/listeners/contextCommands/contextCommandError.ts index e020f2b..a532d5e 100644 --- a/src/listeners/contextCommands/contextCommandError.ts +++ b/src/listeners/contextCommands/contextCommandError.ts @@ -1,4 +1,3 @@ -import { Severity } from '@sentry/types'; import { ContextMenuCommand, ContextMenuCommandHandlerEvents } from 'discord-akairo'; import { ContextMenuCommandInteraction, EmbedBuilder, GuildTextBasedChannel } from 'discord.js'; import { BushListener } from '../../lib/extensions/discord-akairo/BushListener.js'; @@ -25,7 +24,7 @@ export default class ContextCommandErrorListener extends BushListener { : (<GuildTextBasedChannel>interaction.channel)?.name; client.sentry.captureException(error, { - level: Severity.Error, + level: 'error', user: { id: interaction.user.id, username: interaction.user.tag }, extra: { 'command.name': command?.id, diff --git a/src/listeners/contextCommands/contextCommandStarted.ts b/src/listeners/contextCommands/contextCommandStarted.ts index c1fec6a..965b8b9 100644 --- a/src/listeners/contextCommands/contextCommandStarted.ts +++ b/src/listeners/contextCommands/contextCommandStarted.ts @@ -1,5 +1,4 @@ import { BushListener } from '#lib'; -import { Severity } from '@sentry/types'; import { ContextMenuCommandHandlerEvents } from 'discord-akairo'; import { ApplicationCommandType, ChannelType } from 'discord.js'; @@ -15,7 +14,7 @@ export default class ContextCommandStartedListener extends BushListener { public override async exec(...[interaction, command]: ContextMenuCommandHandlerEvents['started']) { client.sentry.addBreadcrumb({ message: `[contextCommandStarted] The ${command.id} was started by ${interaction.user.tag}.`, - level: Severity.Info, + level: 'info', timestamp: Date.now(), data: { 'command.name': command?.id, diff --git a/src/listeners/other/promiseRejection.ts b/src/listeners/other/promiseRejection.ts index 1157556..ad82469 100644 --- a/src/listeners/other/promiseRejection.ts +++ b/src/listeners/other/promiseRejection.ts @@ -1,5 +1,4 @@ import { BushListener } from '#lib'; -import { Severity } from '@sentry/node'; import CommandErrorListener from '../commands/commandError.js'; export default class PromiseRejectionListener extends BushListener { @@ -18,7 +17,7 @@ export default class PromiseRejectionListener extends BushListener { }); client.sentry.captureException(error, { - level: Severity.Error + level: 'error' }); void client.console.error( diff --git a/src/listeners/other/uncaughtException.ts b/src/listeners/other/uncaughtException.ts index 4a66515..8eb326f 100644 --- a/src/listeners/other/uncaughtException.ts +++ b/src/listeners/other/uncaughtException.ts @@ -1,5 +1,4 @@ import { BushListener } from '#lib'; -import { Severity } from '@sentry/node'; import CommandErrorListener from '../commands/commandError.js'; export default class UncaughtExceptionListener extends BushListener { @@ -17,7 +16,7 @@ export default class UncaughtExceptionListener extends BushListener { process.removeListener('uncaughtException', listener); }); client.sentry.captureException(error, { - level: Severity.Error + level: 'error' }); void client.console.error('uncaughtException', `An uncaught exception occurred:\n${util.formatError(error, true)}`, false); diff --git a/src/listeners/other/warning.ts b/src/listeners/other/warning.ts index 8e1fdf6..800472a 100644 --- a/src/listeners/other/warning.ts +++ b/src/listeners/other/warning.ts @@ -1,5 +1,4 @@ import { BushListener } from '#lib'; -import { Severity } from '@sentry/node'; import CommandErrorListener from '../commands/commandError.js'; export default class WarningListener extends BushListener { @@ -14,7 +13,7 @@ export default class WarningListener extends BushListener { if (error.name === 'ExperimentalWarning') return; client.sentry.captureException(error, { - level: Severity.Warning + level: 'warning' }); void client.console.warn('warning', `A warning occurred:\n${util.formatError(error, true)}`, false); |