diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-06-14 12:47:57 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-06-14 12:47:57 -0400 |
commit | 661e4c9935aeb8760dafc7ced4bbec6cc356a033 (patch) | |
tree | bb4c12bdef067d203f100e13e05ccb705b299834 /src/commands/moderation | |
parent | eaf592b72eb5b1d66aa2bde5151a8947570a506c (diff) | |
download | tanzanite-661e4c9935aeb8760dafc7ced4bbec6cc356a033.tar.gz tanzanite-661e4c9935aeb8760dafc7ced4bbec6cc356a033.tar.bz2 tanzanite-661e4c9935aeb8760dafc7ced4bbec6cc356a033.zip |
remove the war crimes that I previously committed
- Remove custom typings and replace with declaration merging
- Fix the typings for args
- Replace all discord-api-types imports with discord.js imports
- Fix discord.js breaking changes
Diffstat (limited to 'src/commands/moderation')
22 files changed, 207 insertions, 202 deletions
diff --git a/src/commands/moderation/_activePunishments.ts b/src/commands/moderation/_activePunishments.ts index e751493..92b4242 100644 --- a/src/commands/moderation/_activePunishments.ts +++ b/src/commands/moderation/_activePunishments.ts @@ -1,79 +1,78 @@ -/* import { BushCommand, ModLog, ModLogModel, type BushGuildMember, type BushMessage, type BushSlashMessage } from '#lib'; -import { FindOptions, Op } from 'sequelize'; -import { Permissions } from 'discord.js'; +// import { BushCommand, ModLog, ModLogModel, OptArgType, type CommandMessage, type SlashMessage } from '#lib'; +// import { ApplicationCommandOptionType, PermissionFlagsBits } from 'discord.js'; +// import { FindOptions, Op } from 'sequelize'; -const punishmentTypes = ['ban', 'kick', 'mute', 'warn', 'role'] as const; +// const punishmentTypes = ['ban', 'kick', 'mute', 'warn', 'role'] as const; -export default class ActivePunishmentsCommand extends BushCommand { - public constructor() { - super('activePunishments', { - 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: ApplicationCommandOptionType.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: ApplicationCommandOptionType.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, [PermissionFlagsBits.ManageMessages]) - }); - } +// export default class ActivePunishmentsCommand extends BushCommand { +// public constructor() { +// super('activePunishments', { +// 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: ApplicationCommandOptionType.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: ApplicationCommandOptionType.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, [PermissionFlagsBits.ManageMessages]) +// }); +// } - 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.`); - } - } +// public override async exec( +// message: CommandMessage | SlashMessage, +// args: { moderator: OptArgType<'user' | 'member'>; 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']] - }); - } -} - */ +// const logs = await ModLog.findAll({ +// where, +// order: [['createdAt', 'ASC']] +// }); +// } +// } diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts index 77951c3..f4bd52b 100644 --- a/src/commands/moderation/ban.ts +++ b/src/commands/moderation/ban.ts @@ -4,9 +4,9 @@ import { BushCommand, Moderation, type ArgType, - type BushMessage, - type BushSlashMessage, - type OptArgType + type CommandMessage, + type OptArgType, + type SlashMessage } from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, PermissionFlagsBits } from 'discord.js'; @@ -71,12 +71,12 @@ export default class BanCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, args: { - user: ArgType<'user'> | ArgType<'snowflake'>; + user: ArgType<'user' | 'snowflake'>; reason_and_duration: OptArgType<'contentWithDuration'> | string; days: OptArgType<'integer'>; - force: boolean; + force: ArgType<'flag'>; } ) { assert(message.inGuild()); diff --git a/src/commands/moderation/block.ts b/src/commands/moderation/block.ts index 722f08b..16beb6f 100644 --- a/src/commands/moderation/block.ts +++ b/src/commands/moderation/block.ts @@ -4,9 +4,9 @@ import { BushCommand, Moderation, type ArgType, - type BushMessage, - type BushSlashMessage, - type OptArgType + type CommandMessage, + type OptArgType, + type SlashMessage } from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, PermissionFlagsBits } from 'discord.js'; @@ -58,15 +58,16 @@ export default class BlockCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, args: { user: ArgType<'user'>; reason_and_duration: OptArgType<'contentWithDuration'> | string; - force?: ArgType<'boolean'>; + force: ArgType<'flag'>; } ) { assert(message.inGuild()); assert(message.member); + assert(message.channel); if (!message.channel.isTextBased()) return message.util.send(`${util.emojis.error} This command can only be used in text based channels.`); diff --git a/src/commands/moderation/evidence.ts b/src/commands/moderation/evidence.ts index 9b63189..f1fac0d 100644 --- a/src/commands/moderation/evidence.ts +++ b/src/commands/moderation/evidence.ts @@ -1,8 +1,7 @@ -import { BushCommand, ModLog, OptArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, ModLog, OptArgType, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; -import { ArgumentGeneratorReturn } from 'discord-akairo'; -import { Argument, ArgumentTypeCasterReturn } from 'discord-akairo/dist/src/struct/commands/arguments/Argument.js'; -import { ApplicationCommandOptionType, PermissionFlagsBits, User } from 'discord.js'; +import { Argument, ArgumentGeneratorReturn } from 'discord-akairo'; +import { ApplicationCommandOptionType, PermissionFlagsBits, type Message } from 'discord.js'; export default class EvidenceCommand extends BushCommand { public constructor() { @@ -48,8 +47,8 @@ export default class EvidenceCommand extends BushCommand { }); } - public override *args(message: BushMessage): ArgumentGeneratorReturn { - const target: ArgumentTypeCasterReturn<'string'> | ArgumentTypeCasterReturn<'snowflake'> = yield { + public override *args(message: CommandMessage): ArgumentGeneratorReturn { + const target: ArgType<'string' | 'snowflake'> = yield { id: 'target', type: Argument.union('snowflake', 'string'), prompt: { @@ -59,7 +58,7 @@ export default class EvidenceCommand extends BushCommand { } }; - const evidence: ArgumentTypeCasterReturn<'string'> = yield { + const evidence: OptArgType<'string'> = yield { id: 'evidence', type: 'string', match: 'restContent', @@ -74,13 +73,18 @@ export default class EvidenceCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, { case_id: caseID, user, target: messageCommandTarget, evidence - }: { case_id?: string; user?: User; target: string | User; evidence: OptArgType<'string'> } + }: { + case_id: OptArgType<'string'>; + user: OptArgType<'user'>; + target: ArgType<'string' | 'snowflake'>; + evidence: OptArgType<'string'>; + } ) { assert(message.inGuild()); @@ -88,22 +92,13 @@ export default class EvidenceCommand extends BushCommand { 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']] - }) + ? util.consts.regex.snowflake.test(messageCommandTarget) + ? await ModLog.findOne({ where: { user: messageCommandTarget }, order: [['createdAt', 'DESC']] }) + : await ModLog.findByPk(messageCommandTarget) : caseID ? await ModLog.findByPk(caseID) - : await ModLog.findOne({ - where: { - user: user!.id - }, - order: [['createdAt', 'DESC']] - }); + : 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.`); @@ -122,8 +117,8 @@ export default class EvidenceCommand extends BushCommand { ); } - public static getEvidence(message: BushMessage | BushSlashMessage, evidenceArg: OptArgType<'string'>): null | string { - if (evidenceArg && (message as BushMessage).attachments?.size) { + public static getEvidence(message: CommandMessage | SlashMessage, evidenceArg: OptArgType<'string'>): null | string { + if (evidenceArg && (message as Message).attachments?.size) { void message.util.reply(`${util.emojis.error} Please either attach an image or a reason not both.`); return null; } @@ -131,7 +126,7 @@ export default class EvidenceCommand extends BushCommand { const _evidence = evidenceArg ? evidenceArg : !message.util.isSlash - ? (message as BushMessage).attachments.first()?.url + ? (message as Message).attachments.first()?.url : undefined; if (!_evidence) { void message.util.reply(`${util.emojis.error} You must provide evidence for this modlog.`); diff --git a/src/commands/moderation/hideCase.ts b/src/commands/moderation/hideCase.ts index 8cec66e..fc5baf4 100644 --- a/src/commands/moderation/hideCase.ts +++ b/src/commands/moderation/hideCase.ts @@ -1,4 +1,4 @@ -import { BushCommand, ModLog, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, ModLog, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, PermissionFlagsBits } from 'discord.js'; @@ -27,7 +27,7 @@ export default class HideCaseCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage, { case_id: caseID }: { case_id: string }) { + public override async exec(message: CommandMessage | SlashMessage, { case_id: caseID }: { case_id: string }) { assert(message.inGuild()); const entry = await ModLog.findByPk(caseID); diff --git a/src/commands/moderation/kick.ts b/src/commands/moderation/kick.ts index 26098b5..a9a0336 100644 --- a/src/commands/moderation/kick.ts +++ b/src/commands/moderation/kick.ts @@ -4,8 +4,9 @@ import { kickResponse, Moderation, type ArgType, - type BushMessage, - type BushSlashMessage + type CommandMessage, + type OptArgType, + type SlashMessage } from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, PermissionFlagsBits } from 'discord.js'; @@ -55,8 +56,8 @@ export default class KickCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, - { user, reason, force }: { user: ArgType<'user'>; reason: ArgType<'string'>; force: boolean } + message: CommandMessage | SlashMessage, + { user, reason, force }: { user: ArgType<'user'>; reason: OptArgType<'string'>; force: ArgType<'flag'> } ) { assert(message.inGuild()); assert(message.member); diff --git a/src/commands/moderation/lockdown.ts b/src/commands/moderation/lockdown.ts index d10a5d4..7d8211c 100644 --- a/src/commands/moderation/lockdown.ts +++ b/src/commands/moderation/lockdown.ts @@ -3,9 +3,9 @@ import { BushCommand, ConfirmationPrompt, type ArgType, - type BushMessage, - type BushSlashMessage, - type OptArgType + type CommandMessage, + type OptArgType, + type SlashMessage } from '#lib'; import assert from 'assert'; import { @@ -72,22 +72,22 @@ export default class LockdownCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, args: { - channel: OptArgType<'textChannel'> | OptArgType<'newsChannel'> | OptArgType<'threadChannel'>; + channel: OptArgType<'textChannel' | 'newsChannel' | 'threadChannel' | 'voiceChannel'>; reason: OptArgType<'string'>; - all: ArgType<'boolean'>; + all: ArgType<'flag'>; } ) { return await LockdownCommand.lockdownOrUnlockdown(message, args, 'lockdown'); } public static async lockdownOrUnlockdown( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, args: { - channel: OptArgType<'textChannel'> | OptArgType<'newsChannel'> | OptArgType<'threadChannel'> | OptArgType<'voiceChannel'>; + channel: OptArgType<'textChannel' | 'newsChannel' | 'threadChannel' | 'voiceChannel'>; reason: OptArgType<'string'>; - all: ArgType<'boolean'>; + all: ArgType<'flag'>; }, action: 'lockdown' | 'unlockdown' ) { diff --git a/src/commands/moderation/massBan.ts b/src/commands/moderation/massBan.ts index f1d85ed..a25c64f 100644 --- a/src/commands/moderation/massBan.ts +++ b/src/commands/moderation/massBan.ts @@ -3,9 +3,9 @@ import { banResponse, BushCommand, type ArgType, - type BushMessage, - type BushSlashMessage, - type OptArgType + type CommandMessage, + type OptArgType, + type SlashMessage } from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, Collection, PermissionFlagsBits } from 'discord.js'; @@ -61,7 +61,7 @@ export default class MassBanCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, args: { users: ArgType<'string'>; reason: OptArgType<'string'>; days: OptArgType<'integer'> } ) { assert(message.inGuild()); diff --git a/src/commands/moderation/massEvidence.ts b/src/commands/moderation/massEvidence.ts index 67f5a25..468d43c 100644 --- a/src/commands/moderation/massEvidence.ts +++ b/src/commands/moderation/massEvidence.ts @@ -1,4 +1,4 @@ -import { BushCommand, ModLog, type ArgType, type BushMessage, type BushSlashMessage, type OptArgType } from '#lib'; +import { BushCommand, ModLog, type ArgType, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, PermissionFlagsBits } from 'discord.js'; import { EvidenceCommand } from '../index.js'; @@ -44,7 +44,7 @@ export default class MassEvidenceCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, args: { users: ArgType<'string'>; evidence: OptArgType<'string'> } ) { assert(message.inGuild()); diff --git a/src/commands/moderation/modlog.ts b/src/commands/moderation/modlog.ts index 66368f9..71ed975 100644 --- a/src/commands/moderation/modlog.ts +++ b/src/commands/moderation/modlog.ts @@ -1,4 +1,4 @@ -import { BushCommand, ButtonPaginator, ModLog, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, ButtonPaginator, ModLog, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, PermissionFlagsBits, User } from 'discord.js'; @@ -40,8 +40,8 @@ export default class ModlogCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, - { search, hidden }: { search: ArgType<'user'> | string; hidden: boolean } + message: CommandMessage | SlashMessage, + { search, hidden }: { search: ArgType<'user'> | string; hidden: ArgType<'flag'> } ) { assert(message.inGuild()); diff --git a/src/commands/moderation/mute.ts b/src/commands/moderation/mute.ts index d846817..a665670 100644 --- a/src/commands/moderation/mute.ts +++ b/src/commands/moderation/mute.ts @@ -4,9 +4,9 @@ import { Moderation, muteResponse, type ArgType, - type BushMessage, - type BushSlashMessage, - type OptArgType + type CommandMessage, + type OptArgType, + type SlashMessage } from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, PermissionFlagsBits } from 'discord.js'; @@ -57,11 +57,11 @@ export default class MuteCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, args: { user: ArgType<'user'>; reason_and_duration: OptArgType<'contentWithDuration'> | string; - force?: ArgType<'boolean'>; + force: ArgType<'flag'>; } ) { assert(message.inGuild()); diff --git a/src/commands/moderation/purge.ts b/src/commands/moderation/purge.ts index 799cf36..1652f6f 100644 --- a/src/commands/moderation/purge.ts +++ b/src/commands/moderation/purge.ts @@ -1,6 +1,6 @@ -import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, OptArgType, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; -import { ApplicationCommandOptionType, Collection, PermissionFlagsBits } from 'discord.js'; +import { ApplicationCommandOptionType, Collection, PermissionFlagsBits, type Message } from 'discord.js'; export default class PurgeCommand extends BushCommand { public constructor() { @@ -50,14 +50,14 @@ export default class PurgeCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, - args: { amount: number; bot: boolean; user: ArgType<'user'> } + message: CommandMessage | SlashMessage, + args: { amount: ArgType<'integer'>; bot: ArgType<'flag'>; user: OptArgType<'user'> } ) { assert(message.inGuild()); if (args.amount > 100 || args.amount < 1) return message.util.reply(`${util.emojis.error} `); - const messageFilter = (filterMessage: BushMessage): boolean => { + const messageFilter = (filterMessage: Message): boolean => { const shouldFilter: boolean[] = []; if (args.bot) shouldFilter.push(filterMessage.author.bot); if (args.user) shouldFilter.push(filterMessage.author.id === args.user.id); @@ -65,16 +65,16 @@ export default class PurgeCommand extends BushCommand { return shouldFilter.filter((bool) => bool === false).length === 0 && filterMessage.id !== message.id; }; const messages = new Collection( - (await message.channel.messages.fetch({ limit: 100, before: message.id })) + (await message.channel!.messages.fetch({ limit: 100, before: message.id })) .filter((message) => messageFilter(message)) .first(args.amount) .map((m) => [m.id, m] as const) ); - const purged = await message.channel.bulkDelete(messages, true).catch(() => null); + const purged = await message.channel!.bulkDelete(messages, true).catch(() => null); if (!purged) return message.util.reply(`${util.emojis.error} Failed to purge messages.`).catch(() => null); else { - client.emit('bushPurge', message.author, message.guild, message.channel, messages); + client.emit('bushPurge', message.author, message.guild, message.channel!, messages); await message.util.send(`${util.emojis.success} Successfully purged **${purged.size}** messages.`); /* .then(async (purgeMessage) => { if (!message.util.isSlashMessage(message)) { diff --git a/src/commands/moderation/removeReactionEmoji.ts b/src/commands/moderation/removeReactionEmoji.ts index bc24db0..4359c5b 100644 --- a/src/commands/moderation/removeReactionEmoji.ts +++ b/src/commands/moderation/removeReactionEmoji.ts @@ -1,4 +1,4 @@ -import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, Message, PermissionFlagsBits } from 'discord.js'; @@ -40,8 +40,8 @@ export default class RemoveReactionEmojiCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, - args: { message: ArgType<'guildMessage'> | string; emoji: ArgType<'emoji'> | ArgType<'snowflake'> } + message: CommandMessage | SlashMessage, + args: { message: ArgType<'guildMessage'> | string; emoji: ArgType<'emoji' | 'snowflake'> } ) { assert(message.channel); const resolvedMessage = args.message instanceof Message ? args.message : await message.channel.messages.fetch(args.message); diff --git a/src/commands/moderation/role.ts b/src/commands/moderation/role.ts index a87b2bf..b9e1490 100644 --- a/src/commands/moderation/role.ts +++ b/src/commands/moderation/role.ts @@ -4,10 +4,11 @@ import { BushCommand, removeRoleResponse, type ArgType, - type BushMessage, - type BushSlashMessage, - type OptArgType + type CommandMessage, + type OptArgType, + type SlashMessage } from '#lib'; +import assert from 'assert'; import { type ArgumentGeneratorReturn } from 'discord-akairo'; import { ApplicationCommandOptionType, PermissionFlagsBits, type Snowflake } from 'discord.js'; @@ -59,6 +60,7 @@ export default class RoleCommand extends BushCommand { ], slash: true, channel: 'guild', + flags: ['--force'], typing: true, clientPermissions: (m) => util.clientSendAndPermCheck(m, [PermissionFlagsBits.ManageRoles, PermissionFlagsBits.EmbedLinks], true), @@ -66,7 +68,7 @@ export default class RoleCommand extends BushCommand { }); } - public override *args(message: BushMessage): ArgumentGeneratorReturn { + public override *args(message: CommandMessage): ArgumentGeneratorReturn { const action = (['rr'] as const).includes(message.util.parsed?.alias ?? '') ? 'remove' : (['ar', 'ra'] as const).includes(message.util.parsed?.alias ?? '') @@ -118,15 +120,16 @@ export default class RoleCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, args: { action: 'add' | 'remove'; member: ArgType<'member'>; role: ArgType<'role'>; - duration?: OptArgType<'duration'>; - force?: boolean; + duration: OptArgType<'duration'>; + force?: ArgType<'flag'>; } ) { + assert(message.inGuild()); if (!args.role) return await message.util.reply(`${util.emojis.error} You must specify a role.`); args.duration ??= 0; if ( diff --git a/src/commands/moderation/slowmode.ts b/src/commands/moderation/slowmode.ts index 6d93ede..e657b76 100644 --- a/src/commands/moderation/slowmode.ts +++ b/src/commands/moderation/slowmode.ts @@ -1,4 +1,4 @@ -import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; import assert from 'assert'; import { Argument } from 'discord-akairo'; import { ApplicationCommandOptionType, ChannelType, PermissionFlagsBits } from 'discord.js'; @@ -42,17 +42,22 @@ export default class SlowmodeCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, args: { - length: ArgType<'duration'> | ArgType<'durationSeconds'> | 'off' | 'none' | 'disable' | null; - channel: ArgType<'channel'>; + length: OptArgType<'duration' | 'durationSeconds'> | 'off' | 'none' | 'disable'; + channel: OptArgType<'channel'>; } ) { assert(message.inGuild()); - args.channel ??= message.channel; + args.channel ??= message.channel!; - if (!args.channel.isTextBased() || args.channel.isNews()) + if ( + args.channel.type !== ChannelType.GuildText && + args.channel.type !== ChannelType.GuildNews && + args.channel.type !== ChannelType.GuildVoice && + !args.channel.isThread() + ) return await message.util.reply(`${util.emojis.error} <#${args.channel.id}> is not a text or thread channel.`); args.length = diff --git a/src/commands/moderation/timeout.ts b/src/commands/moderation/timeout.ts index b8fb78f..ed3562d 100644 --- a/src/commands/moderation/timeout.ts +++ b/src/commands/moderation/timeout.ts @@ -4,8 +4,8 @@ import { Moderation, timeoutResponse, type ArgType, - type BushMessage, - type BushSlashMessage + type CommandMessage, + type SlashMessage } from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, PermissionFlagsBits } from 'discord.js'; @@ -55,8 +55,8 @@ export default class TimeoutCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, - args: { user: ArgType<'user'>; reason_and_duration: ArgType<'contentWithDuration'> | string; force?: ArgType<'boolean'> } + message: CommandMessage | SlashMessage, + args: { user: ArgType<'user'>; reason_and_duration: ArgType<'contentWithDuration'> | string; force?: ArgType<'flag'> } ) { assert(message.inGuild()); assert(message.member); diff --git a/src/commands/moderation/unban.ts b/src/commands/moderation/unban.ts index e6ac6d0..d7549ab 100644 --- a/src/commands/moderation/unban.ts +++ b/src/commands/moderation/unban.ts @@ -3,9 +3,9 @@ import { BushCommand, unbanResponse, type ArgType, - type BushMessage, - type BushSlashMessage, - type OptArgType + type CommandMessage, + type OptArgType, + type SlashMessage } from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, PermissionFlagsBits } from 'discord.js'; @@ -46,8 +46,8 @@ export default class UnbanCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, - { user, reason }: { user: ArgType<'user'>; reason: OptArgType<'string'> } + message: CommandMessage | SlashMessage, + { user, reason }: { user: ArgType<'user' | 'globalUser'>; reason: OptArgType<'string'> } ) { assert(message.inGuild()); diff --git a/src/commands/moderation/unblock.ts b/src/commands/moderation/unblock.ts index 22c9949..886d546 100644 --- a/src/commands/moderation/unblock.ts +++ b/src/commands/moderation/unblock.ts @@ -4,9 +4,9 @@ import { Moderation, unblockResponse, type ArgType, - type BushMessage, - type BushSlashMessage, - type OptArgType + type CommandMessage, + type OptArgType, + type SlashMessage } from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, PermissionFlagsBits } from 'discord.js'; @@ -57,11 +57,12 @@ export default class UnblockCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, - args: { user: ArgType<'user'>; reason: OptArgType<'string'>; force?: ArgType<'boolean'> } + message: CommandMessage | SlashMessage, + args: { user: ArgType<'user'>; reason: OptArgType<'string'>; force?: ArgType<'flag'> } ) { assert(message.inGuild()); assert(message.member); + assert(message.channel); if (!message.channel.isTextBased()) return message.util.send(`${util.emojis.error} This command can only be used in text based channels.`); diff --git a/src/commands/moderation/unlockdown.ts b/src/commands/moderation/unlockdown.ts index 253ce37..dbcd429 100644 --- a/src/commands/moderation/unlockdown.ts +++ b/src/commands/moderation/unlockdown.ts @@ -1,5 +1,5 @@ import { LockdownCommand } from '#commands'; -import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage, type OptArgType } from '#lib'; +import { BushCommand, type ArgType, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; import { ApplicationCommandOptionType, ChannelType, PermissionFlagsBits } from 'discord.js'; export default class UnlockdownCommand extends BushCommand { @@ -14,7 +14,7 @@ export default class UnlockdownCommand extends BushCommand { { id: 'channel', description: 'Specify a different channel to unlockdown instead of the one you trigger the command in.', - type: util.arg.union('textChannel', 'newsChannel', 'threadChannel'), + type: util.arg.union('textChannel', 'newsChannel', 'threadChannel', 'voiceChannel'), prompt: 'What channel would you like to unlockdown?', slashType: ApplicationCommandOptionType.Channel, channelTypes: [ @@ -22,7 +22,8 @@ export default class UnlockdownCommand extends BushCommand { ChannelType.GuildNews, ChannelType.GuildNewsThread, ChannelType.GuildPublicThread, - ChannelType.GuildPrivateThread + ChannelType.GuildPrivateThread, + ChannelType.GuildVoice ], optional: true }, @@ -53,11 +54,11 @@ export default class UnlockdownCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, args: { - channel: OptArgType<'textChannel'> | OptArgType<'newsChannel'> | OptArgType<'threadChannel'>; + channel: OptArgType<'textChannel' | 'newsChannel' | 'threadChannel' | 'voiceChannel'>; reason: OptArgType<'string'>; - all: ArgType<'boolean'>; + all: ArgType<'flag'>; } ) { return await LockdownCommand.lockdownOrUnlockdown(message, args, 'unlockdown'); diff --git a/src/commands/moderation/unmute.ts b/src/commands/moderation/unmute.ts index 094cadd..202e341 100644 --- a/src/commands/moderation/unmute.ts +++ b/src/commands/moderation/unmute.ts @@ -4,10 +4,9 @@ import { Moderation, unmuteResponse, type ArgType, - type BushGuildMember, - type BushMessage, - type BushSlashMessage, - type OptArgType + type CommandMessage, + type OptArgType, + type SlashMessage } from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, PermissionFlagsBits } from 'discord.js'; @@ -58,14 +57,14 @@ export default class UnmuteCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, - { user, reason, force = false }: { user: ArgType<'user'>; reason: OptArgType<'string'>; force?: boolean } + message: CommandMessage | SlashMessage, + { user, reason, force = false }: { user: ArgType<'user'>; reason: OptArgType<'string'>; force?: ArgType<'flag'> } ) { assert(message.inGuild()); assert(message.member); const error = util.emojis.error; - const member = message.guild.members.cache.get(user.id) as BushGuildMember; + const member = message.guild.members.cache.get(user.id)!; const useForce = force && message.author.isOwner(); const canModerateResponse = await Moderation.permissionCheck(message.member, member, 'unmute', true, useForce); diff --git a/src/commands/moderation/untimeout.ts b/src/commands/moderation/untimeout.ts index cbaf7d1..7622f29 100644 --- a/src/commands/moderation/untimeout.ts +++ b/src/commands/moderation/untimeout.ts @@ -4,9 +4,9 @@ import { Moderation, removeTimeoutResponse, type ArgType, - type BushMessage, - type BushSlashMessage, - type OptArgType + type CommandMessage, + type OptArgType, + type SlashMessage } from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, PermissionFlagsBits } from 'discord.js'; @@ -57,8 +57,8 @@ export default class UntimeoutCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, - args: { user: ArgType<'user'>; reason: OptArgType<'string'>; force?: ArgType<'boolean'> } + message: CommandMessage | SlashMessage, + args: { user: ArgType<'user'>; reason: OptArgType<'string'>; force?: ArgType<'flag'> } ) { assert(message.inGuild()); assert(message.member); diff --git a/src/commands/moderation/warn.ts b/src/commands/moderation/warn.ts index 87baf4a..b3bf965 100644 --- a/src/commands/moderation/warn.ts +++ b/src/commands/moderation/warn.ts @@ -4,9 +4,9 @@ import { Moderation, warnResponse, type ArgType, - type BushMessage, - type BushSlashMessage, - type OptArgType + type CommandMessage, + type OptArgType, + type SlashMessage } from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, PermissionFlagsBits } from 'discord.js'; @@ -56,8 +56,8 @@ export default class WarnCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, - { user, reason, force = false }: { user: ArgType<'user'>; reason: OptArgType<'string'>; force?: boolean } + message: CommandMessage | SlashMessage, + { user, reason, force = false }: { user: ArgType<'user'>; reason: OptArgType<'string'>; force?: ArgType<'flag'> } ) { assert(message.inGuild()); assert(message.member); |