diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-06-16 14:32:18 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-06-16 14:32:18 -0400 |
commit | 0e87bbd3940d89defcb04926587b35c8f4d1947f (patch) | |
tree | e50860d4dc25a11d4c3977b583284c4bcad1b077 /src/commands/moderation | |
parent | 661e4c9935aeb8760dafc7ced4bbec6cc356a033 (diff) | |
download | tanzanite-0e87bbd3940d89defcb04926587b35c8f4d1947f.tar.gz tanzanite-0e87bbd3940d89defcb04926587b35c8f4d1947f.tar.bz2 tanzanite-0e87bbd3940d89defcb04926587b35c8f4d1947f.zip |
remove util classes, move config out of src
Diffstat (limited to 'src/commands/moderation')
22 files changed, 367 insertions, 227 deletions
diff --git a/src/commands/moderation/_activePunishments.ts b/src/commands/moderation/_activePunishments.ts index 92b4242..80cecf2 100644 --- a/src/commands/moderation/_activePunishments.ts +++ b/src/commands/moderation/_activePunishments.ts @@ -37,8 +37,8 @@ // slash: true, // channel: 'guild', // hidden: true, -// clientPermissions: (m) => util.clientSendAndPermCheck(m), -// userPermissions: (m) => util.userGuildPermCheck(m, [PermissionFlagsBits.ManageMessages]) +// clientPermissions: (m) => clientSendAndPermCheck(m), +// userPermissions: (m) => userGuildPermCheck(m, [PermissionFlagsBits.ManageMessages]) // }); // } @@ -66,7 +66,7 @@ // 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.`); +// return message.util.reply(`${emojis.error} You supplied an invalid case type to filter by.`); // } // } diff --git a/src/commands/moderation/ban.ts b/src/commands/moderation/ban.ts index f4bd52b..e301fb2 100644 --- a/src/commands/moderation/ban.ts +++ b/src/commands/moderation/ban.ts @@ -1,8 +1,13 @@ import { AllowedMentions, + Arg, banResponse, BushCommand, + castDurationContent, + emojis, + format, Moderation, + resolveNonCachedUser, type ArgType, type CommandMessage, type OptArgType, @@ -23,7 +28,7 @@ export default class BanCommand extends BushCommand { { id: 'user', description: 'The user that will be banned.', - type: util.arg.union('user', 'snowflake'), + type: Arg.union('user', 'snowflake'), readableType: 'user|snowflake', prompt: 'What user would you like to ban?', retry: '{error} Choose a valid user to ban.', @@ -46,7 +51,7 @@ export default class BanCommand extends BushCommand { match: 'option', 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.', - type: util.arg.range('integer', 0, 7, true), + type: Arg.range('integer', 0, 7, true), readableType: 'integer [0, 7]', optional: true, slashType: ApplicationCommandOptionType.Integer, @@ -82,12 +87,12 @@ export default class BanCommand extends BushCommand { assert(message.inGuild()); assert(message.member); - const { duration, content } = await util.castDurationContent(args.reason_and_duration, message); + const { duration, content } = await castDurationContent(args.reason_and_duration, message); args.days ??= message.util.parsed?.alias === 'dban' ? 1 : 0; const member = message.guild.members.cache.get(typeof args.user === 'string' ? args.user : args.user.id); - const user = member?.user ?? (await util.resolveNonCachedUser(typeof args.user === 'string' ? args.user : args.user.id)); - if (!user) return message.util.reply(`${util.emojis.error} Invalid user.`); + const user = member?.user ?? (await resolveNonCachedUser(typeof args.user === 'string' ? args.user : args.user.id)); + if (!user) return message.util.reply(`${emojis.error} Invalid user.`); const useForce = args.force && message.author.isOwner(); const canModerateResponse = member ? await Moderation.permissionCheck(message.member, member, 'ban', true, useForce) : true; @@ -97,7 +102,7 @@ export default class BanCommand extends BushCommand { } if (!Number.isInteger(args.days) || args.days! < 0 || args.days! > 7) { - return message.util.reply(`${util.emojis.error} The delete days must be an integer between 0 and 7.`); + return message.util.reply(`${emojis.error} The delete days must be an integer between 0 and 7.`); } const opts = { reason: content, moderator: message.member, duration: duration, deleteDays: args.days }; @@ -105,24 +110,24 @@ export default class BanCommand extends BushCommand { const responseCode = member ? await member.bushBan(opts) : await message.guild.bushBan({ user, ...opts }); const responseMessage = (): string => { - const victim = util.format.input(user.tag); + const victim = format.input(user.tag); switch (responseCode) { case banResponse.ALREADY_BANNED: - return `${util.emojis.error} ${victim} is already banned.`; + return `${emojis.error} ${victim} is already banned.`; case banResponse.MISSING_PERMISSIONS: - return `${util.emojis.error} Could not ban ${victim} because I am missing the **Ban Members** permission.`; + return `${emojis.error} Could not ban ${victim} because I am missing the **Ban Members** permission.`; case banResponse.ACTION_ERROR: - return `${util.emojis.error} An error occurred while trying to ban ${victim}.`; + return `${emojis.error} An error occurred while trying to ban ${victim}.`; case banResponse.PUNISHMENT_ENTRY_ADD_ERROR: - return `${util.emojis.error} While banning ${victim}, there was an error creating a ban entry, please report this to my developers.`; + return `${emojis.error} While banning ${victim}, there was an error creating a ban entry, please report this to my developers.`; case banResponse.MODLOG_ERROR: - return `${util.emojis.error} While banning ${victim}, there was an error creating a modlog entry, please report this to my developers.`; + return `${emojis.error} While banning ${victim}, there was an error creating a modlog entry, please report this to my developers.`; case banResponse.DM_ERROR: - return `${util.emojis.warn} Banned ${victim} however I could not send them a dm.`; + return `${emojis.warn} Banned ${victim} however I could not send them a dm.`; case banResponse.SUCCESS: - return `${util.emojis.success} Successfully banned ${victim}.`; + return `${emojis.success} Successfully banned ${victim}.`; default: - return `${util.emojis.error} An error occurred: ${util.format.input(responseCode)}}`; + return `${emojis.error} An error occurred: ${format.input(responseCode)}}`; } }; return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() }); diff --git a/src/commands/moderation/block.ts b/src/commands/moderation/block.ts index 16beb6f..fc93fb1 100644 --- a/src/commands/moderation/block.ts +++ b/src/commands/moderation/block.ts @@ -2,7 +2,12 @@ import { AllowedMentions, blockResponse, BushCommand, + castDurationContent, + clientSendAndPermCheck, + emojis, + format, Moderation, + userGuildPermCheck, type ArgType, type CommandMessage, type OptArgType, @@ -51,8 +56,8 @@ export default class BlockCommand extends BushCommand { ], slash: true, channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m, [PermissionFlagsBits.ManageChannels]), - userPermissions: (m) => util.userGuildPermCheck(m, [PermissionFlagsBits.ManageMessages]), + clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.ManageChannels]), + userPermissions: (m) => userGuildPermCheck(m, [PermissionFlagsBits.ManageMessages]), lock: 'channel' }); } @@ -70,13 +75,13 @@ export default class BlockCommand extends BushCommand { assert(message.channel); if (!message.channel.isTextBased()) - return message.util.send(`${util.emojis.error} This command can only be used in text based channels.`); + return message.util.send(`${emojis.error} This command can only be used in text based channels.`); - const { duration, content } = await util.castDurationContent(args.reason_and_duration, message); + const { duration, content } = await castDurationContent(args.reason_and_duration, message); const member = await message.guild.members.fetch(args.user.id).catch(() => null); if (!member) - return await message.util.reply(`${util.emojis.error} The user you selected is not in the server or is not a valid user.`); + return await message.util.reply(`${emojis.error} The user you selected is not in the server or is not a valid user.`); const useForce = args.force && message.author.isOwner(); const canModerateResponse = await Moderation.permissionCheck(message.member, member, 'block', true, useForce); @@ -93,24 +98,24 @@ export default class BlockCommand extends BushCommand { }); const responseMessage = (): string => { - const victim = util.format.input(member.user.tag); + const victim = format.input(member.user.tag); switch (responseCode) { case blockResponse.MISSING_PERMISSIONS: - return `${util.emojis.error} Could not block ${victim} because I am missing the **Manage Channel** permission.`; + return `${emojis.error} Could not block ${victim} because I am missing the **Manage Channel** permission.`; case blockResponse.INVALID_CHANNEL: - return `${util.emojis.error} Could not block ${victim}, you can only block users in text or thread channels.`; + return `${emojis.error} Could not block ${victim}, you can only block users in text or thread channels.`; case blockResponse.ACTION_ERROR: - return `${util.emojis.error} An unknown error occurred while trying to block ${victim}.`; + return `${emojis.error} An unknown error occurred while trying to block ${victim}.`; case blockResponse.MODLOG_ERROR: - return `${util.emojis.error} There was an error creating a modlog entry, please report this to my developers.`; + return `${emojis.error} There was an error creating a modlog entry, please report this to my developers.`; case blockResponse.PUNISHMENT_ENTRY_ADD_ERROR: - return `${util.emojis.error} There was an error creating a punishment entry, please report this to my developers.`; + return `${emojis.error} There was an error creating a punishment entry, please report this to my developers.`; case blockResponse.DM_ERROR: - return `${util.emojis.warn} Blocked ${victim} however I could not send them a dm.`; + return `${emojis.warn} Blocked ${victim} however I could not send them a dm.`; case blockResponse.SUCCESS: - return `${util.emojis.success} Successfully blocked ${victim}.`; + return `${emojis.success} Successfully blocked ${victim}.`; default: - return `${util.emojis.error} An error occurred: ${util.format.input(responseCode)}}`; + return `${emojis.error} An error occurred: ${format.input(responseCode)}}`; } }; return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() }); diff --git a/src/commands/moderation/evidence.ts b/src/commands/moderation/evidence.ts index f1fac0d..3c9e726 100644 --- a/src/commands/moderation/evidence.ts +++ b/src/commands/moderation/evidence.ts @@ -1,4 +1,16 @@ -import { BushCommand, ModLog, OptArgType, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; +import { + BushCommand, + clientSendAndPermCheck, + emojis, + format, + ModLog, + OptArgType, + regex, + userGuildPermCheck, + type ArgType, + type CommandMessage, + type SlashMessage +} from '#lib'; import assert from 'assert'; import { Argument, ArgumentGeneratorReturn } from 'discord-akairo'; import { ApplicationCommandOptionType, PermissionFlagsBits, type Message } from 'discord.js'; @@ -42,8 +54,8 @@ export default class EvidenceCommand extends BushCommand { ], slash: true, channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m), - userPermissions: (m) => util.userGuildPermCheck(m, [PermissionFlagsBits.ManageMessages]) + clientPermissions: (m) => clientSendAndPermCheck(m), + userPermissions: (m) => userGuildPermCheck(m, [PermissionFlagsBits.ManageMessages]) }); } @@ -89,18 +101,18 @@ export default class EvidenceCommand extends BushCommand { assert(message.inGuild()); if (message.interaction && !caseID && !user) - return message.util.send(`${util.emojis.error} You must provide either a user or a case ID.`); + return message.util.send(`${emojis.error} You must provide either a user or a case ID.`); const entry = messageCommandTarget - ? util.consts.regex.snowflake.test(messageCommandTarget) + ? 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']] }); - 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 (!entry || entry.pseudo) return message.util.send(`${emojis.error} Invalid modlog entry.`); + if (entry.guild !== message.guild.id) return message.util.reply(`${emojis.error} This modlog is from another server.`); const oldEntry = entry.evidence; @@ -112,14 +124,12 @@ 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(entry.id)}.` - ); + return message.util.reply(`${emojis.success} Successfully updated the evidence for case ${format.input(entry.id)}.`); } 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.`); + void message.util.reply(`${emojis.error} Please either attach an image or a reason not both.`); return null; } @@ -129,7 +139,7 @@ export default class EvidenceCommand extends BushCommand { ? (message as Message).attachments.first()?.url : undefined; if (!_evidence) { - void message.util.reply(`${util.emojis.error} You must provide evidence for this modlog.`); + void message.util.reply(`${emojis.error} You must provide evidence for this modlog.`); return null; } diff --git a/src/commands/moderation/hideCase.ts b/src/commands/moderation/hideCase.ts index fc5baf4..0cc3de4 100644 --- a/src/commands/moderation/hideCase.ts +++ b/src/commands/moderation/hideCase.ts @@ -1,4 +1,13 @@ -import { BushCommand, ModLog, type CommandMessage, type SlashMessage } from '#lib'; +import { + BushCommand, + clientSendAndPermCheck, + emojis, + format, + ModLog, + userGuildPermCheck, + type CommandMessage, + type SlashMessage +} from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, PermissionFlagsBits } from 'discord.js'; @@ -21,8 +30,8 @@ export default class HideCaseCommand extends BushCommand { } ], slash: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m), - userPermissions: (m) => util.userGuildPermCheck(m, [PermissionFlagsBits.ManageMessages]), + clientPermissions: (m) => clientSendAndPermCheck(m), + userPermissions: (m) => userGuildPermCheck(m, [PermissionFlagsBits.ManageMessages]), channel: 'guild' }); } @@ -31,8 +40,8 @@ export default class HideCaseCommand extends BushCommand { assert(message.inGuild()); const entry = await ModLog.findByPk(caseID); - if (!entry || entry.pseudo) return message.util.send(`${util.emojis.error} Invalid entry.`); - if (entry.guild !== message.guild.id) return message.util.reply(`${util.emojis.error} This modlog is from another server.`); + if (!entry || entry.pseudo) return message.util.send(`${emojis.error} Invalid entry.`); + if (entry.guild !== message.guild.id) return message.util.reply(`${emojis.error} This modlog is from another server.`); const action = entry.hidden ? 'no longer hidden' : 'now hidden'; const oldEntry = entry.hidden; entry.hidden = !entry.hidden; @@ -40,6 +49,6 @@ export default class HideCaseCommand extends BushCommand { client.emit('bushUpdateModlog', message.member!, entry.id, 'hidden', oldEntry, entry.hidden); - return await message.util.reply(`${util.emojis.success} CaseID ${util.format.input(caseID)} is ${action}.`); + return await message.util.reply(`${emojis.success} CaseID ${format.input(caseID)} is ${action}.`); } } diff --git a/src/commands/moderation/kick.ts b/src/commands/moderation/kick.ts index a9a0336..bf079f3 100644 --- a/src/commands/moderation/kick.ts +++ b/src/commands/moderation/kick.ts @@ -1,6 +1,9 @@ import { AllowedMentions, BushCommand, + clientSendAndPermCheck, + emojis, + format, kickResponse, Moderation, type ArgType, @@ -50,7 +53,7 @@ export default class KickCommand extends BushCommand { } ], slash: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m, [PermissionFlagsBits.KickMembers]), + clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.KickMembers]), userPermissions: [PermissionFlagsBits.KickMembers] }); } @@ -65,7 +68,7 @@ export default class KickCommand extends BushCommand { const member = await message.guild.members.fetch(user.id); if (!member) - return await message.util.reply(`${util.emojis.error} The user you selected is not in the server or is not a valid user.`); + return await message.util.reply(`${emojis.error} The user you selected is not in the server or is not a valid user.`); const useForce = force && message.author.isOwner(); const canModerateResponse = await Moderation.permissionCheck(message.member, member, 'kick', true, useForce); @@ -79,20 +82,20 @@ export default class KickCommand extends BushCommand { }); const responseMessage = (): string => { - const victim = util.format.input(member.user.tag); + const victim = format.input(member.user.tag); switch (responseCode) { case kickResponse.MISSING_PERMISSIONS: - return `${util.emojis.error} Could not kick ${victim} because I am missing the **Kick Members** permission.`; + return `${emojis.error} Could not kick ${victim} because I am missing the **Kick Members** permission.`; case kickResponse.ACTION_ERROR: - return `${util.emojis.error} An error occurred while trying to kick ${victim}.`; + return `${emojis.error} An error occurred while trying to kick ${victim}.`; case kickResponse.MODLOG_ERROR: - return `${util.emojis.error} While muting ${victim}, there was an error creating a modlog entry, please report this to my developers.`; + return `${emojis.error} While muting ${victim}, there was an error creating a modlog entry, please report this to my developers.`; case kickResponse.DM_ERROR: - return `${util.emojis.warn} Kicked ${victim} however I could not send them a dm.`; + return `${emojis.warn} Kicked ${victim} however I could not send them a dm.`; case kickResponse.SUCCESS: - return `${util.emojis.success} Successfully kicked ${victim}.`; + return `${emojis.success} Successfully kicked ${victim}.`; default: - return `${util.emojis.error} An error occurred: ${util.format.input(responseCode)}}`; + return `${emojis.error} An error occurred: ${format.input(responseCode)}}`; } }; return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() }); diff --git a/src/commands/moderation/lockdown.ts b/src/commands/moderation/lockdown.ts index 7d8211c..76d61d0 100644 --- a/src/commands/moderation/lockdown.ts +++ b/src/commands/moderation/lockdown.ts @@ -1,7 +1,12 @@ import { AllowedMentions, + Arg, BushCommand, + clientSendAndPermCheck, + colors, ConfirmationPrompt, + emojis, + format, type ArgType, type CommandMessage, type OptArgType, @@ -31,7 +36,7 @@ export default class LockdownCommand extends BushCommand { { id: 'channel', description: 'Specify a different channel to lockdown instead of the one you trigger the command in.', - type: util.arg.union('textChannel', 'newsChannel', 'threadChannel', 'voiceChannel'), + type: Arg.union('textChannel', 'newsChannel', 'threadChannel', 'voiceChannel'), prompt: 'What channel would you like to lockdown?', slashType: ApplicationCommandOptionType.Channel, channelTypes: [ @@ -65,7 +70,7 @@ export default class LockdownCommand extends BushCommand { ], slash: true, channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m, [PermissionFlagsBits.ManageChannels]), + clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.ManageChannels]), userPermissions: [PermissionFlagsBits.ManageChannels], lock: 'channel' }); @@ -95,7 +100,7 @@ export default class LockdownCommand extends BushCommand { if (message.util.isSlashMessage(message)) await message.interaction.deferReply(); if (args.channel && args.all) - return await message.util.reply(`${util.emojis.error} You can't specify a channel and set all to true at the same time.`); + return await message.util.reply(`${emojis.error} You can't specify a channel and set all to true at the same time.`); const channel = args.channel ?? message.channel; @@ -108,14 +113,14 @@ export default class LockdownCommand extends BushCommand { ) ) return await message.util.reply( - `${util.emojis.error} You can only ${action} text channels, news channels, and thread channels.` + `${emojis.error} You can only ${action} text channels, news channels, and thread channels.` ); if (args.all) { const confirmation = await ConfirmationPrompt.send(message, { content: `Are you sure you want to ${action} all channels?` }); - if (!confirmation) return message.util.sendNew(`${util.emojis.error} Lockdown cancelled.`); + if (!confirmation) return message.util.sendNew(`${emojis.error} Lockdown cancelled.`); } const response = await message.guild.lockdown({ @@ -128,33 +133,33 @@ export default class LockdownCommand extends BushCommand { if (response instanceof Collection) { return await message.util.sendNew({ - content: `${util.emojis.error} The following channels failed to ${action}:`, + content: `${emojis.error} The following channels failed to ${action}:`, embeds: [ { description: response.map((e, c) => `<#${c}> : ${e.message}`).join('\n'), - color: util.colors.warn + color: colors.warn } ] }); } else { let messageResponse; if (response === 'all not chosen and no channel specified') { - messageResponse = `${util.emojis.error} You must specify a channel to ${action}.`; + messageResponse = `${emojis.error} You must specify a channel to ${action}.`; } else if (response.startsWith('invalid channel configured: ')) { const channels = response.replace('invalid channel configured: ', ''); const actionFormatted = `${action.replace('down', '')}ed`; - messageResponse = `${util.emojis.error} Some of the channels configured to be ${actionFormatted} cannot be resolved: ${channels}}`; + messageResponse = `${emojis.error} Some of the channels configured to be ${actionFormatted} cannot be resolved: ${channels}}`; } else if (response === 'no channels configured') { - messageResponse = `${util.emojis.error} The all option is selected but there are no channels configured to be locked down.`; + messageResponse = `${emojis.error} The all option is selected but there are no channels configured to be locked down.`; } else if (response === 'moderator not found') { - messageResponse = `${util.emojis.error} For some reason I could not resolve you?`; + messageResponse = `${emojis.error} For some reason I could not resolve you?`; } else if (response.startsWith('success: ')) { const num = Number.parseInt(response.replace('success: ', '')); - messageResponse = `${util.emojis.success} Successfully ${ + messageResponse = `${emojis.success} Successfully ${ action === 'lockdown' ? 'locked down' : 'unlocked' } **${num}** channel${num > 0 ? 's' : ''}.`; } else { - return `${util.emojis.error} An error occurred: ${util.format.input(response)}}`; + return `${emojis.error} An error occurred: ${format.input(response)}}`; } assert(messageResponse); diff --git a/src/commands/moderation/massBan.ts b/src/commands/moderation/massBan.ts index a25c64f..ab9fbc8 100644 --- a/src/commands/moderation/massBan.ts +++ b/src/commands/moderation/massBan.ts @@ -1,7 +1,13 @@ import { + Arg, BanResponse, banResponse, BushCommand, + clientSendAndPermCheck, + colors, + emojis, + overflowEmbed, + regex, type ArgType, type CommandMessage, type OptArgType, @@ -45,7 +51,7 @@ export default class MassBanCommand extends BushCommand { match: 'option', 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.', - type: util.arg.range('integer', 0, 7, true), + type: Arg.range('integer', 0, 7, true), optional: true, slashType: ApplicationCommandOptionType.Integer, choices: [...Array(8).keys()].map((v) => ({ name: v.toString(), value: v })) @@ -54,7 +60,7 @@ export default class MassBanCommand extends BushCommand { quoted: true, slash: true, channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [PermissionFlagsBits.BanMembers], lock: 'user' }); @@ -69,14 +75,13 @@ export default class MassBanCommand extends BushCommand { args.days ??= message.util.parsed?.alias?.includes('dban') ? 1 : 0; const ids = args.users.split(/\n| /).filter((id) => id.length > 0); - if (ids.length === 0) return message.util.send(`${util.emojis.error} You must provide at least one user id.`); + if (ids.length === 0) return message.util.send(`${emojis.error} You must provide at least one user id.`); for (const id of ids) { - if (!client.constants.regex.snowflake.test(id)) - return message.util.send(`${util.emojis.error} ${id} is not a valid snowflake.`); + if (!regex.snowflake.test(id)) return message.util.send(`${emojis.error} ${id} is not a valid snowflake.`); } if (!Number.isInteger(args.days) || args.days! < 0 || args.days! > 7) { - return message.util.reply(`${util.emojis.error} The delete days must be an integer between 0 and 7.`); + return message.util.reply(`${emojis.error} The delete days must be an integer between 0 and 7.`); } const promises = ids.map((id) => @@ -99,13 +104,13 @@ export default class MassBanCommand extends BushCommand { const id = ids[i]; const status = res[i]; const isSuccess = success(status); - const emoji = isSuccess ? util.emojis.success : util.emojis.error; + const emoji = isSuccess ? emojis.success : emojis.error; return `${emoji} ${id}${isSuccess ? '' : ` - ${status}`}`; }); - const embeds = util.overflowEmbed( + const embeds = overflowEmbed( { - color: util.colors.DarkRed, + color: colors.DarkRed, title: 'Mass Ban Results' }, lines diff --git a/src/commands/moderation/massEvidence.ts b/src/commands/moderation/massEvidence.ts index 468d43c..ffe85d2 100644 --- a/src/commands/moderation/massEvidence.ts +++ b/src/commands/moderation/massEvidence.ts @@ -1,4 +1,16 @@ -import { BushCommand, ModLog, type ArgType, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; +import { + BushCommand, + clientSendAndPermCheck, + colors, + emojis, + ModLog, + overflowEmbed, + regex, + 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'; @@ -37,7 +49,7 @@ export default class MassEvidenceCommand extends BushCommand { quoted: true, slash: true, channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [PermissionFlagsBits.ManageMessages], lock: 'user' }); @@ -53,10 +65,9 @@ export default class MassEvidenceCommand extends BushCommand { if (!evidence) return; const ids = args.users.split(/\n| /).filter((id) => id.length > 0); - if (ids.length === 0) return message.util.send(`${util.emojis.error} You must provide at least one user id.`); + if (ids.length === 0) return message.util.send(`${emojis.error} You must provide at least one user id.`); for (const id of ids) { - if (!client.constants.regex.snowflake.test(id)) - return message.util.send(`${util.emojis.error} ${id} is not a valid snowflake.`); + if (!regex.snowflake.test(id)) return message.util.send(`${emojis.error} ${id} is not a valid snowflake.`); } const caseMap = ( @@ -78,15 +89,15 @@ export default class MassEvidenceCommand extends BushCommand { const lines = ids.map((id, i) => { const case_ = res[i]; - if (!case_) return `${util.emojis.error} ${id} - no case found.`; - return `${util.emojis.success} ${id} - ${case_.id}`; + if (!case_) return `${emojis.error} ${id} - no case found.`; + return `${emojis.success} ${id} - ${case_.id}`; }); client.emit('massEvidence', message.member!, message.guild, evidence, lines); - const embeds = util.overflowEmbed( + const embeds = overflowEmbed( { - color: util.colors.DarkRed, + color: colors.DarkRed, title: 'Mass Evidence' }, lines diff --git a/src/commands/moderation/modlog.ts b/src/commands/moderation/modlog.ts index 71ed975..2c0e33a 100644 --- a/src/commands/moderation/modlog.ts +++ b/src/commands/moderation/modlog.ts @@ -1,6 +1,22 @@ -import { BushCommand, ButtonPaginator, ModLog, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; +import { + Arg, + BushCommand, + ButtonPaginator, + chunk, + clientSendAndPermCheck, + colors, + emojis, + humanizeDuration, + ModLog, + resolveUserAsync, + timestamp, + userGuildPermCheck, + type ArgType, + type CommandMessage, + type SlashMessage +} from '#lib'; import assert from 'assert'; -import { ApplicationCommandOptionType, PermissionFlagsBits, User } from 'discord.js'; +import { ApplicationCommandOptionType, escapeMarkdown, PermissionFlagsBits, User } from 'discord.js'; export default class ModlogCommand extends BushCommand { public static separator = '\n━━━━━━━━━━━━━━━\n'; @@ -16,7 +32,7 @@ export default class ModlogCommand extends BushCommand { { id: 'search', description: 'The case id or user to search for modlogs by.', - type: util.arg.union('user', 'string'), + type: Arg.union('user', 'string'), prompt: 'What case id or user would you like to see?', retry: '{error} Choose a valid case id or user.', slashType: ApplicationCommandOptionType.String @@ -34,8 +50,8 @@ export default class ModlogCommand extends BushCommand { ], slash: true, channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m), - userPermissions: (m) => util.userGuildPermCheck(m, [PermissionFlagsBits.ManageMessages]) + clientPermissions: (m) => clientSendAndPermCheck(m), + userPermissions: (m) => userGuildPermCheck(m, [PermissionFlagsBits.ManageMessages]) }); } @@ -45,7 +61,7 @@ export default class ModlogCommand extends BushCommand { ) { assert(message.inGuild()); - const foundUser = search instanceof User ? search : await util.resolveUserAsync(search); + const foundUser = search instanceof User ? search : await resolveUserAsync(search); if (foundUser) { const logs = await ModLog.findAll({ where: { @@ -59,23 +75,23 @@ export default class ModlogCommand extends BushCommand { .filter((log) => !(log.hidden && hidden)) .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); + return message.util.reply(`${emojis.error} **${foundUser.tag}** does not have any modlogs.`); + const chunked: string[][] = chunk(niceLogs, 4); const embedPages = chunked.map((chunk) => ({ title: `${foundUser.tag}'s Mod Logs`, description: chunk.join(ModlogCommand.separator), - color: util.colors.default + color: colors.default })); return await ButtonPaginator.send(message, embedPages, undefined, true); } else if (search) { const entry = await ModLog.findByPk(search as string); if (!entry || entry.pseudo || (entry.hidden && !hidden)) - return message.util.send(`${util.emojis.error} That modlog does not exist.`); - if (entry.guild !== message.guild.id) return message.util.reply(`${util.emojis.error} This modlog is from another server.`); + return message.util.send(`${emojis.error} That modlog does not exist.`); + if (entry.guild !== message.guild.id) return message.util.reply(`${emojis.error} This modlog is from another server.`); const embed = { title: `Case ${entry.id}`, description: ModlogCommand.generateModlogInfo(entry, true), - color: util.colors.default + color: colors.default }; return await ButtonPaginator.send(message, [embed]); } @@ -83,12 +99,12 @@ export default class ModlogCommand extends BushCommand { public 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()}`]; + const modLog = [`**Case ID:** ${escapeMarkdown(log.id)}`, `**Type:** ${log.type.toLowerCase()}`]; if (showUser) modLog.push(`**User:** <@!${log.user}>`); modLog.push(`**Moderator:** <@!${log.moderator}>`); - if (log.duration) modLog.push(`**Duration:** ${util.humanizeDuration(log.duration)}`); + if (log.duration) modLog.push(`**Duration:** ${humanizeDuration(log.duration)}`); modLog.push(`**Reason:** ${trim(log.reason ?? 'No Reason Specified.')}`); - modLog.push(`**Date:** ${util.timestamp(log.createdAt)}`); + modLog.push(`**Date:** ${timestamp(log.createdAt)}`); if (log.evidence) modLog.push(`**Evidence:** ${trim(log.evidence)}`); return modLog.join(`\n`); } diff --git a/src/commands/moderation/mute.ts b/src/commands/moderation/mute.ts index a665670..7ad023a 100644 --- a/src/commands/moderation/mute.ts +++ b/src/commands/moderation/mute.ts @@ -1,8 +1,14 @@ import { AllowedMentions, BushCommand, + castDurationContent, + clientSendAndPermCheck, + emojis, + format, Moderation, muteResponse, + prefix, + userGuildPermCheck, type ArgType, type CommandMessage, type OptArgType, @@ -51,8 +57,8 @@ export default class MuteCommand extends BushCommand { ], slash: true, channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m, [PermissionFlagsBits.ManageRoles]), - userPermissions: (m) => util.userGuildPermCheck(m, [PermissionFlagsBits.ManageMessages]) + clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.ManageRoles]), + userPermissions: (m) => userGuildPermCheck(m, [PermissionFlagsBits.ManageMessages]) }); } @@ -67,11 +73,11 @@ export default class MuteCommand extends BushCommand { assert(message.inGuild()); assert(message.member); - const { duration, content } = await util.castDurationContent(args.reason_and_duration, message); + const { duration, content } = await castDurationContent(args.reason_and_duration, message); const member = await message.guild.members.fetch(args.user.id).catch(() => null); if (!member) - return await message.util.reply(`${util.emojis.error} The user you selected is not in the server or is not a valid user.`); + return await message.util.reply(`${emojis.error} The user you selected is not in the server or is not a valid user.`); const useForce = args.force && message.author.isOwner(); const canModerateResponse = await Moderation.permissionCheck(message.member, member, 'mute', true, useForce); @@ -87,29 +93,29 @@ export default class MuteCommand extends BushCommand { }); const responseMessage = (): string => { - const prefix = util.prefix(message); - const victim = util.format.input(member.user.tag); + const prefix_ = prefix(message); + const victim = format.input(member.user.tag); switch (responseCode) { case muteResponse.MISSING_PERMISSIONS: - return `${util.emojis.error} Could not mute ${victim} because I am missing the **Manage Roles** permission.`; + return `${emojis.error} Could not mute ${victim} because I am missing the **Manage Roles** permission.`; case muteResponse.NO_MUTE_ROLE: - return `${util.emojis.error} Could not mute ${victim}, you must set a mute role with \`${prefix}config muteRole\`.`; + return `${emojis.error} Could not mute ${victim}, you must set a mute role with \`${prefix_}config muteRole\`.`; case muteResponse.MUTE_ROLE_INVALID: - return `${util.emojis.error} Could not mute ${victim} because the current mute role no longer exists. Please set a new mute role with \`${prefix}config muteRole\`.`; + return `${emojis.error} Could not mute ${victim} because the current mute role no longer exists. Please set a new mute role with \`${prefix_}config muteRole\`.`; case muteResponse.MUTE_ROLE_NOT_MANAGEABLE: - return `${util.emojis.error} Could not mute ${victim} because I cannot assign the current mute role, either change the role's position or set a new mute role with \`${prefix}config muteRole\`.`; + return `${emojis.error} Could not mute ${victim} because I cannot assign the current mute role, either change the role's position or set a new mute role with \`${prefix_}config muteRole\`.`; case muteResponse.ACTION_ERROR: - return `${util.emojis.error} Could not mute ${victim}, there was an error assigning them the mute role.`; + return `${emojis.error} Could not mute ${victim}, there was an error assigning them the mute role.`; case muteResponse.MODLOG_ERROR: - return `${util.emojis.error} There was an error creating a modlog entry, please report this to my developers.`; + return `${emojis.error} There was an error creating a modlog entry, please report this to my developers.`; case muteResponse.PUNISHMENT_ENTRY_ADD_ERROR: - return `${util.emojis.error} There was an error creating a punishment entry, please report this to my developers.`; + return `${emojis.error} There was an error creating a punishment entry, please report this to my developers.`; case muteResponse.DM_ERROR: - return `${util.emojis.warn} Muted ${victim} however I could not send them a dm.`; + return `${emojis.warn} Muted ${victim} however I could not send them a dm.`; case muteResponse.SUCCESS: - return `${util.emojis.success} Successfully muted ${victim}.`; + return `${emojis.success} Successfully muted ${victim}.`; default: - return `${util.emojis.error} An error occurred: ${util.format.input(responseCode)}}`; + return `${emojis.error} An error occurred: ${format.input(responseCode)}}`; } }; return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() }); diff --git a/src/commands/moderation/purge.ts b/src/commands/moderation/purge.ts index 1652f6f..acf3897 100644 --- a/src/commands/moderation/purge.ts +++ b/src/commands/moderation/purge.ts @@ -1,4 +1,13 @@ -import { BushCommand, OptArgType, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; +import { + Arg, + BushCommand, + clientSendAndPermCheck, + emojis, + OptArgType, + type ArgType, + type CommandMessage, + type SlashMessage +} from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, Collection, PermissionFlagsBits, type Message } from 'discord.js'; @@ -14,7 +23,7 @@ export default class PurgeCommand extends BushCommand { { id: 'amount', description: 'The amount of messages to purge.', - type: util.arg.range('integer', 1, 100, true), + type: Arg.range('integer', 1, 100, true), readableType: 'integer', prompt: 'How many messages would you like to purge?', retry: '{error} Please pick a number between 1 and 100.', @@ -43,7 +52,7 @@ export default class PurgeCommand extends BushCommand { ], slash: true, clientPermissions: (m) => - util.clientSendAndPermCheck(m, [PermissionFlagsBits.ManageMessages, PermissionFlagsBits.EmbedLinks], true), + clientSendAndPermCheck(m, [PermissionFlagsBits.ManageMessages, PermissionFlagsBits.EmbedLinks], true), userPermissions: [PermissionFlagsBits.ManageMessages], channel: 'guild' }); @@ -55,7 +64,7 @@ export default class PurgeCommand extends BushCommand { ) { assert(message.inGuild()); - if (args.amount > 100 || args.amount < 1) return message.util.reply(`${util.emojis.error} `); + if (args.amount > 100 || args.amount < 1) return message.util.reply(`${emojis.error} `); const messageFilter = (filterMessage: Message): boolean => { const shouldFilter: boolean[] = []; @@ -72,13 +81,13 @@ export default class PurgeCommand extends BushCommand { ); 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); + if (!purged) return message.util.reply(`${emojis.error} Failed to purge messages.`).catch(() => null); else { client.emit('bushPurge', message.author, message.guild, message.channel!, messages); - await message.util.send(`${util.emojis.success} Successfully purged **${purged.size}** messages.`); + await message.util.send(`${emojis.success} Successfully purged **${purged.size}** messages.`); /* .then(async (purgeMessage) => { if (!message.util.isSlashMessage(message)) { - await util.sleep(5); + await sleep(5); await purgeMessage.delete().catch(() => {}); } }); */ diff --git a/src/commands/moderation/removeReactionEmoji.ts b/src/commands/moderation/removeReactionEmoji.ts index 4359c5b..a088287 100644 --- a/src/commands/moderation/removeReactionEmoji.ts +++ b/src/commands/moderation/removeReactionEmoji.ts @@ -1,4 +1,13 @@ -import { BushCommand, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; +import { + Arg, + BushCommand, + clientSendAndPermCheck, + emojis, + format, + type ArgType, + type CommandMessage, + type SlashMessage +} from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, Message, PermissionFlagsBits } from 'discord.js'; @@ -14,7 +23,7 @@ export default class RemoveReactionEmojiCommand extends BushCommand { { id: 'message', description: 'The message to remove all the reactions of a certain emoji from.', - type: util.arg.union('message', 'messageLink'), + type: Arg.union('message', 'messageLink'), readableType: 'message|messageLink', prompt: 'What message would you like to remove a reaction from?', retry: '{error} Please pick a valid message.', @@ -23,7 +32,7 @@ export default class RemoveReactionEmojiCommand extends BushCommand { { id: 'emoji', description: 'The emoji to remove all the reactions of from a message.', - type: util.arg.union('emoji', 'snowflake'), + type: Arg.union('emoji', 'snowflake'), readableType: 'emoji|snowflake', match: 'restContent', prompt: 'What emoji would you like to remove?', @@ -34,7 +43,7 @@ export default class RemoveReactionEmojiCommand extends BushCommand { slash: true, channel: 'guild', clientPermissions: (m) => - util.clientSendAndPermCheck(m, [PermissionFlagsBits.ManageMessages, PermissionFlagsBits.EmbedLinks], true), + clientSendAndPermCheck(m, [PermissionFlagsBits.ManageMessages, PermissionFlagsBits.EmbedLinks], true), userPermissions: [PermissionFlagsBits.ManageMessages, PermissionFlagsBits.ManageEmojisAndStickers] // Can't undo the removal of 1000s of reactions }); } @@ -54,15 +63,15 @@ export default class RemoveReactionEmojiCommand extends BushCommand { if (success) { return await message.util.reply( - `${util.emojis.success} Removed all reactions of ${util.format.input( - emojiID! - )} from the message with the id of ${util.format.input(resolvedMessage.id)}.` + `${emojis.success} Removed all reactions of ${format.input(emojiID!)} from the message with the id of ${format.input( + resolvedMessage.id + )}.` ); } else { return await message.util.reply( - `${util.emojis.error} There was an error removing all reactions of ${util.format.input( + `${emojis.error} There was an error removing all reactions of ${format.input( emojiID! - )} from the message with the id of ${util.format.input(resolvedMessage.id)}.` + )} from the message with the id of ${format.input(resolvedMessage.id)}.` ); } } diff --git a/src/commands/moderation/role.ts b/src/commands/moderation/role.ts index b9e1490..6febaa6 100644 --- a/src/commands/moderation/role.ts +++ b/src/commands/moderation/role.ts @@ -2,6 +2,11 @@ import { addRoleResponse, AllowedMentions, BushCommand, + clientSendAndPermCheck, + emojis, + format, + humanizeDuration, + mappings, removeRoleResponse, type ArgType, type CommandMessage, @@ -63,7 +68,7 @@ export default class RoleCommand extends BushCommand { flags: ['--force'], typing: true, clientPermissions: (m) => - util.clientSendAndPermCheck(m, [PermissionFlagsBits.ManageRoles, PermissionFlagsBits.EmbedLinks], true), + clientSendAndPermCheck(m, [PermissionFlagsBits.ManageRoles, PermissionFlagsBits.EmbedLinks], true), userPermissions: [] }); } @@ -130,14 +135,13 @@ export default class RoleCommand extends BushCommand { } ) { assert(message.inGuild()); - if (!args.role) return await message.util.reply(`${util.emojis.error} You must specify a role.`); + if (!args.role) return await message.util.reply(`${emojis.error} You must specify a role.`); args.duration ??= 0; if ( !message.member!.permissions.has(PermissionFlagsBits.ManageRoles) && message.member!.id !== message.guild?.ownerId && !message.member!.user.isOwner() ) { - const mappings = client.consts.mappings; let mappedRole: { name: string; id: string }; for (let i = 0; i < mappings.roleMap.length; i++) { const a = mappings.roleMap[i]; @@ -145,7 +149,7 @@ export default class RoleCommand extends BushCommand { } if (!mappedRole! || !(mappedRole.name in mappings.roleWhitelist)) { return await message.util.reply({ - content: `${util.emojis.error} <@&${args.role.id}> is not whitelisted, and you do not have manage roles permission.`, + content: `${emojis.error} <@&${args.role.id}> is not whitelisted, and you do not have manage roles permission.`, allowedMentions: AllowedMentions.none() }); } @@ -157,7 +161,7 @@ export default class RoleCommand extends BushCommand { }); if (!message.member!.roles.cache.some((role) => (allowedRoles as Snowflake[]).includes(role.id))) { return await message.util.reply({ - content: `${util.emojis.error} <@&${args.role.id}> is whitelisted, but you do not have any of the roles required to manage it.`, + content: `${emojis.error} <@&${args.role.id}> is whitelisted, but you do not have any of the roles required to manage it.`, allowedMentions: AllowedMentions.none() }); } @@ -173,33 +177,33 @@ export default class RoleCommand extends BushCommand { }); const responseMessage = (): string => { - const victim = util.format.input(args.member.user.tag); + const victim = format.input(args.member.user.tag); switch (responseCode) { case addRoleResponse.MISSING_PERMISSIONS: - return `${util.emojis.error} I don't have the **Manage Roles** permission.`; + return `${emojis.error} I don't have the **Manage Roles** permission.`; case addRoleResponse.USER_HIERARCHY: - return `${util.emojis.error} <@&${args.role.id}> is higher or equal to your highest role.`; + return `${emojis.error} <@&${args.role.id}> is higher or equal to your highest role.`; case addRoleResponse.ROLE_MANAGED: - return `${util.emojis.error} <@&${args.role.id}> is managed by an integration and cannot be managed.`; + return `${emojis.error} <@&${args.role.id}> is managed by an integration and cannot be managed.`; case addRoleResponse.CLIENT_HIERARCHY: - return `${util.emojis.error} <@&${args.role.id}> is higher or equal to my highest role.`; + return `${emojis.error} <@&${args.role.id}> is higher or equal to my highest role.`; case addRoleResponse.MODLOG_ERROR: - return `${util.emojis.error} There was an error creating a modlog entry, please report this to my developers.`; + return `${emojis.error} There was an error creating a modlog entry, please report this to my developers.`; case addRoleResponse.PUNISHMENT_ENTRY_ADD_ERROR: case removeRoleResponse.PUNISHMENT_ENTRY_REMOVE_ERROR: - return `${util.emojis.error} There was an error ${ + return `${emojis.error} There was an error ${ args.action === 'add' ? 'creating' : 'removing' } a punishment entry, please report this to my developers.`; case addRoleResponse.ACTION_ERROR: - return `${util.emojis.error} An error occurred while trying to ${args.action} <@&${args.role.id}> ${ + return `${emojis.error} An error occurred while trying to ${args.action} <@&${args.role.id}> ${ args.action === 'add' ? 'to' : 'from' } ${victim}.`; case addRoleResponse.SUCCESS: - return `${util.emojis.success} Successfully ${args.action === 'add' ? 'added' : 'removed'} <@&${args.role.id}> ${ + return `${emojis.success} Successfully ${args.action === 'add' ? 'added' : 'removed'} <@&${args.role.id}> ${ args.action === 'add' ? 'to' : 'from' - } ${victim}${args.duration ? ` for ${util.humanizeDuration(args.duration)}` : ''}.`; + } ${victim}${args.duration ? ` for ${humanizeDuration(args.duration)}` : ''}.`; default: - return `${util.emojis.error} An error occurred: ${util.format.input(responseCode)}}`; + return `${emojis.error} An error occurred: ${format.input(responseCode)}}`; } }; diff --git a/src/commands/moderation/slowmode.ts b/src/commands/moderation/slowmode.ts index e657b76..641f88e 100644 --- a/src/commands/moderation/slowmode.ts +++ b/src/commands/moderation/slowmode.ts @@ -1,4 +1,15 @@ -import { BushCommand, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; +import { + Arg, + BushCommand, + clientSendAndPermCheck, + emojis, + format, + humanizeDuration, + userGuildPermCheck, + type CommandMessage, + type OptArgType, + type SlashMessage +} from '#lib'; import assert from 'assert'; import { Argument } from 'discord-akairo'; import { ApplicationCommandOptionType, ChannelType, PermissionFlagsBits } from 'discord.js'; @@ -36,8 +47,8 @@ export default class SlowmodeCommand extends BushCommand { slash: true, channel: 'guild', clientPermissions: (m) => - util.clientSendAndPermCheck(m, [PermissionFlagsBits.ManageChannels, PermissionFlagsBits.EmbedLinks], true), - userPermissions: (m) => util.userGuildPermCheck(m, [PermissionFlagsBits.ManageMessages]) + clientSendAndPermCheck(m, [PermissionFlagsBits.ManageChannels, PermissionFlagsBits.EmbedLinks], true), + userPermissions: (m) => userGuildPermCheck(m, [PermissionFlagsBits.ManageMessages]) }); } @@ -58,11 +69,11 @@ export default class SlowmodeCommand extends BushCommand { 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.`); + return await message.util.reply(`${emojis.error} <#${args.channel.id}> is not a text or thread channel.`); args.length = typeof args.length === 'string' && !(['off', 'none', 'disable'] as const).includes(args.length) - ? await util.arg.cast('duration', message, args.length) + ? await Arg.cast('duration', message, args.length) : args.length; const length2: number = (['off', 'none', 'disable'] as const).includes(args.length) || args.length === null ? 0 : args.length; @@ -71,11 +82,11 @@ export default class SlowmodeCommand extends BushCommand { .setRateLimitPerUser(length2 / 1000, `Changed by ${message.author.tag} (${message.author.id}).`) .catch(() => {}); if (!setSlowmode) - return await message.util.reply(`${util.emojis.error} There was an error changing the slowmode of <#${args.channel.id}>.`); + return await message.util.reply(`${emojis.error} There was an error changing the slowmode of <#${args.channel.id}>.`); else return await message.util.reply( - `${util.emojis.success} Successfully changed the slowmode of <#${args.channel.id}> ${ - length2 ? `to ${util.format.input(util.humanizeDuration(length2))}` : '**off**' + `${emojis.success} Successfully changed the slowmode of <#${args.channel.id}> ${ + length2 ? `to ${format.input(humanizeDuration(length2))}` : '**off**' }.` ); } diff --git a/src/commands/moderation/timeout.ts b/src/commands/moderation/timeout.ts index ed3562d..7be8ecb 100644 --- a/src/commands/moderation/timeout.ts +++ b/src/commands/moderation/timeout.ts @@ -1,6 +1,10 @@ import { AllowedMentions, BushCommand, + castDurationContent, + clientSendAndPermCheck, + emojis, + format, Moderation, timeoutResponse, type ArgType, @@ -49,7 +53,7 @@ export default class TimeoutCommand extends BushCommand { ], slash: true, channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m, [PermissionFlagsBits.ModerateMembers]), + clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.ModerateMembers]), userPermissions: [PermissionFlagsBits.ModerateMembers] }); } @@ -61,12 +65,12 @@ export default class TimeoutCommand extends BushCommand { assert(message.inGuild()); assert(message.member); - const { duration, content } = await util.castDurationContent(args.reason_and_duration, message); + const { duration, content } = await castDurationContent(args.reason_and_duration, message); - if (!duration) return await message.util.reply(`${util.emojis.error} You must specify a duration for timeouts.`); + if (!duration) return await message.util.reply(`${emojis.error} You must specify a duration for timeouts.`); const member = await message.guild.members.fetch(args.user.id).catch(() => null); if (!member) - return await message.util.reply(`${util.emojis.error} The user you selected is not in the server or is not a valid user.`); + return await message.util.reply(`${emojis.error} The user you selected is not in the server or is not a valid user.`); const useForce = args.force && message.author.isOwner(); const canModerateResponse = await Moderation.permissionCheck(message.member, member, 'timeout', true, useForce); @@ -82,22 +86,22 @@ export default class TimeoutCommand extends BushCommand { }); const responseMessage = (): string => { - const victim = util.format.input(member.user.tag); + const victim = format.input(member.user.tag); switch (responseCode) { case timeoutResponse.MISSING_PERMISSIONS: - return `${util.emojis.error} Could not timeout ${victim} because I am missing the **Timeout Members** permission.`; + return `${emojis.error} Could not timeout ${victim} because I am missing the **Timeout Members** permission.`; case timeoutResponse.INVALID_DURATION: - return `${util.emojis.error} The duration you specified is too long, the longest you can timeout someone for is 28 days.`; + return `${emojis.error} The duration you specified is too long, the longest you can timeout someone for is 28 days.`; case timeoutResponse.ACTION_ERROR: - return `${util.emojis.error} An unknown error occurred while trying to timeout ${victim}.`; + return `${emojis.error} An unknown error occurred while trying to timeout ${victim}.`; case timeoutResponse.MODLOG_ERROR: - return `${util.emojis.error} There was an error creating a modlog entry, please report this to my developers.`; + return `${emojis.error} There was an error creating a modlog entry, please report this to my developers.`; case timeoutResponse.DM_ERROR: - return `${util.emojis.warn} Timed out ${victim} however I could not send them a dm.`; + return `${emojis.warn} Timed out ${victim} however I could not send them a dm.`; case timeoutResponse.SUCCESS: - return `${util.emojis.success} Successfully timed out ${victim}.`; + return `${emojis.success} Successfully timed out ${victim}.`; default: - return `${util.emojis.error} An error occurred: ${util.format.input(responseCode)}}`; + return `${emojis.error} An error occurred: ${format.input(responseCode)}}`; } }; return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() }); diff --git a/src/commands/moderation/unban.ts b/src/commands/moderation/unban.ts index d7549ab..a4c4992 100644 --- a/src/commands/moderation/unban.ts +++ b/src/commands/moderation/unban.ts @@ -1,6 +1,9 @@ import { AllowedMentions, + Arg, BushCommand, + emojis, + format, unbanResponse, type ArgType, type CommandMessage, @@ -22,7 +25,7 @@ export default class UnbanCommand extends BushCommand { { id: 'user', description: 'The user to unban.', - type: util.arg.union('user', 'globalUser'), + type: Arg.union('user', 'globalUser'), prompt: 'What user would you like to unban?', retry: '{error} Choose a valid user to unban.', slashType: ApplicationCommandOptionType.User @@ -58,23 +61,23 @@ export default class UnbanCommand extends BushCommand { }); const responseMessage = (): string => { - const victim = util.format.input(user.tag); + const victim = format.input(user.tag); switch (responseCode) { case unbanResponse.MISSING_PERMISSIONS: - return `${util.emojis.error} Could not unban ${victim} because I am missing the **Ban Members** permission.`; + return `${emojis.error} Could not unban ${victim} because I am missing the **Ban Members** permission.`; case unbanResponse.ACTION_ERROR: - return `${util.emojis.error} An error occurred while trying to unban ${victim}.`; + return `${emojis.error} An error occurred while trying to unban ${victim}.`; case unbanResponse.PUNISHMENT_ENTRY_REMOVE_ERROR: - return `${util.emojis.error} While unbanning ${victim}, there was an error removing their ban entry, please report this to my developers.`; + return `${emojis.error} While unbanning ${victim}, there was an error removing their ban entry, please report this to my developers.`; case unbanResponse.MODLOG_ERROR: - return `${util.emojis.error} While unbanning ${victim}, there was an error creating a modlog entry, please report this to my developers.`; + return `${emojis.error} While unbanning ${victim}, there was an error creating a modlog entry, please report this to my developers.`; case unbanResponse.NOT_BANNED: - return `${util.emojis.warn} ${victim} is not banned but I tried to unban them anyways.`; + return `${emojis.warn} ${victim} is not banned but I tried to unban them anyways.`; case unbanResponse.DM_ERROR: case unbanResponse.SUCCESS: - return `${util.emojis.success} Successfully unbanned ${victim}.`; + return `${emojis.success} Successfully unbanned ${victim}.`; default: - return `${util.emojis.error} An error occurred: ${util.format.input(responseCode)}}`; + return `${emojis.error} An error occurred: ${format.input(responseCode)}}`; } }; return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() }); diff --git a/src/commands/moderation/unblock.ts b/src/commands/moderation/unblock.ts index 886d546..09ec281 100644 --- a/src/commands/moderation/unblock.ts +++ b/src/commands/moderation/unblock.ts @@ -1,8 +1,12 @@ import { AllowedMentions, BushCommand, + clientSendAndPermCheck, + emojis, + format, Moderation, unblockResponse, + userGuildPermCheck, type ArgType, type CommandMessage, type OptArgType, @@ -51,8 +55,8 @@ export default class UnblockCommand extends BushCommand { ], slash: true, channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m, [PermissionFlagsBits.ManageChannels]), - userPermissions: (m) => util.userGuildPermCheck(m, [PermissionFlagsBits.ManageMessages]) + clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.ManageChannels]), + userPermissions: (m) => userGuildPermCheck(m, [PermissionFlagsBits.ManageMessages]) }); } @@ -65,11 +69,11 @@ export default class UnblockCommand extends BushCommand { assert(message.channel); if (!message.channel.isTextBased()) - return message.util.send(`${util.emojis.error} This command can only be used in text based channels.`); + return message.util.send(`${emojis.error} This command can only be used in text based channels.`); const member = await message.guild.members.fetch(args.user.id).catch(() => null); if (!member) - return await message.util.reply(`${util.emojis.error} The user you selected is not in the server or is not a valid user.`); + return await message.util.reply(`${emojis.error} The user you selected is not in the server or is not a valid user.`); const useForce = args.force && message.author.isOwner(); const canModerateResponse = await Moderation.permissionCheck(message.member, member, 'unblock', true, useForce); @@ -85,24 +89,24 @@ export default class UnblockCommand extends BushCommand { }); const responseMessage = (): string => { - const victim = util.format.input(member.user.tag); + const victim = format.input(member.user.tag); switch (responseCode) { case unblockResponse.MISSING_PERMISSIONS: - return `${util.emojis.error} Could not unblock ${victim} because I am missing the **Manage Channel** permission.`; + return `${emojis.error} Could not unblock ${victim} because I am missing the **Manage Channel** permission.`; case unblockResponse.INVALID_CHANNEL: - return `${util.emojis.error} Could not unblock ${victim}, you can only unblock users in text or thread channels.`; + return `${emojis.error} Could not unblock ${victim}, you can only unblock users in text or thread channels.`; case unblockResponse.ACTION_ERROR: - return `${util.emojis.error} An unknown error occurred while trying to unblock ${victim}.`; + return `${emojis.error} An unknown error occurred while trying to unblock ${victim}.`; case unblockResponse.MODLOG_ERROR: - return `${util.emojis.error} There was an error creating a modlog entry, please report this to my developers.`; + return `${emojis.error} There was an error creating a modlog entry, please report this to my developers.`; case unblockResponse.PUNISHMENT_ENTRY_REMOVE_ERROR: - return `${util.emojis.error} There was an error creating a punishment entry, please report this to my developers.`; + return `${emojis.error} There was an error creating a punishment entry, please report this to my developers.`; case unblockResponse.DM_ERROR: - return `${util.emojis.warn} Unblocked ${victim} however I could not send them a dm.`; + return `${emojis.warn} Unblocked ${victim} however I could not send them a dm.`; case unblockResponse.SUCCESS: - return `${util.emojis.success} Successfully unblocked ${victim}.`; + return `${emojis.success} Successfully unblocked ${victim}.`; default: - return `${util.emojis.error} An error occurred: ${util.format.input(responseCode)}}`; + return `${emojis.error} An error occurred: ${format.input(responseCode)}}`; } }; return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() }); diff --git a/src/commands/moderation/unlockdown.ts b/src/commands/moderation/unlockdown.ts index dbcd429..db1a09d 100644 --- a/src/commands/moderation/unlockdown.ts +++ b/src/commands/moderation/unlockdown.ts @@ -1,5 +1,13 @@ import { LockdownCommand } from '#commands'; -import { BushCommand, type ArgType, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; +import { + Arg, + BushCommand, + clientSendAndPermCheck, + 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 +22,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', 'voiceChannel'), + type: Arg.union('textChannel', 'newsChannel', 'threadChannel', 'voiceChannel'), prompt: 'What channel would you like to unlockdown?', slashType: ApplicationCommandOptionType.Channel, channelTypes: [ @@ -48,7 +56,7 @@ export default class UnlockdownCommand extends BushCommand { ], slash: true, channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m, [PermissionFlagsBits.ManageChannels]), + clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.ManageChannels]), userPermissions: [PermissionFlagsBits.ManageChannels] }); } diff --git a/src/commands/moderation/unmute.ts b/src/commands/moderation/unmute.ts index 202e341..9ac13ce 100644 --- a/src/commands/moderation/unmute.ts +++ b/src/commands/moderation/unmute.ts @@ -1,8 +1,13 @@ import { AllowedMentions, BushCommand, + clientSendAndPermCheck, + emojis, + format, Moderation, + prefix, unmuteResponse, + userGuildPermCheck, type ArgType, type CommandMessage, type OptArgType, @@ -51,8 +56,8 @@ export default class UnmuteCommand extends BushCommand { ], slash: true, channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m, [PermissionFlagsBits.ManageRoles]), - userPermissions: (m) => util.userGuildPermCheck(m, [PermissionFlagsBits.ManageMessages]) + clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.ManageRoles]), + userPermissions: (m) => userGuildPermCheck(m, [PermissionFlagsBits.ManageMessages]) }); } @@ -63,7 +68,7 @@ export default class UnmuteCommand extends BushCommand { assert(message.inGuild()); assert(message.member); - const error = util.emojis.error; + const error = emojis.error; const member = message.guild.members.cache.get(user.id)!; const useForce = force && message.author.isOwner(); @@ -79,17 +84,17 @@ export default class UnmuteCommand extends BushCommand { }); const responseMessage = (): string => { - const prefix = util.prefix(message); - const victim = util.format.input(member.user.tag); + const prefix_ = prefix(message); + const victim = format.input(member.user.tag); switch (responseCode) { case unmuteResponse.MISSING_PERMISSIONS: return `${error} Could not unmute ${victim} because I am missing the **Manage Roles** permission.`; case unmuteResponse.NO_MUTE_ROLE: - return `${error} Could not unmute ${victim}, you must set a mute role with \`${prefix}config muteRole\`.`; + return `${error} Could not unmute ${victim}, you must set a mute role with \`${prefix_}config muteRole\`.`; case unmuteResponse.MUTE_ROLE_INVALID: - return `${error} Could not unmute ${victim} because the current mute role no longer exists. Please set a new mute role with \`${prefix}config muteRole\`.`; + return `${error} Could not unmute ${victim} because the current mute role no longer exists. Please set a new mute role with \`${prefix_}config muteRole\`.`; case unmuteResponse.MUTE_ROLE_NOT_MANAGEABLE: - return `${error} Could not unmute ${victim} because I cannot assign the current mute role, either change the role's position or set a new mute role with \`${prefix}config muteRole\`.`; + return `${error} Could not unmute ${victim} because I cannot assign the current mute role, either change the role's position or set a new mute role with \`${prefix_}config muteRole\`.`; case unmuteResponse.ACTION_ERROR: return `${error} Could not unmute ${victim}, there was an error removing their mute role.`; case unmuteResponse.MODLOG_ERROR: @@ -97,11 +102,11 @@ export default class UnmuteCommand extends BushCommand { case unmuteResponse.PUNISHMENT_ENTRY_REMOVE_ERROR: return `${error} While muting ${victim}, there was an error removing their mute entry, please report this to my developers.`; case unmuteResponse.DM_ERROR: - return `${util.emojis.warn} unmuted ${victim} however I could not send them a dm.`; + return `${emojis.warn} unmuted ${victim} however I could not send them a dm.`; case unmuteResponse.SUCCESS: - return `${util.emojis.success} Successfully unmuted ${victim}.`; + return `${emojis.success} Successfully unmuted ${victim}.`; default: - return `${util.emojis.error} An error occurred: ${util.format.input(responseCode)}}`; + return `${emojis.error} An error occurred: ${format.input(responseCode)}}`; } }; return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() }); diff --git a/src/commands/moderation/untimeout.ts b/src/commands/moderation/untimeout.ts index 7622f29..c6860c5 100644 --- a/src/commands/moderation/untimeout.ts +++ b/src/commands/moderation/untimeout.ts @@ -1,6 +1,9 @@ import { AllowedMentions, BushCommand, + clientSendAndPermCheck, + emojis, + format, Moderation, removeTimeoutResponse, type ArgType, @@ -51,7 +54,7 @@ export default class UntimeoutCommand extends BushCommand { ], slash: true, channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m, [PermissionFlagsBits.ModerateMembers]), + clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.ModerateMembers]), userPermissions: [PermissionFlagsBits.ModerateMembers] }); } @@ -65,9 +68,9 @@ export default class UntimeoutCommand extends BushCommand { const member = await message.guild.members.fetch(args.user.id).catch(() => null); if (!member) - return await message.util.reply(`${util.emojis.error} The user you selected is not in the server or is not a valid user.`); + return await message.util.reply(`${emojis.error} The user you selected is not in the server or is not a valid user.`); - if (!member.isCommunicationDisabled()) return message.util.reply(`${util.emojis.error} That user is not timed out.`); + if (!member.isCommunicationDisabled()) return message.util.reply(`${emojis.error} That user is not timed out.`); const useForce = args.force && message.author.isOwner(); const canModerateResponse = await Moderation.permissionCheck(message.member, member, 'timeout', true, useForce); @@ -82,20 +85,20 @@ export default class UntimeoutCommand extends BushCommand { }); const responseMessage = (): string => { - const victim = util.format.input(member.user.tag); + const victim = format.input(member.user.tag); switch (responseCode) { case removeTimeoutResponse.MISSING_PERMISSIONS: - return `${util.emojis.error} Could not untimeout ${victim} because I am missing the **Timeout Members** permission.`; + return `${emojis.error} Could not untimeout ${victim} because I am missing the **Timeout Members** permission.`; case removeTimeoutResponse.ACTION_ERROR: - return `${util.emojis.error} An unknown error occurred while trying to timeout ${victim}.`; + return `${emojis.error} An unknown error occurred while trying to timeout ${victim}.`; case removeTimeoutResponse.MODLOG_ERROR: - return `${util.emojis.error} There was an error creating a modlog entry, please report this to my developers.`; + return `${emojis.error} There was an error creating a modlog entry, please report this to my developers.`; case removeTimeoutResponse.DM_ERROR: - return `${util.emojis.warn} Removed ${victim}'s timeout however I could not send them a dm.`; + return `${emojis.warn} Removed ${victim}'s timeout however I could not send them a dm.`; case removeTimeoutResponse.SUCCESS: - return `${util.emojis.success} Successfully removed ${victim}'s timeout.`; + return `${emojis.success} Successfully removed ${victim}'s timeout.`; default: - return `${util.emojis.error} An error occurred: ${util.format.input(responseCode)}}`; + return `${emojis.error} An error occurred: ${format.input(responseCode)}}`; } }; return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() }); diff --git a/src/commands/moderation/warn.ts b/src/commands/moderation/warn.ts index b3bf965..81b2937 100644 --- a/src/commands/moderation/warn.ts +++ b/src/commands/moderation/warn.ts @@ -1,7 +1,12 @@ import { AllowedMentions, BushCommand, + clientSendAndPermCheck, + emojis, + format, Moderation, + ordinal, + userGuildPermCheck, warnResponse, type ArgType, type CommandMessage, @@ -50,8 +55,8 @@ export default class WarnCommand extends BushCommand { ], slash: true, channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m), - userPermissions: (m) => util.userGuildPermCheck(m, [PermissionFlagsBits.ManageMessages]) + clientPermissions: (m) => clientSendAndPermCheck(m), + userPermissions: (m) => userGuildPermCheck(m, [PermissionFlagsBits.ManageMessages]) }); } @@ -63,7 +68,7 @@ export default class WarnCommand extends BushCommand { assert(message.member); const member = message.guild.members.cache.get(user.id); - if (!member) return message.util.reply(`${util.emojis.error} I cannot warn users that are not in the server.`); + if (!member) return message.util.reply(`${emojis.error} I cannot warn users that are not in the server.`); const useForce = force && message.author.isOwner(); const canModerateResponse = await Moderation.permissionCheck(message.member, member, 'warn', true, useForce); @@ -77,19 +82,19 @@ export default class WarnCommand extends BushCommand { }); const responseMessage = (): string => { - const victim = util.format.input(member.user.tag); + const victim = format.input(member.user.tag); switch (response) { case warnResponse.MODLOG_ERROR: - return `${util.emojis.error} While warning ${victim}, there was an error creating a modlog entry, please report this to my developers.`; + return `${emojis.error} While warning ${victim}, there was an error creating a modlog entry, please report this to my developers.`; case warnResponse.ACTION_ERROR: case warnResponse.DM_ERROR: - return `${util.emojis.warn} ${victim} has been warned for the ${util.ordinal( + return `${emojis.warn} ${victim} has been warned for the ${ordinal( caseNum ?? 0 )} time, however I could not send them a dm.`; case warnResponse.SUCCESS: - return `${util.emojis.success} Successfully warned ${victim} for the ${util.ordinal(caseNum ?? 0)} time.`; + return `${emojis.success} Successfully warned ${victim} for the ${ordinal(caseNum ?? 0)} time.`; default: - return `${util.emojis.error} An error occurred: ${util.format.input(response)}}`; + return `${emojis.error} An error occurred: ${format.input(response)}}`; } }; return await message.util.reply({ content: responseMessage(), allowedMentions: AllowedMentions.none() }); |