diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-09-06 15:20:46 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-09-06 15:20:46 -0400 |
commit | 13306f17accea5d3653dd4b8670ba0d6ab69c7c5 (patch) | |
tree | 7075dcca19ed1164a166efac19c49311e93ffeee /src/commands/moderation/evidence.ts | |
parent | a8386e756758f243b75e5df4886224d2bf9f241c (diff) | |
download | tanzanite-13306f17accea5d3653dd4b8670ba0d6ab69c7c5.tar.gz tanzanite-13306f17accea5d3653dd4b8670ba0d6ab69c7c5.tar.bz2 tanzanite-13306f17accea5d3653dd4b8670ba0d6ab69c7c5.zip |
evidence command and more logging
Diffstat (limited to 'src/commands/moderation/evidence.ts')
-rw-r--r-- | src/commands/moderation/evidence.ts | 92 |
1 files changed, 60 insertions, 32 deletions
diff --git a/src/commands/moderation/evidence.ts b/src/commands/moderation/evidence.ts index ae0a128..71a52b2 100644 --- a/src/commands/moderation/evidence.ts +++ b/src/commands/moderation/evidence.ts @@ -1,4 +1,5 @@ -import { BushCommand, BushMessage, BushSlashMessage } from '@lib'; +import { BushCommand, BushMessage, BushSlashMessage, ModLog } from '@lib'; +import { ArgumentOptions, Flag } from 'discord-akairo'; export default class EvidenceCommand extends BushCommand { public constructor() { @@ -7,54 +8,81 @@ export default class EvidenceCommand extends BushCommand { category: 'moderation', description: { content: 'Add evidence to a modlog case.', - usage: 'evidence <caseID> <evidence>', + usage: 'evidence <case_id> <evidence>', examples: ['evidence '] }, - args: [ - { - id: 'case', - type: 'string', - prompt: { - start: 'What would you like to set your first argument to be?', - retry: '{error} Pick a valid argument.', - optional: false - } - }, - { - id: 'evidence', - type: 'string', - prompt: { - start: 'What would you like to set your second argument to be?', - retry: '{error} Pick a valid argument.', - optional: true - } - } - ], slash: true, slashOptions: [ { - name: 'case', - description: 'What would you like to set your first argument to be?', + name: 'case_id', + description: 'What case would you like to modify the evidence of?', type: 'STRING', required: true }, { name: 'evidence', - description: 'What would you like to set your second argument to be?', + description: 'What would you like to modify the evidence to?', type: 'STRING', - required: false + required: true } ], - superUserOnly: true, - ownerOnly: true, channel: 'guild', - hidden: true, clientPermissions: ['SEND_MESSAGES'], - userPermissions: ['SEND_MESSAGES'] + userPermissions: ['SEND_MESSAGES', 'MANAGE_MESSAGES'] }); } - public override async exec(message: BushMessage | BushSlashMessage): Promise<unknown> { - return await message.util.reply(`${util.emojis.error} Soon:tm:.`); + *args(message: BushMessage): IterableIterator<ArgumentOptions | Flag> { + const case_id = yield { + id: 'case_id', + type: 'string', + prompt: { + start: 'What case would you like to modify the evidence of?', + retry: '{error} Pick a valid case to modify the evidence of.', + optional: false + } + }; + + const evidence = yield { + id: 'evidence', + type: 'string', + match: 'restContent', + prompt: { + start: 'What would you like to modify the evidence to?', + retry: '{error} Pick a valid argument.', + optional: !!message.attachments.some((attachment) => !!attachment.contentType?.includes('image')) + } + }; + + return { case_id, evidence }; + } + + public override async exec( + message: BushMessage | BushSlashMessage, + { case_id: caseID, evidence }: { case_id: string; evidence?: string } + ): Promise<unknown> { + const entry = await ModLog.findByPk(caseID); + 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.`); + + if (evidence && (message as BushMessage).attachments?.size) + return message.util.reply(`${util.emojis.error} Please either attach an image or a reason not both.`); + + const _evidence = evidence + ? evidence + : !message.util.isSlash + ? (message as BushMessage).attachments.first()?.url + : undefined; + if (!_evidence) return message.util.reply(`${util.emojis.error} You must provide evidence for this modlog.`); + + const oldEntry = entry.evidence; + + entry.evidence = _evidence.trim(); + await entry.save(); + + client.emit('bushUpdateModlog', message.member!, entry.id, 'evidence', oldEntry, entry.evidence); + + return message.util.reply(`${util.emojis.success} Successfully updated the evidence for case \`${caseID}\`.`); } } |