aboutsummaryrefslogtreecommitdiff
path: root/src/commands
diff options
context:
space:
mode:
authorTymanWasTaken <32660892+TymanWasTaken@users.noreply.github.com>2022-06-11 18:53:09 -0400
committerGitHub <noreply@github.com>2022-06-11 18:53:09 -0400
commit71e4999154956ea469d95f3d6a5711b2f0bb0fc3 (patch)
treed61bc34c08064a03a405b744597879a5c65cd288 /src/commands
parenta2e8aebe4134bedf1052d7a92db8eed6b58b964a (diff)
downloadtanzanite-71e4999154956ea469d95f3d6a5711b2f0bb0fc3.tar.gz
tanzanite-71e4999154956ea469d95f3d6a5711b2f0bb0fc3.tar.bz2
tanzanite-71e4999154956ea469d95f3d6a5711b2f0bb0fc3.zip
Add support for users as an argument to evidence command (#61)
* Add user as an option for evidence command * Update usage and examples * Automatically format code * No clue why @discordjs/builders was missing * Update package.json * upgrade deps Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: IRONM00N <64110067+IRONM00N@users.noreply.github.com>
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 {