aboutsummaryrefslogtreecommitdiff
path: root/src/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands')
-rw-r--r--src/commands/moderation/evidence.ts67
1 files changed, 52 insertions, 15 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 {