diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-11-28 09:27:41 -0500 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-11-28 09:27:41 -0500 |
commit | 453683b57b8ff013ff25e2aaa4aa1d2e047edcb7 (patch) | |
tree | 8b98d2f30dbb6a8448602446cfacf9091667cc33 /src/commands/moderation | |
parent | de4c3dcaf172804d34ae708be1ed3e75af42f4d5 (diff) | |
download | tanzanite-453683b57b8ff013ff25e2aaa4aa1d2e047edcb7.tar.gz tanzanite-453683b57b8ff013ff25e2aaa4aa1d2e047edcb7.tar.bz2 tanzanite-453683b57b8ff013ff25e2aaa4aa1d2e047edcb7.zip |
a few small changes
Diffstat (limited to 'src/commands/moderation')
-rw-r--r-- | src/commands/moderation/_lockdown.ts | 23 | ||||
-rw-r--r-- | src/commands/moderation/activePunishments.ts | 76 | ||||
-rw-r--r-- | src/commands/moderation/ban.ts | 73 | ||||
-rw-r--r-- | src/commands/moderation/evidence.ts | 32 | ||||
-rw-r--r-- | src/commands/moderation/hideCase.ts | 24 | ||||
-rw-r--r-- | src/commands/moderation/kick.ts | 49 | ||||
-rw-r--r-- | src/commands/moderation/modlog.ts | 46 | ||||
-rw-r--r-- | src/commands/moderation/mute.ts | 49 | ||||
-rw-r--r-- | src/commands/moderation/purge.ts | 57 | ||||
-rw-r--r-- | src/commands/moderation/removeReactionEmoji.ts | 48 | ||||
-rw-r--r-- | src/commands/moderation/role.ts | 123 | ||||
-rw-r--r-- | src/commands/moderation/slowmode.ts | 44 | ||||
-rw-r--r-- | src/commands/moderation/unban.ts | 42 | ||||
-rw-r--r-- | src/commands/moderation/unmute.ts | 49 | ||||
-rw-r--r-- | src/commands/moderation/warn.ts | 49 |
15 files changed, 381 insertions, 403 deletions
diff --git a/src/commands/moderation/_lockdown.ts b/src/commands/moderation/_lockdown.ts index 029db29..08d4011 100644 --- a/src/commands/moderation/_lockdown.ts +++ b/src/commands/moderation/_lockdown.ts @@ -5,27 +5,21 @@ export default class LockdownCommand extends BushCommand { super('lockdown', { aliases: ['lockdown', 'unlockdown'], category: 'moderation', - description: { - content: 'Allows you to lockdown a channel or all configured channels..', - usage: ['lockdown [--all]'], - examples: ['lockdown', 'lockdown --all'] - }, + description: 'Allows you to lockdown a channel or all configured channels..', + usage: ['lockdown [--all]'], + examples: ['lockdown', 'lockdown --all'], args: [ { id: 'all', + description: 'Whether or not to lock all channels', match: 'flag', - flag: '--all' + flag: '--all', + prompt: 'Would you like to lockdown all channels?', + slashType: 'BOOLEAN', + optional: true } ], slash: true, - slashOptions: [ - { - name: 'all', - description: 'Would you like to lockdown all channels?', - type: 'BOOLEAN', - required: false - } - ], channel: 'guild', clientPermissions: (m) => util.clientSendAndPermCheck(m), userPermissions: [], @@ -34,6 +28,7 @@ export default class LockdownCommand extends BushCommand { } public override async exec(message: BushMessage | BushSlashMessage, args: { all: boolean }) { + // todo stop being lazy return await message.util.reply('Unfortunately my developer is too lazy to implement this command.'); if (!args.all) { if (!['GUILD_TEXT', 'GUILD_NEWS'].includes(message.channel!.type)) diff --git a/src/commands/moderation/activePunishments.ts b/src/commands/moderation/activePunishments.ts new file mode 100644 index 0000000..d40f2ba --- /dev/null +++ b/src/commands/moderation/activePunishments.ts @@ -0,0 +1,76 @@ +// import { BushCommand, ModLog, ModLogModel, type BushGuildMember, type BushMessage, type BushSlashMessage } from '#lib'; +// import { FindOptions, Op } from 'sequelize'; + +// const punishmentTypes = ['ban', 'kick', 'mute', 'warn', 'role'] as const; + +// export default class ActivePunishmentsCommand extends BushCommand { +// public constructor() { +// super('active-punishments', { +// aliases: ['active-punishments', 'ap'], +// category: 'moderation', +// description: 'Gets a list of all the active punishment in the server.', +// usage: [`active-punishments [--moderator <user>] [--type <${punishmentTypes.map((v) => `'${v}'`).join('|')}>]`], +// examples: ['active-punishments'], +// args: [ +// { +// id: 'moderator', +// description: 'Only show active punishments by this moderator.', +// type: 'user', +// match: 'option', +// prompt: 'Only show active punishments from what user?', +// optional: true, +// slashType: 'USER', +// slashResolve: 'member' +// }, +// { +// id: 'type', +// description: 'Only show active punishments of this type.', +// customType: [...punishmentTypes], +// readableType: punishmentTypes.map((v) => `'${v}'`).join('|'), +// match: 'option', +// optional: true, +// slashType: 'STRING', +// choices: punishmentTypes.map((v) => ({ name: v, value: v })) +// } +// ], +// slash: true, +// channel: 'guild', +// hidden: true, +// clientPermissions: (m) => util.clientSendAndPermCheck(m), +// userPermissions: (m) => util.userGuildPermCheck(m, ['MANAGE_MESSAGES']) +// }); +// } +// public override async exec( +// message: BushMessage | BushSlashMessage, +// args: { moderator?: BushGuildMember; type: typeof punishmentTypes[number] } +// ) { +// const where: FindOptions<ModLogModel>['where'] = { guild: message.guild!.id }; +// if (args.moderator?.id) where.user = args.moderator.id; +// if (args.type) { +// switch (args.type) { +// case 'ban': +// where.type = { [Op.or]: ['PERM_BAN', 'TEMP_BAN', 'UNBAN'] }; +// break; +// case 'kick': +// where.type = { [Op.or]: ['KICK'] }; +// break; +// case 'mute': +// where.type = { [Op.or]: ['PERM_MUTE', 'TEMP_MUTE', 'UNMUTE'] }; +// break; +// case 'warn': +// where.type = { [Op.or]: ['WARN'] }; +// break; +// case 'role': +// where.type = { [Op.or]: ['PERM_PUNISHMENT_ROLE', 'TEMP_PUNISHMENT_ROLE', 'REMOVE_PUNISHMENT_ROLE'] }; +// break; +// default: +// return message.util.reply(`${util.emojis.error} You supplied an invalid case type to filter by.`); +// } +// } + +// const logs = await ModLog.findAll({ +// where, +// order: [['createdAt', 'ASC']] +// }); +// } +// } diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts index 7c0d010..3d68a97 100644 --- a/src/commands/moderation/ban.ts +++ b/src/commands/moderation/ban.ts @@ -6,73 +6,52 @@ export default class BanCommand extends BushCommand { super('ban', { aliases: ['ban', 'force-ban', 'dban'], category: 'moderation', - description: { - content: 'Ban a member from the server.', - usage: ['ban <member> <reason> [--delete]'], - examples: ['ban ironm00n 1 day commands in #general --delete 7'] - }, + description: 'Ban a member from the server.', + usage: ['ban <member> <reason> [--delete]'], + examples: ['ban ironm00n 1 day commands in #general --delete 7'], args: [ { id: 'user', + description: 'The user that will be banned.', customType: util.arg.union('user', 'snowflake'), - prompt: { - start: 'What user would you like to ban?', - retry: '{error} Choose a valid user to ban.' - } + prompt: 'What user would you like to ban?', + retry: '{error} Choose a valid user to ban.', + slashType: 'USER' }, { id: 'reason', + description: 'The reason and duration of the ban.', type: 'contentWithDuration', match: 'restContent', - prompt: { - start: 'Why should this user be banned and for how long?', - retry: '{error} Choose a valid ban reason and duration.', - optional: true - } + prompt: 'Why should this user be banned and for how long?', + retry: '{error} Choose a valid ban reason and duration.', + slashType: 'STRING', + optional: true }, { id: 'days', + description: 'The number of days of messages to delete when the user is banned, defaults to 0.', flag: '--days', match: 'option', - customType: util.arg.range('integer', 0, 7, true) + prompt: "How many days of the user's messages would you like to delete?", + retry: '{error} Choose between 0 and 7 days to delete messages from the user for.', + customType: util.arg.range('integer', 0, 7, true), + optional: true, + slashType: 'INTEGER', + choices: [...Array(8).keys()].map((v) => ({ name: v.toString(), value: v })) }, { id: 'force', + description: 'Override permission checks.', flag: '--force', - match: 'flag' + match: 'flag', + optional: true, + slashType: false, + only: 'text', + ownerOnly: true } ], slash: true, - slashOptions: [ - { - name: 'user', - description: 'What user would you like to ban?', - type: 'USER', - required: true - }, - { - name: 'reason', - description: 'Why should this user be banned and for how long?', - type: 'STRING', - required: false - }, - { - name: 'days', - description: "How many days of the user's messages would you like to delete?", - type: 'INTEGER', - required: false, - choices: [ - { name: '0', value: 0 }, - { name: '1', value: 1 }, - { name: '2', value: 2 }, - { name: '3', value: 3 }, - { name: '4', value: 4 }, - { name: '5', value: 5 }, - { name: '6', value: 6 }, - { name: '7', value: 7 } - ] - } - ], channel: 'guild', clientPermissions: ['BAN_MEMBERS'], userPermissions: ['BAN_MEMBERS'] @@ -134,7 +113,7 @@ export default class BanCommand extends BushCommand { }); const responseMessage = () => { - const victim = util.format.bold(user.tag); + const victim = util.format.input(user.tag); switch (responseCode) { case 'missing permissions': return `${util.emojis.error} Could not ban ${victim} because I am missing the **Ban Members** permission.`; diff --git a/src/commands/moderation/evidence.ts b/src/commands/moderation/evidence.ts index 0204d84..714a2e5 100644 --- a/src/commands/moderation/evidence.ts +++ b/src/commands/moderation/evidence.ts @@ -6,26 +6,28 @@ export default class EvidenceCommand extends BushCommand { super('evidence', { aliases: ['evidence'], category: 'moderation', - description: { - content: 'Add evidence to a modlog case.', - usage: ['evidence <case_id> <evidence>'], - examples: ['evidence '] - }, - slash: true, - slashOptions: [ + description: 'Add evidence to a modlog case.', + usage: ['evidence <case_id> <evidence>'], + examples: ['evidence 9210b1ea-91f5-4ea2-801b-02b394469c77 was spamming in #general'], + args: [ { - name: 'case_id', - description: 'What case would you like to modify the evidence of?', - type: 'STRING', - required: true + id: 'case_id', + description: 'The case to modify the evidence of.', + type: 'string', + prompt: 'What case would you like to modify the evidence of?', + slashType: 'STRING', + only: 'slash' }, { - name: 'evidence', - description: 'What would you like to modify the evidence to?', - type: 'STRING', - required: true + id: 'evidence', + description: 'The value to set the evidence to.', + type: 'string', + prompt: 'What would you like to modify the evidence to?', + slashType: 'STRING', + only: 'slash' } ], + slash: true, channel: 'guild', clientPermissions: (m) => util.clientSendAndPermCheck(m), userPermissions: (m) => util.userGuildPermCheck(m, ['MANAGE_MESSAGES']) diff --git a/src/commands/moderation/hideCase.ts b/src/commands/moderation/hideCase.ts index 9c22e63..de7b310 100644 --- a/src/commands/moderation/hideCase.ts +++ b/src/commands/moderation/hideCase.ts @@ -5,30 +5,20 @@ export default class HideCaseCommand extends BushCommand { super('hideCase', { aliases: ['hide-case', 'hide_case', 'showcase', 'show_case', 'cover-up-mod-abuse', 'cover_up_mod_abuse'], category: 'moderation', - description: { - content: 'Hide a particular modlog case from the modlog command unless the `--hidden` flag is specified', - usage: ['hide-case <case_id>'], - examples: ['hide-case 9210b1ea-91f5-4ea2-801b-02b394469c77'] - }, + description: 'Hide a particular modlog case from the modlog command unless the `--hidden` flag is specified', + usage: ['hide-case <case_id>'], + examples: ['hide-case 9210b1ea-91f5-4ea2-801b-02b394469c77'], args: [ { id: 'case_id', + description: 'The id of the case to be hidden.', type: 'string', - prompt: { - start: 'What modlog case would you like to hide?', - retry: '{error} Choose a valid case id.' - } + prompt: 'What modlog case would you like to hide?', + retry: '{error} Choose a valid case id.', + slashType: 'STRING' } ], slash: true, - slashOptions: [ - { - name: 'case_id', - description: 'What modlog case would you like to hide?', - type: 'STRING', - required: true - } - ], clientPermissions: (m) => util.clientSendAndPermCheck(m), userPermissions: (m) => util.userGuildPermCheck(m, ['MANAGE_MESSAGES']), channel: 'guild' diff --git a/src/commands/moderation/kick.ts b/src/commands/moderation/kick.ts index 1f1c2fb..9463154 100644 --- a/src/commands/moderation/kick.ts +++ b/src/commands/moderation/kick.ts @@ -5,51 +5,40 @@ export default class KickCommand extends BushCommand { super('kick', { aliases: ['kick'], category: 'moderation', - description: { - content: 'Kick a user.', - usage: ['kick <member> <reason>'], - examples: ['kick @user bad'] - }, + description: 'Kick a user.', + usage: ['kick <member> <reason>'], + examples: ['kick @user bad'], args: [ { id: 'user', + description: 'The user to kick.', type: 'user', - prompt: { - start: 'What user would you like to kick?', - retry: '{error} Choose a valid user to kick.' - } + prompt: 'What user would you like to kick?', + retry: '{error} Choose a valid user to kick.', + slashType: 'USER' }, { id: 'reason', + description: 'The reason for the kick.', type: 'string', match: 'rest', - prompt: { - start: 'Why should this user be kicked?', - retry: '{error} Choose a valid kick reason.', - optional: true - } + prompt: 'Why should this user be kicked?', + retry: '{error} Choose a valid kick reason.', + optional: true, + slashType: 'STRING' }, { id: 'force', + description: 'Override permission checks.', flag: '--force', - match: 'flag' + match: 'flag', + optional: true, + slashType: false, + only: 'text', + ownerOnly: true } ], slash: true, - slashOptions: [ - { - name: 'user', - description: 'What user would you like to kick?', - type: 'USER', - required: true - }, - { - name: 'reason', - description: 'Why should this user be kicked?', - type: 'STRING', - required: false - } - ], clientPermissions: (m) => util.clientSendAndPermCheck(m, ['KICK_MEMBERS']), userPermissions: ['KICK_MEMBERS'] }); @@ -77,7 +66,7 @@ export default class KickCommand extends BushCommand { }); const responseMessage = () => { - const victim = util.format.bold(member.user.tag); + const victim = util.format.input(member.user.tag); switch (responseCode) { case 'missing permissions': return `${util.emojis.error} Could not kick ${victim} because I am missing the \`Kick Members\` permission.`; diff --git a/src/commands/moderation/modlog.ts b/src/commands/moderation/modlog.ts index 8bdee59..474eaa9 100644 --- a/src/commands/moderation/modlog.ts +++ b/src/commands/moderation/modlog.ts @@ -6,48 +6,36 @@ export default class ModlogCommand extends BushCommand { super('modlog', { aliases: ['modlog', 'modlogs'], category: 'moderation', - description: { - content: "View a user's modlogs, or view a specific case.", - usage: ['modlogs <search> [--hidden]'], - examples: ['modlogs @Tyman'] - }, + description: "View a user's modlogs, or view a specific case.", + usage: ['modlogs <search> [--hidden]'], + examples: ['modlogs @Tyman'], args: [ { id: 'search', + description: 'The case id or user to search for modlogs by.', customType: util.arg.union('user', 'string'), - prompt: { - start: 'What case id or user would you like to see?', - retry: '{error} Choose a valid case id or user.' - } + prompt: 'What case id or user would you like to see?', + retry: '{error} Choose a valid case id or user.', + slashType: 'STRING' }, { id: 'hidden', + description: 'Show hidden modlogs.', + prompt: 'Would you like to see hidden modlogs?', match: 'flag', flag: ['--hidden', '-h'], - default: false + default: false, + optional: true, + slashType: 'BOOLEAN' } ], - clientPermissions: (m) => util.clientSendAndPermCheck(m), - userPermissions: (m) => util.userGuildPermCheck(m, ['MANAGE_MESSAGES']), slash: true, - slashOptions: [ - { - name: 'search', - description: 'What case id or user would you like to see?', - type: 'STRING', - required: true - }, - { - name: 'hidden', - description: 'Would you like to see hidden modlogs?', - type: 'BOOLEAN', - required: false - } - ] + clientPermissions: (m) => util.clientSendAndPermCheck(m), + userPermissions: (m) => util.userGuildPermCheck(m, ['MANAGE_MESSAGES']) }); } - #generateModlogInfo(log: ModLog, showUser: boolean): string { + static generateModlogInfo(log: ModLog, showUser: boolean): string { const trim = (str: string): string => (str.endsWith('\n') ? str.substring(0, str.length - 1).trim() : str.trim()); const modLog = [`**Case ID**: ${util.discord.escapeMarkdown(log.id)}`, `**Type**: ${log.type.toLowerCase()}`]; if (showUser) modLog.push(`**User**: <@!${log.user}>`); @@ -75,7 +63,7 @@ export default class ModlogCommand extends BushCommand { const niceLogs = logs .filter((log) => !log.pseudo) .filter((log) => !(log.hidden && hidden)) - .map((log) => this.#generateModlogInfo(log, false)); + .map((log) => ModlogCommand.generateModlogInfo(log, false)); if (!logs.length || !niceLogs.length) return message.util.reply(`${util.emojis.error} **${foundUser.tag}** does not have any modlogs.`); const chunked: string[][] = util.chunk(niceLogs, 4); @@ -96,7 +84,7 @@ export default class ModlogCommand extends BushCommand { return message.util.reply(`${util.emojis.error} This modlog is from another server.`); const embed = { title: `Case ${entry.id}`, - description: this.#generateModlogInfo(entry, true), + description: ModlogCommand.generateModlogInfo(entry, true), color: util.colors.default }; return await ButtonPaginator.send(message, [embed]); diff --git a/src/commands/moderation/mute.ts b/src/commands/moderation/mute.ts index 44e1db4..0584d97 100644 --- a/src/commands/moderation/mute.ts +++ b/src/commands/moderation/mute.ts @@ -5,51 +5,40 @@ export default class MuteCommand extends BushCommand { super('mute', { aliases: ['mute'], category: 'moderation', - description: { - content: 'Mute a user.', - usage: ['mute <member> [reason] [duration]'], - examples: ['mute ironm00n 1 day commands in #general'] - }, + description: 'Mute a user.', + usage: ['mute <member> [reason] [duration]'], + examples: ['mute ironm00n 1 day commands in #general'], args: [ { id: 'user', + description: 'The user to mute.', type: 'user', - prompt: { - start: 'What user would you like to mute?', - retry: '{error} Choose a valid user to mute.' - } + prompt: 'What user would you like to mute?', + retry: '{error} Choose a valid user to mute.', + slashType: 'USER' }, { id: 'reason', + description: 'The reason for the mute.', type: 'contentWithDuration', match: 'rest', - prompt: { - start: 'Why should this user be muted and for how long?', - retry: '{error} Choose a valid mute reason and duration.', - optional: true - } + prompt: 'Why should this user be muted and for how long?', + retry: '{error} Choose a valid mute reason and duration.', + optional: true, + slashType:'STRING' }, { id: 'force', + description: 'Override permission checks.', flag: '--force', - match: 'flag' + match: 'flag', + optional: true, + slashType: false, + only: 'text', + ownerOnly: true } ], slash: true, - slashOptions: [ - { - name: 'user', - description: 'What user would you like to mute?', - type: 'USER', - required: true - }, - { - name: 'reason', - description: 'Why should this user be muted and for how long?', - type: 'STRING', - required: false - } - ], channel: 'guild', clientPermissions: (m) => util.clientSendAndPermCheck(m, ['MANAGE_ROLES']), userPermissions: (m) => util.userGuildPermCheck(m, ['MANAGE_MESSAGES']) @@ -95,7 +84,7 @@ export default class MuteCommand extends BushCommand { const responseMessage = () => { const prefix = util.prefix(message); - const victim = util.format.bold(member.user.tag); + const victim = util.format.input(member.user.tag); switch (responseCode) { case 'missing permissions': return `${util.emojis.error} Could not mute ${victim} because I am missing the **Manage Roles** permission.`; diff --git a/src/commands/moderation/purge.ts b/src/commands/moderation/purge.ts index 4d8db08..6bc62de 100644 --- a/src/commands/moderation/purge.ts +++ b/src/commands/moderation/purge.ts @@ -1,4 +1,4 @@ -import { BushCommand, BushMessage } from '#lib'; +import { BushCommand, BushMessage, BushUser } from '#lib'; import { Collection, type Snowflake } from 'discord.js'; export default class PurgeCommand extends BushCommand { @@ -6,61 +6,56 @@ export default class PurgeCommand extends BushCommand { super('purge', { aliases: ['purge'], category: 'moderation', - description: { - content: 'A command to mass delete messages.', - usage: ['purge <amount>'], - examples: ['purge 20'] - }, + description: 'A command to mass delete messages.', + usage: ['purge <amount> [--bot] [--user <user>]'], + examples: ['purge 20'], args: [ { id: 'amount', + description: 'The amount of messages to purge.', customType: util.arg.range('integer', 1, 100, true), - prompt: { - start: 'How many messages would you like to purge?', - retry: '{error} Please pick a number between 1 and 100.' - } + readableType: 'integer', + prompt: 'How many messages would you like to purge?', + retry: '{error} Please pick a number between 1 and 100.', + slashType: 'INTEGER', + minValue: 1, + maxValue: 100 }, { id: 'bot', + description: 'Filter messages to only include those that are from bots.', match: 'flag', - flag: '--bot' + flag: '--bot', + prompt: 'Would you like to only delete messages that are from bots?', + slashType: 'BOOLEAN', + optional: true }, { id: 'user', + description: 'Filter messages to only include those that are from a specified user.', match: 'option', - flag: '--user' + type: 'user', + flag: '--user', + slashType: 'BOOLEAN', + optional: true } ], slash: true, - slashOptions: [ - { - name: 'amount', - description: 'How many messages would you like to purge?', - type: 'INTEGER', - required: true - }, - { - name: 'bot', - description: 'Would you like to only delete messages that are from bots?', - type: 'BOOLEAN', - required: false - } - ], clientPermissions: (m) => util.clientSendAndPermCheck(m, ['MANAGE_MESSAGES', 'EMBED_LINKS'], true), userPermissions: ['MANAGE_MESSAGES'], channel: 'guild' }); } - public override async exec(message: BushMessage, args: { amount: number; bot: boolean }) { + public override async exec(message: BushMessage, args: { amount: number; bot: boolean, user: BushUser }) { if (message.channel.type === 'DM') return message.util.reply(`${util.emojis.error} You cannot run this command in dms.`); if (args.amount > 100 || args.amount < 1) return message.util.reply(`${util.emojis.error} `); const messageFilter = (filterMessage: BushMessage): boolean => { - const shouldFilter = new Array<boolean>(); - if (args.bot) { - shouldFilter.push(filterMessage.author.bot); - } + const shouldFilter: boolean[] = []; + if (args.bot) shouldFilter.push(filterMessage.author.bot); + if (args.user) shouldFilter.push(filterMessage.author.id === args.user.id); + return shouldFilter.filter((bool) => bool === false).length === 0 && filterMessage.id !== message.id; }; const _messages = (await message.channel.messages.fetch({ limit: 100, before: message.id })) diff --git a/src/commands/moderation/removeReactionEmoji.ts b/src/commands/moderation/removeReactionEmoji.ts index 80f2c01..e847aba 100644 --- a/src/commands/moderation/removeReactionEmoji.ts +++ b/src/commands/moderation/removeReactionEmoji.ts @@ -1,35 +1,35 @@ import { BushCommand, type BushMessage } from '#lib'; -import { type Emoji, type Snowflake } from 'discord.js'; +import { Message, type Emoji, type Snowflake } from 'discord.js'; export default class RemoveReactionEmojiCommand extends BushCommand { public constructor() { super('removeReactionEmoji', { aliases: ['remove-reaction-emoji', 'rre'], category: 'moderation', - description: { - content: 'Deleted all the reactions of a certain emoji from a message.', - usage: ['remove-reaction-emoji <message> <emoji>'], - examples: ['remove-reaction-emoji 791413052347252786 <:omegaclown:782630946435366942>'] - }, + description: 'Delete all the reactions of a certain emoji from a message.', + usage: ['remove-reaction-emoji <message> <emoji>'], + examples: ['remove-reaction-emoji 791413052347252786 <:omegaclown:782630946435366942>'], args: [ { - id: 'messageToRemoveFrom', + id: 'message', + description: 'The message to remove all the reactions of a certain emoji from.', type: 'guildMessage', - prompt: { - start: 'What message would you like to remove a reaction from?', - retry: '{error} Please pick a valid message.' - } + prompt: 'What message would you like to remove a reaction from?', + retry: '{error} Please pick a valid message.', + slashType: 'STRING' }, { id: 'emoji', + description: 'The emoji to remove all the reactions of from a message.', customType: util.arg.union('emoji', 'snowflake'), + readableType:'emoji|snowflake', match: 'restContent', - prompt: { - start: 'What emoji would you like to remove?', - retry: '{error} Please pick a valid emoji.' - } + prompt: 'What emoji would you like to remove?', + retry: '{error} Please pick a valid emoji.', + slashType: 'STRING' } ], + slash: true, channel: 'guild', clientPermissions: (m) => util.clientSendAndPermCheck(m, ['MANAGE_MESSAGES', 'EMBED_LINKS'], true), userPermissions: ['MANAGE_MESSAGES', 'MANAGE_EMOJIS_AND_STICKERS'] // Can't undo the removal of 1000s of reactions @@ -38,25 +38,27 @@ export default class RemoveReactionEmojiCommand extends BushCommand { public override async exec( message: BushMessage, - { messageToRemoveFrom, emoji }: { messageToRemoveFrom: BushMessage; emoji: Emoji | Snowflake } + args: { message: BushMessage|Snowflake; emoji: Emoji | Snowflake } ) { - const id = !['string'].includes(typeof emoji); - const emojiID = !id ? `${emoji}` : (emoji as Emoji).id; - const success = await messageToRemoveFrom.reactions.cache + const resolvedMessage = args.message instanceof Message ? args.message : await message.channel.messages.fetch(args.message ) + + const id = !(['string'] as const).includes(typeof args.emoji); + const emojiID = !id ? `${args.emoji}` : (args.emoji as Emoji).id; + const success = await resolvedMessage.reactions.cache ?.get(emojiID!) ?.remove() ?.catch(() => {}); if (success) { return await message.util.reply( - `${util.emojis.success} Removed all reactions of \`${id ? emojiID : emoji}\` from the message with the id of \`${ - messageToRemoveFrom.id + `${util.emojis.success} Removed all reactions of \`${id ? emojiID : args.emoji}\` from the message with the id of \`${ + resolvedMessage.id }\`.` ); } else { return await message.util.reply( `${util.emojis.error} There was an error removing all reactions of \`${ - id ? emojiID : emoji - }\` from the message with the id of \`${messageToRemoveFrom.id}\`.` + id ? emojiID : args.emoji + }\` from the message with the id of \`${resolvedMessage.id}\`.` ); } } diff --git a/src/commands/moderation/role.ts b/src/commands/moderation/role.ts index dd74bb4..7ca0a5d 100644 --- a/src/commands/moderation/role.ts +++ b/src/commands/moderation/role.ts @@ -1,47 +1,54 @@ import { AllowedMentions, BushCommand, type BushGuildMember, type BushMessage, type BushRole, type BushSlashMessage } from '#lib'; import { type ArgumentOptions, type Flag } from 'discord-akairo'; +import { Snowflake } from 'discord.js'; export default class RoleCommand extends BushCommand { public constructor() { super('role', { aliases: ['role', 'rr', 'ar', 'ra'], category: 'moderation', - description: { - content: "Manages users' roles.", - usage: ['role <add|remove> <user> <role> [duration]'], - examples: ['role add spammer nogiveaways 7days', 'ra tyman muted', 'rr tyman staff'] - }, - slash: true, - slashOptions: [ + description: "Manages users' roles.", + usage: ['role <add|remove> <member> <role> [duration]'], + examples: ['role add spammer nogiveaways 7days', 'ra tyman muted', 'rr tyman staff'], + args: [ { - name: 'action', - description: 'Would you like to add or remove a role?', - type: 'STRING', + id: 'action', + description: 'Whether to add or remove a role for the the user.', + prompt: 'Would you like to add or remove a role?', + slashType: 'STRING', choices: [ { name: 'add', value: 'add' }, { name: 'remove', value: 'remove' } ], - required: true + only: 'slash' }, { - name: 'user', - description: 'What user do you want to add/remove the role to/from?', - type: 'USER', - required: true + id: 'member', + description: 'The user to add/remove a role to/from.', + prompt: 'What user do you want to add/remove a role to/from?', + slashType: 'USER', + slashResolve: 'member', + optional: true, + only: 'slash' }, { - name: 'role', + id: 'role', description: 'The role you would like to add/remove from the to/from.', - type: 'ROLE', - required: true + prompt: 'What role would you like to add/remove from the user?', + slashType: 'ROLE', + optional: true, + only: 'slash' }, { - name: 'duration', - description: 'How long would you like to role to last?', - type: 'STRING', - required: false + id: 'duration', + description: 'The time before the role will be removed (ignored if removing a role).', + prompt: 'How long would you like to role to last?', + slashType: 'STRING', + optional: true, + only: 'slash' } ], + slash: true, channel: 'guild', typing: true, clientPermissions: (m) => util.clientSendAndPermCheck(m, ['MANAGE_ROLES', 'EMBED_LINKS'], true), @@ -49,10 +56,10 @@ export default class RoleCommand extends BushCommand { }); } - override *args(message: BushMessage): IterableIterator<ArgumentOptions | Flag> { - const action = ['rr'].includes(message.util.parsed?.alias ?? '') + override *args(message: BushMessage): Generator<ArgumentOptions | Flag> { + const action = (['rr'] as const).includes(message.util.parsed?.alias ?? '') ? 'remove' - : ['ar', 'ra'].includes(message.util.parsed?.alias ?? '') + : (['ar', 'ra'] as const).includes(message.util.parsed?.alias ?? '') ? 'add' : yield { id: 'action', @@ -63,7 +70,7 @@ export default class RoleCommand extends BushCommand { } }; - const user = yield { + const member = yield { id: 'user', type: 'member', prompt: { @@ -84,19 +91,21 @@ export default class RoleCommand extends BushCommand { } }; - return { action, user, role: (_role as any).role ?? _role, duration: (_role as any).duration }; + const force = yield { + id: 'force', + description: 'Override permission checks and ban the user anyway.', + flag: '--force', + match: 'flag' + }; + + return { action, member: member, role: (_role as any).role ?? _role, duration: (_role as any).duration, force }; } public override async exec( message: BushMessage | BushSlashMessage, - { - action, - user: member, - role, - duration - }: { action: 'add' | 'remove'; user: BushGuildMember; role: BushRole; duration?: number | null } + args: { action: 'add' | 'remove'; member: BushGuildMember; role: BushRole; duration?: number | null; force?: boolean } ) { - if (duration === null) duration = 0; + if (args.duration === null) args.duration = 0; if ( !message.member!.permissions.has('MANAGE_ROLES') && message.member!.id !== message.guild?.ownerId && @@ -106,11 +115,11 @@ export default class RoleCommand extends BushCommand { let mappedRole: { name: string; id: string }; for (let i = 0; i < mappings.roleMap.length; i++) { const a = mappings.roleMap[i]; - if (a.id == role.id) mappedRole = a; + if (a.id === args.role.id) mappedRole = a; } if (!mappedRole! || !Reflect.has(mappings.roleWhitelist, mappedRole.name)) { return await message.util.reply({ - content: `${util.emojis.error} <@&${role.id}> is not whitelisted, and you do not have manage roles permission.`, + content: `${util.emojis.error} <@&${args.role.id}> is not whitelisted, and you do not have manage roles permission.`, allowedMentions: AllowedMentions.none() }); } @@ -120,44 +129,54 @@ export default class RoleCommand extends BushCommand { } return; }); - if (!message.member!.roles.cache.some((role) => allowedRoles.includes(role.id))) { + if (!message.member!.roles.cache.some((role) => (allowedRoles as Snowflake[]).includes(role.id))) { return await message.util.reply({ - content: `${util.emojis.error} <@&${role.id}> is whitelisted, but you do not have any of the roles required to manage it.`, + content: `${util.emojis.error} <@&${args.role.id}> is whitelisted, but you do not have any of the roles required to manage it.`, allowedMentions: AllowedMentions.none() }); } } - const shouldLog = this.punishmentRoleNames.includes(role.name); + const shouldLog = this.punishmentRoleNames.includes(args.role.name); const responseCode = - action === 'add' - ? await member.addRole({ moderator: message.member!, addToModlog: shouldLog, role, duration }) - : await member.removeRole({ moderator: message.member!, addToModlog: shouldLog, role, duration }); + args.action === 'add' + ? await args.member.addRole({ + moderator: message.member!, + addToModlog: shouldLog, + role: args.role, + duration: args.duration + }) + : await args.member.removeRole({ + moderator: message.member!, + addToModlog: shouldLog, + role: args.role, + duration: args.duration + }); const responseMessage = () => { - const victim = util.format.bold(member.user.tag); + const victim = util.format.input(args.member.user.tag); switch (responseCode) { case 'user hierarchy': - return `${util.emojis.error} <@&${role.id}> is higher or equal to your highest role.`; + return `${util.emojis.error} <@&${args.role.id}> is higher or equal to your highest role.`; case 'role managed': - return `${util.emojis.error} <@&${role.id}> is managed by an integration and cannot be managed.`; + return `${util.emojis.error} <@&${args.role.id}> is managed by an integration and cannot be managed.`; case 'client hierarchy': - return `${util.emojis.error} <@&${role.id}> is higher or equal to my highest role.`; + return `${util.emojis.error} <@&${args.role.id}> is higher or equal to my highest role.`; case 'error creating modlog entry': return `${util.emojis.error} There was an error creating a modlog entry, please report this to my developers.`; case 'error creating role entry' || 'error removing role entry': return `${util.emojis.error} There was an error ${ - action === 'add' ? 'creating' : 'removing' + args.action === 'add' ? 'creating' : 'removing' } a punishment entry, please report this to my developers.`; case 'error adding role' || 'error removing role': - return `${util.emojis.error} An error occurred while trying to ${action} <@&${role.id}> ${ - action === 'add' ? 'to' : 'from' + return `${util.emojis.error} An error occurred while trying to ${args.action} <@&${args.role.id}> ${ + args.action === 'add' ? 'to' : 'from' } ${victim}.`; case 'success': - return `${util.emojis.success} Successfully ${action === 'add' ? 'added' : 'removed'} <@&${role.id}> ${ - action === 'add' ? 'to' : 'from' - } ${victim}${duration ? ` for ${util.humanizeDuration(duration)}` : ''}.`; + return `${util.emojis.success} Successfully ${args.action === 'add' ? 'added' : 'removed'} <@&${args.role.id}> ${ + args.action === 'add' ? 'to' : 'from' + } ${victim}${args.duration ? ` for ${util.humanizeDuration(args.duration)}` : ''}.`; } }; diff --git a/src/commands/moderation/slowmode.ts b/src/commands/moderation/slowmode.ts index e05a409..949038c 100644 --- a/src/commands/moderation/slowmode.ts +++ b/src/commands/moderation/slowmode.ts @@ -14,40 +14,32 @@ export default class SlowModeCommand extends BushCommand { super('slowmode', { aliases: ['slowmode', 'slow'], category: 'moderation', - description: { - content: 'A command to set the slowmode of a channel.', - usage: ['slowmode <length>'], - examples: ['slowmode 3'] - }, + description: 'A command to set the slowmode of a channel.', + usage: ['slowmode <length> [channel]'], + examples: ['slowmode 3'], args: [ { id: 'length', + description: 'The amount of time to set the slowmode of a channel to.', customType: Argument.union('duration', 'durationSeconds', 'off', 'none', 'disable'), - prompt: { - start: 'What would you like to set the slowmode to?', - retry: '{error} Please set the slowmode to a valid length.', - optional: true - } + readableType: "duration|durationSeconds|'off'|'none'|'disable'", + prompt: 'What would you like to set the slowmode to?', + retry: '{error} Please set the slowmode to a valid length.', + optional: true, + slashType: 'INTEGER' }, { id: 'channel', + description: 'The channel to change the slowmode of, defaults to the current channel.', type: 'channel', - prompt: { - start: 'What channel would you like to change?', - retry: '{error} Choose a valid channel.', - optional: true - } + prompt: 'What channel would you like to change?', + retry: '{error} Choose a valid channel.', + optional: true, + slashType: 'CHANNEL', + channelTypes: ['GUILD_TEXT', 'GUILD_PRIVATE_THREAD', 'GUILD_PUBLIC_THREAD'] } ], slash: true, - slashOptions: [ - { - name: 'channel', - description: 'What channel would you like to change the slowmode of?', - type: 'CHANNEL', - required: false - } - ], channel: 'guild', clientPermissions: (m) => util.clientSendAndPermCheck(m, ['MANAGE_CHANNELS', 'EMBED_LINKS'], true), userPermissions: (m) => util.userGuildPermCheck(m, ['MANAGE_MESSAGES']) @@ -67,16 +59,16 @@ export default class SlowModeCommand extends BushCommand { if (message.channel!.type === 'DM') return await message.util.reply(`${util.emojis.error} This command cannot be run in dms.`); if (!channel) channel = message.channel as any; - if (!(channel instanceof TextChannel) && !(channel instanceof ThreadChannel)) + if (!(['GUILD_TEXT', 'GUILD_PRIVATE_THREAD', 'GUILD_PUBLIC_THREAD'] as const).includes(channel.type)) return await message.util.reply(`${util.emojis.error} <#${channel.id}> is not a text or thread channel.`); if (length) { length = - typeof length === 'string' && !['off', 'none', 'disable'].includes(length) + typeof length === 'string' && !(['off', 'none', 'disable'] as const).includes(length) ? await util.arg.cast('duration', message, length) : length; } - const length2: number = ['off', 'none', 'disable'].includes(length as string) ? 0 : (length as number); + const length2: number = (['off', 'none', 'disable'] as const).includes(length as string) ? 0 : (length as number); const setSlowmode = await (channel as ThreadChannel | TextChannel) .setRateLimitPerUser(length2 / 1000, `Changed by ${message.author.tag} (${message.author.id}).`) diff --git a/src/commands/moderation/unban.ts b/src/commands/moderation/unban.ts index 1492b63..8444801 100644 --- a/src/commands/moderation/unban.ts +++ b/src/commands/moderation/unban.ts @@ -5,46 +5,30 @@ export default class UnbanCommand extends BushCommand { super('unban', { aliases: ['unban'], category: 'moderation', - description: { - content: 'Unban a member from the server.', - usage: ['unban <member> <reason> [--delete]'], - examples: ['unban 322862723090219008 I changed my mind, commands are allowed in #general'] - }, + description: 'Unban a member from the server.', + usage: ['unban <member> <reason>'], + examples: ['unban 322862723090219008 I changed my mind, commands are allowed in #general'], args: [ { id: 'user', + description: 'The user to unban.', type: 'globalUser', - prompt: { - start: 'What user would you like to unban?', - retry: '{error} Choose a valid user to unban.' - } + prompt: 'What user would you like to unban?', + retry: '{error} Choose a valid user to unban.', + slashType: 'USER' }, { id: 'reason', + description: 'The reason for the unban', type: 'string', match: 'restContent', - prompt: { - start: 'Why should this user be unbanned?', - retry: '{error} Choose a valid unban reason.', - optional: true - } + prompt: 'Why should this user be unbanned?', + retry: '{error} Choose a valid unban reason.', + optional: true, + slashType: 'STRING' } ], slash: true, - slashOptions: [ - { - name: 'user', - description: 'What user would you like to unban?', - type: 'USER', - required: true - }, - { - name: 'reason', - description: 'Why should this user be unbanned?', - type: 'STRING', - required: false - } - ], channel: 'guild', clientPermissions: ['BAN_MEMBERS'], userPermissions: ['BAN_MEMBERS'] @@ -58,7 +42,7 @@ export default class UnbanCommand extends BushCommand { }); const responseMessage = () => { - const victim = util.format.bold(user.tag); + const victim = util.format.input(user.tag); switch (responseCode) { case 'missing permissions': return `${util.emojis.error} Could not unban ${victim} because I am missing the **Ban Members** permission.`; diff --git a/src/commands/moderation/unmute.ts b/src/commands/moderation/unmute.ts index c31ce21..0c59b1f 100644 --- a/src/commands/moderation/unmute.ts +++ b/src/commands/moderation/unmute.ts @@ -13,51 +13,40 @@ export default class UnmuteCommand extends BushCommand { super('unmute', { aliases: ['unmute'], category: 'moderation', - description: { - content: 'unmute a user.', - usage: ['unmute <member> [reason]'], - examples: ['unmute 322862723090219008 1 day commands in #general'] - }, + description: 'unmute a user.', + usage: ['unmute <member> [reason]'], + examples: ['unmute 322862723090219008 1 day commands in #general'], args: [ { id: 'user', + description: 'The user to unmute.', type: 'user', - prompt: { - start: 'What user would you like to unmute?', - retry: '{error} Choose a valid user to unmute.' - } + prompt: 'What user would you like to unmute?', + retry: '{error} Choose a valid user to unmute.', + slashType: 'USER' }, { id: 'reason', + description: 'The reason for the unmute.', type: 'string', match: 'rest', - prompt: { - start: 'Why should this user be unmuted?', - retry: '{error} Choose a valid unmute reason.', - optional: true - } + prompt: 'Why should this user be unmuted?', + retry: '{error} Choose a valid unmute reason.', + optional: true, + slashType: 'STRING' }, { id: 'force', + description: 'Override permission checks.', flag: '--force', - match: 'flag' + match: 'flag', + optional: true, + slashType: false, + only: 'text', + ownerOnly: true } ], slash: true, - slashOptions: [ - { - name: 'user', - description: 'What user would you like to unmute?', - type: 'USER', - required: true - }, - { - name: 'reason', - description: 'Why should this user be unmuted?', - type: 'STRING', - required: false - } - ], channel: 'guild', clientPermissions: (m) => util.clientSendAndPermCheck(m, ['MANAGE_ROLES']), userPermissions: (m) => util.userGuildPermCheck(m, ['MANAGE_MESSAGES']) @@ -87,7 +76,7 @@ export default class UnmuteCommand extends BushCommand { const responseMessage = () => { const prefix = util.prefix(message); - const victim = util.format.bold(member.user.tag); + const victim = util.format.input(member.user.tag); switch (responseCode) { case 'missing permissions': return `${error} Could not unmute ${victim} because I am missing the **Manage Roles** permission.`; diff --git a/src/commands/moderation/warn.ts b/src/commands/moderation/warn.ts index 9b58cf6..2212548 100644 --- a/src/commands/moderation/warn.ts +++ b/src/commands/moderation/warn.ts @@ -13,50 +13,39 @@ export default class WarnCommand extends BushCommand { super('warn', { aliases: ['warn'], category: 'moderation', - description: { - content: 'Warn a user.', - usage: ['warn <member> [reason]'], - examples: ['warn @Tyman being cool'] - }, + description: 'Warn a user.', + usage: ['warn <member> [reason]'], + examples: ['warn @Tyman being cool'], args: [ { id: 'user', + description: 'The user to warn.', type: 'user', - prompt: { - start: 'What user would you like to warn?', - retry: '{error} Choose a valid user to warn.' - } + prompt: 'What user would you like to warn?', + retry: '{error} Choose a valid user to warn.', + slashType: 'USER' }, { id: 'reason', + description: 'The reason for the warn.', match: 'rest', - prompt: { - start: 'Why should this user be warned?', - retry: '{error} Choose a valid warn reason.', - optional: true - } + prompt: 'Why should this user be warned?', + retry: '{error} Choose a valid warn reason.', + slashType: 'STRING', + optional: true }, { id: 'force', + description: 'Override permission checks.', flag: '--force', - match: 'flag' + match: 'flag', + optional: true, + slashType: false, + only: 'text', + ownerOnly: true } ], slash: true, - slashOptions: [ - { - name: 'user', - description: 'What user would you like to warn?', - type: 'USER', - required: true - }, - { - name: 'reason', - description: 'Why should this user be warned?', - type: 'STRING', - required: false - } - ], channel: 'guild', clientPermissions: (m) => util.clientSendAndPermCheck(m), userPermissions: (m) => util.userGuildPermCheck(m, ['MANAGE_MESSAGES']) @@ -83,7 +72,7 @@ export default class WarnCommand extends BushCommand { }); const responseMessage = () => { - const victim = util.format.bold(member.user.tag); + const victim = util.format.input(member.user.tag); switch (response) { case 'error creating modlog entry': return `${util.emojis.error} While warning ${victim}, there was an error creating a modlog entry, please report this to my developers.`; |