diff options
Diffstat (limited to 'src/commands/moderation')
-rw-r--r-- | src/commands/moderation/modlog.ts | 12 | ||||
-rw-r--r-- | src/commands/moderation/removeReactionEmoji.ts | 64 | ||||
-rw-r--r-- | src/commands/moderation/slowmode.ts | 87 |
3 files changed, 158 insertions, 5 deletions
diff --git a/src/commands/moderation/modlog.ts b/src/commands/moderation/modlog.ts index af5f563..4b57a4f 100644 --- a/src/commands/moderation/modlog.ts +++ b/src/commands/moderation/modlog.ts @@ -1,6 +1,6 @@ -import { BushCommand, BushMessage, BushSlashMessage, ModLog } from '@lib'; +import { BushCommand, BushMessage, BushSlashMessage, BushUser, ModLog } from '@lib'; import { Argument } from 'discord-akairo'; -import { MessageEmbed } from 'discord.js'; +import { MessageEmbed, User } from 'discord.js'; export default class ModlogCommand extends BushCommand { public constructor() { @@ -47,8 +47,8 @@ export default class ModlogCommand extends BushCommand { return modLog.join(`\n`); } - async exec(message: BushMessage | BushSlashMessage, { search }: { search: string }): Promise<unknown> { - const foundUser = await this.client.util.resolveUserAsync(search); + async exec(message: BushMessage | BushSlashMessage, { search }: { search: BushUser | string }): Promise<unknown> { + const foundUser = search instanceof User ? search : await this.client.util.resolveUserAsync(search); if (foundUser) { const logs = await ModLog.findAll({ where: { @@ -57,6 +57,8 @@ export default class ModlogCommand extends BushCommand { }, order: [['createdAt', 'ASC']] }); + if (!logs.length) + return message.util.reply(`${this.client.util.emojis.error} **${foundUser.tag}** does not have any modlogs.`); const niceLogs: string[] = []; for (const log of logs) { niceLogs.push(this.generateModlogInfo(log)); @@ -72,7 +74,7 @@ export default class ModlogCommand extends BushCommand { ); this.client.util.buttonPaginate(message, embedPages, '', true); } else if (search) { - const entry = await ModLog.findByPk(search); + const entry = await ModLog.findByPk(search as string); if (!entry) return message.util.send(`${this.client.util.emojis.error} That modlog does not exist.`); const embed = new MessageEmbed({ title: `Case ${entry.id}`, diff --git a/src/commands/moderation/removeReactionEmoji.ts b/src/commands/moderation/removeReactionEmoji.ts new file mode 100644 index 0000000..3d274e1 --- /dev/null +++ b/src/commands/moderation/removeReactionEmoji.ts @@ -0,0 +1,64 @@ +import { BushCommand, BushMessage } from '@lib'; +import { Argument } from 'discord-akairo'; +import { Emoji } from 'discord.js'; + +export default class RemoveReactionEmojiCommand extends BushCommand { + public constructor() { + super('removereactionemoji', { + aliases: ['removereactionemoji', 'rre'], + category: 'moderation', + description: { + content: 'Deleted all the reactions of a certain emoji from a message.', + usage: 'removereactionemoji <message> <emoji>', + examples: ['removereactionemoji 791413052347252786 <:omegaclown:782630946435366942>'] + }, + clientPermissions: ['MANAGE_MESSAGES', 'SEND_MESSAGES', 'EMBED_LINKS'], + userPermissions: ['MANAGE_MESSAGES', 'MANAGE_EMOJIS'], // Can't undo the removal of 1000s of reactions + args: [ + { + id: 'messageToRemoveFrom', + type: 'guildMessage', + prompt: { + start: 'What message would you like to remove a reaction from?', + retry: '{error} Please pick a valid message.' + } + }, + { + id: 'emoji', + type: Argument.union('emoji', 'bigint'), + match: 'restContent', + prompt: { + start: 'What emoji would you like to remove?', + retry: '{error} Please pick a valid emoji.' + } + } + ], + channel: 'guild' + }); + } + + public async exec( + message: BushMessage, + { messageToRemoveFrom, emoji }: { messageToRemoveFrom: BushMessage; emoji: Emoji | BigInt } + ): Promise<unknown> { + const id = !['bigint', 'string'].includes(typeof emoji); + const emojiID = !id ? `${emoji}` : (emoji as Emoji).id; + const success = await messageToRemoveFrom.reactions.cache + .get(emojiID) + .remove() + .catch(() => {}); + if (success) { + return await message.util.reply( + `${this.client.util.emojis.success} Removed all reactions of \`${ + id ? emojiID : emoji + }\` from the message with the id of \`${messageToRemoveFrom.id}\`.` + ); + } else { + return await message.util.reply( + `${this.client.util.emojis.error} There was an error removing all reactions of \`${ + id ? emojiID : emoji + }\` from the message with the id of \`${messageToRemoveFrom.id}\`.` + ); + } + } +} diff --git a/src/commands/moderation/slowmode.ts b/src/commands/moderation/slowmode.ts new file mode 100644 index 0000000..8384562 --- /dev/null +++ b/src/commands/moderation/slowmode.ts @@ -0,0 +1,87 @@ +import { BushCommand, BushMessage, BushSlashMessage } from '@lib'; +import { Argument, Constants } from 'discord-akairo'; +import { TextChannel, ThreadChannel } from 'discord.js'; + +export default class SlowModeCommand extends BushCommand { + public constructor() { + super('slowmode', { + aliases: ['slowmode', 'slow'], + category: 'moderation', + description: { + content: 'A command to set the slowmode of a channel.', + usage: 'slowmode <length>', + examples: ['slowmode 3'] + }, + args: [ + { + id: 'length', + type: Argument.union('duration', 'off', 'none', 'disable'), + default: 0, + prompt: { + start: 'What would you like to set the slowmode to?', + retry: '{error} Please set the slowmode to a valid length.', + optional: true + } + }, + { + id: 'channel', + type: Constants.ArgumentTypes.CHANNEL, + match: Constants.ArgumentMatches.PHRASE, + prompt: { + start: 'What channel would you like to change?', + retry: '{error} Choose a valid channel.', + optional: true + } + } + ], + slash: true, + slashOptions: [ + { + name: 'channel', + description: 'What channel would you like to change the slowmode of?', + type: 'CHANNEL', + required: false + } + ], + channel: 'guild', + clientPermissions: ['MANAGE_CHANNELS', 'SEND_MESSAGES', 'EMBED_LINKS'], + userPermissions: ['MANAGE_MESSAGES', 'SEND_MESSAGES'] + }); + } + + public async exec( + message: BushMessage | BushSlashMessage, + { length, channel }: { length: number | 'off' | 'none' | 'disable'; channel: TextChannel | ThreadChannel } + ): Promise<unknown> { + if (message.channel.type === 'DM') + return await message.util.reply(`${this.client.util.emojis.error} This command cannot be run in dms.`); + if (!channel) channel = message.channel as ThreadChannel | TextChannel; + if (!(channel instanceof TextChannel) || !(channel instanceof ThreadChannel)) + return await message.util.reply(`${this.client.util.emojis.error} <#${channel.id}> is not a text or thread channel.`); + if (length) { + length = + typeof length === 'string' && !['off', 'none', 'disable'].includes(length) + ? await Argument.cast('duration', this.client.commandHandler.resolver, message as BushMessage, length) + : length; + } + + // @ts-expect-error: stop being dumb smh + const length2: number = ['off', 'none', 'disable'].includes(length) ? 0 : length; + + const setSlowmode = await (channel as ThreadChannel | TextChannel) + .setRateLimitPerUser(length2 / 1000, `Changed by ${message.author.tag} (${message.author.id}).`) + .catch(() => {}); + if (!setSlowmode) + return await message.util.reply( + `${this.client.util.emojis.error} There was an error changing the slowmode of <#${ + (channel as ThreadChannel | TextChannel).id + }>.` + ); + else + return await message.util.reply( + `${this.client.util.emojis.success} Successfully changed the slowmode of ${channel} ${ + length2 ? `to \`${this.client.util.humanizeDuration(length2)}` : '`off' + }\`.` + ); + } +} |