diff options
Diffstat (limited to 'src/commands/utilities')
22 files changed, 260 insertions, 155 deletions
diff --git a/src/commands/utilities/_poll.ts b/src/commands/utilities/_poll.ts index a843561..fdf6381 100644 --- a/src/commands/utilities/_poll.ts +++ b/src/commands/utilities/_poll.ts @@ -29,7 +29,7 @@ // } // ], // slash: true, -// clientPermissions: (m) => util.clientSendAndPermCheck(m), +// clientPermissions: (m) => clientSendAndPermCheck(m), // userPermissions: [] // }); // } @@ -38,8 +38,8 @@ // const { question, options } = this.parseArgs(message, args); // if (!question || !options.length) return; -// if (question.length > 256) return await message.util.reply(`${util.emojis.error} Question must be 256 characters or less.`); -// if (options.length > 10) return await message.util.reply(`${util.emojis.error} You can only have upto 10 options.`); +// if (question.length > 256) return await message.util.reply(`${emojis.error} Question must be 256 characters or less.`); +// if (options.length > 10) return await message.util.reply(`${emojis.error} You can only have upto 10 options.`); // return message.util.send({ // embeds: [ @@ -64,13 +64,13 @@ // const split = args.options.split(/[,|]/).filter((s) => s.trim().length > 0); // if (message.util.isSlash) { // if (split.length < 2) { -// void message.util.reply(`${util.emojis.error} You must provide at least two options.`); +// void message.util.reply(`${emojis.error} You must provide at least two options.`); // return { question: '', options: [] }; // } // return { question: args.question!, options: split }; // } else { // if (split.length < 3) { -// void message.util.reply(`${util.emojis.error} You must provide a question and at least two options.`); +// void message.util.reply(`${emojis.error} You must provide a question and at least two options.`); // return { question: '', options: [] }; // } diff --git a/src/commands/utilities/activity.ts b/src/commands/utilities/activity.ts index 14cc5a0..dfbccfb 100644 --- a/src/commands/utilities/activity.ts +++ b/src/commands/utilities/activity.ts @@ -1,4 +1,13 @@ -import { BushCommand, type ArgType, type BushArgumentTypeCaster, type CommandMessage, type SlashMessage } from '#lib'; +import { + BushCommand, + clientSendAndPermCheck, + emojis, + regex, + type ArgType, + type BushArgumentTypeCaster, + type CommandMessage, + type SlashMessage +} from '#lib'; import { type ArgumentGeneratorReturn, type ArgumentTypeCaster } from 'discord-akairo'; import { ApplicationCommandOptionType, ChannelType, type DiscordAPIError, type Snowflake } from 'discord.js'; @@ -55,7 +64,7 @@ interface Activity { } function map(phase: string): Activity | null { - if (client.consts.regex.snowflake.test(phase)) return { id: phase, aliases: [] }; + if (regex.snowflake.test(phase)) return { id: phase, aliases: [] }; else if (phase in activityMap) return activityMap[phase as keyof typeof activityMap]; for (const activity in activityMap) { @@ -115,7 +124,7 @@ export default class ActivityCommand extends BushCommand { } ], slash: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [] }); } @@ -155,8 +164,7 @@ export default class ActivityCommand extends BushCommand { args: { channel: ArgType<'voiceChannel'>; activity: string } ) { const channel = typeof args.channel === 'string' ? message.guild?.channels.cache.get(args.channel) : args.channel; - if (channel?.type !== ChannelType.GuildVoice) - return await message.util.reply(`${util.emojis.error} Choose a valid voice channel`); + if (channel?.type !== ChannelType.GuildVoice) return await message.util.reply(`${emojis.error} Choose a valid voice channel`); const target_application_id = message.util.isSlashMessage(message) ? args.activity @@ -177,14 +185,12 @@ export default class ActivityCommand extends BushCommand { .catch((e: Error | DiscordAPIError) => { if ((e as DiscordAPIError)?.code === 50013) { - response = `${util.emojis.error} I am missing permissions to make an invite in that channel.`; + response = `${emojis.error} I am missing permissions to make an invite in that channel.`; return; - } else response = `${util.emojis.error} An error occurred while generating your invite: ${e?.message ?? e}`; + } else response = `${emojis.error} An error occurred while generating your invite: ${e?.message ?? e}`; }); if (response! || !invite || !invite.code) - return await message.util.reply( - response! ?? `${util.emojis.error} An unknown error occurred while generating your invite.` - ); + return await message.util.reply(response! ?? `${emojis.error} An unknown error occurred while generating your invite.`); else return await message.util.send(`https://discord.gg/${invite.code}`); } } diff --git a/src/commands/utilities/calculator.ts b/src/commands/utilities/calculator.ts index a318a79..75d63a1 100644 --- a/src/commands/utilities/calculator.ts +++ b/src/commands/utilities/calculator.ts @@ -1,4 +1,13 @@ -import { AllowedMentions, BushCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { + AllowedMentions, + BushCommand, + clientSendAndPermCheck, + colors, + emojis, + inspectCleanRedactCodeblock, + type CommandMessage, + type SlashMessage +} from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, EmbedBuilder } from 'discord.js'; import { evaluate } from 'mathjs'; @@ -25,7 +34,7 @@ export default class CalculatorCommand extends BushCommand { } ], slash: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [] }); } @@ -34,22 +43,20 @@ export default class CalculatorCommand extends BushCommand { const decodedEmbed = new EmbedBuilder().addFields([ { name: '📥 Input', - value: await util.inspectCleanRedactCodeblock(args.expression, 'mma') + value: await inspectCleanRedactCodeblock(args.expression, 'mma') } ]); try { const calculated = /^(9\s*?\+\s*?10)|(10\s*?\+\s*?9)$/.test(args.expression) ? '21' : evaluate(args.expression); decodedEmbed - .setTitle(`${util.emojis.successFull} Successfully Calculated Expression`) - .setColor(util.colors.success) - .addFields([{ name: '📤 Output', value: await util.inspectCleanRedactCodeblock(calculated.toString(), 'mma') }]); + .setTitle(`${emojis.successFull} Successfully Calculated Expression`) + .setColor(colors.success) + .addFields([{ name: '📤 Output', value: await inspectCleanRedactCodeblock(calculated.toString(), 'mma') }]); } catch (error) { decodedEmbed - .setTitle(`${util.emojis.errorFull} Unable to Calculate Expression`) - .setColor(util.colors.error) - .addFields([ - { name: `📤 Error`, value: await util.inspectCleanRedactCodeblock(`${error.name}: ${error.message}`, 'js') } - ]); + .setTitle(`${emojis.errorFull} Unable to Calculate Expression`) + .setColor(colors.error) + .addFields([{ name: `📤 Error`, value: await inspectCleanRedactCodeblock(`${error.name}: ${error.message}`, 'js') }]); } return await message.util.reply({ embeds: [decodedEmbed], allowedMentions: AllowedMentions.none() }); } diff --git a/src/commands/utilities/decode.ts b/src/commands/utilities/decode.ts index 8c82fcc..cc742c8 100644 --- a/src/commands/utilities/decode.ts +++ b/src/commands/utilities/decode.ts @@ -1,4 +1,14 @@ -import { AllowedMentions, BushCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { + AllowedMentions, + BushCommand, + capitalize, + clientSendAndPermCheck, + colors, + formatError, + inspectCleanRedactCodeblock, + type CommandMessage, + type SlashMessage +} from '#lib'; import { ApplicationCommandOptionType, EmbedBuilder } from 'discord.js'; const encodingTypesArray = ['ascii', 'utf8', 'utf-8', 'utf16le', 'ucs2', 'ucs-2', 'base64', 'latin1', 'binary', 'hex']; @@ -42,7 +52,7 @@ export default class DecodeCommand extends BushCommand { } ], slash: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [] }); } @@ -51,20 +61,18 @@ export default class DecodeCommand extends BushCommand { message: CommandMessage | SlashMessage, { from, to, data }: { from: BufferEncoding; to: BufferEncoding; data: string } ) { - const encodeOrDecode = util.capitalizeFirstLetter(message?.util?.parsed?.alias ?? 'decoded'); + const encodeOrDecode = capitalize(message?.util?.parsed?.alias ?? 'decoded'); const decodedEmbed = new EmbedBuilder() .setTitle(`${encodeOrDecode} Information`) - .addFields([{ name: '📥 Input', value: await util.inspectCleanRedactCodeblock(data) }]); + .addFields([{ name: '📥 Input', value: await inspectCleanRedactCodeblock(data) }]); try { const decoded = Buffer.from(data, from).toString(to); - decodedEmbed - .setColor(util.colors.success) - .addFields([{ name: '📤 Output', value: await util.inspectCleanRedactCodeblock(decoded) }]); + decodedEmbed.setColor(colors.success).addFields([{ name: '📤 Output', value: await inspectCleanRedactCodeblock(decoded) }]); } catch (error) { - decodedEmbed.setColor(util.colors.error).addFields([ + decodedEmbed.setColor(colors.error).addFields([ { name: `📤 Error ${encodeOrDecode.slice(1)}ing`, - value: await util.inspectCleanRedactCodeblock(util.formatError(error)) + value: await inspectCleanRedactCodeblock(formatError(error)) } ]); } diff --git a/src/commands/utilities/hash.ts b/src/commands/utilities/hash.ts index f47c388..6e8c37f 100644 --- a/src/commands/utilities/hash.ts +++ b/src/commands/utilities/hash.ts @@ -1,4 +1,4 @@ -import { BushCommand, type CommandMessage } from '#lib'; +import { BushCommand, clientSendAndPermCheck, type CommandMessage } from '#lib'; import assert from 'assert'; import crypto from 'crypto'; import { ApplicationCommandOptionType } from 'discord.js'; @@ -25,7 +25,7 @@ export default class HashCommand extends BushCommand { slashType: ApplicationCommandOptionType.String } ], - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [] }); } diff --git a/src/commands/utilities/highlight-!.ts b/src/commands/utilities/highlight-!.ts index 6dca545..6847737 100644 --- a/src/commands/utilities/highlight-!.ts +++ b/src/commands/utilities/highlight-!.ts @@ -1,4 +1,4 @@ -import { BushCommand, Highlight, HighlightWord, type SlashMessage } from '#lib'; +import { BushCommand, clientSendAndPermCheck, Highlight, HighlightWord, type SlashMessage } from '#lib'; import { Flag, type ArgumentGeneratorReturn, type SlashOption } from 'discord-akairo'; import { ApplicationCommandOptionType, @@ -123,7 +123,7 @@ export default class HighlightCommand extends BushCommand { }), slash: true, channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [] }); } diff --git a/src/commands/utilities/highlight-add.ts b/src/commands/utilities/highlight-add.ts index 726b887..9624a7e 100644 --- a/src/commands/utilities/highlight-add.ts +++ b/src/commands/utilities/highlight-add.ts @@ -1,4 +1,4 @@ -import { AllowedMentions, BushCommand, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; +import { AllowedMentions, BushCommand, emojis, format, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; import { highlightCommandArgs, highlightSubcommands } from './highlight-!.js'; @@ -44,16 +44,16 @@ export default class HighlightAddCommand extends BushCommand { if (!args.regex) { if (args.word.length < 2) - return message.util.send(`${util.emojis.error} You can only highlight words that are longer than 2 characters.`); + return message.util.send(`${emojis.error} You can only highlight words that are longer than 2 characters.`); if (args.word.length > 50) - return await message.util.reply(`${util.emojis.error} You can only highlight words that are shorter than 50 characters.`); + return await message.util.reply(`${emojis.error} You can only highlight words that are shorter than 50 characters.`); } else { try { new RegExp(args.word); } catch (e) { assert(e instanceof SyntaxError); return message.util.send({ - content: `${util.emojis.error} Invalid regex ${util.format.inlineCode(e.message)}.`, + content: `${emojis.error} Invalid regex ${format.inlineCode(e.message)}.`, allowedMentions: AllowedMentions.none() }); } @@ -65,15 +65,15 @@ export default class HighlightAddCommand extends BushCommand { }); if (typeof res === 'string') - return await message.util.reply({ content: `${util.emojis.error} ${res}`, allowedMentions: AllowedMentions.none() }); + return await message.util.reply({ content: `${emojis.error} ${res}`, allowedMentions: AllowedMentions.none() }); else if (!res) return await message.util.reply({ - content: `${util.emojis.error} There was an error highlighting "${args.word}".`, + content: `${emojis.error} There was an error highlighting "${args.word}".`, allowedMentions: AllowedMentions.none() }); return await message.util.reply({ - content: `${util.emojis.success} Successfully added "${args.word}" to your highlight list.`, + content: `${emojis.success} Successfully added "${args.word}" to your highlight list.`, allowedMentions: AllowedMentions.none() }); } diff --git a/src/commands/utilities/highlight-block.ts b/src/commands/utilities/highlight-block.ts index 61e1254..5429071 100644 --- a/src/commands/utilities/highlight-block.ts +++ b/src/commands/utilities/highlight-block.ts @@ -1,4 +1,14 @@ -import { AllowedMentions, BushCommand, Highlight, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; +import { + addToArray, + AllowedMentions, + Arg, + BushCommand, + emojis, + Highlight, + type ArgType, + type CommandMessage, + type SlashMessage +} from '#lib'; import assert from 'assert'; import { Argument, ArgumentGeneratorReturn } from 'discord-akairo'; import { Channel, GuildMember } from 'discord.js'; @@ -35,15 +45,13 @@ export default class HighlightBlockCommand extends BushCommand { assert(message.inGuild()); args.target = - typeof args.target === 'string' - ? (await util.arg.cast(util.arg.union('member', 'channel'), message, args.target))! - : args.target; + typeof args.target === 'string' ? (await Arg.cast(Arg.union('member', 'channel'), message, args.target))! : args.target; if (!args.target || !(args.target instanceof GuildMember || args.target instanceof Channel)) - return await message.util.reply(`${util.emojis.error} You can only block users or channels.`); + return await message.util.reply(`${emojis.error} You can only block users or channels.`); if (args.target instanceof Channel && !args.target.isTextBased()) - return await message.util.reply(`${util.emojis.error} You can only block text-based channels.`); + return await message.util.reply(`${emojis.error} You can only block text-based channels.`); const [highlight] = await Highlight.findOrCreate({ where: { guild: message.guild.id, user: message.author.id } @@ -54,16 +62,16 @@ export default class HighlightBlockCommand extends BushCommand { if (highlight[key].includes(args.target.id)) return await message.util.reply({ // eslint-disable-next-line @typescript-eslint/no-base-to-string - content: `${util.emojis.error} You have already blocked ${args.target}.`, + content: `${emojis.error} You have already blocked ${args.target}.`, allowedMentions: AllowedMentions.none() }); - highlight[key] = util.addToArray(highlight[key], args.target.id); + highlight[key] = addToArray(highlight[key], args.target.id); await highlight.save(); return await message.util.reply({ // eslint-disable-next-line @typescript-eslint/no-base-to-string - content: `${util.emojis.success} Successfully blocked ${args.target} from triggering your highlights.`, + content: `${emojis.success} Successfully blocked ${args.target} from triggering your highlights.`, allowedMentions: AllowedMentions.none() }); } diff --git a/src/commands/utilities/highlight-clear.ts b/src/commands/utilities/highlight-clear.ts index b905f3b..df9f387 100644 --- a/src/commands/utilities/highlight-clear.ts +++ b/src/commands/utilities/highlight-clear.ts @@ -1,4 +1,4 @@ -import { BushCommand, ConfirmationPrompt, type CommandMessage, type SlashMessage } from '#lib'; +import { BushCommand, ConfirmationPrompt, emojis, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; import { highlightSubcommands } from './highlight-!.js'; @@ -21,11 +21,11 @@ export default class HighlightClearCommand extends BushCommand { if (message.util.isSlashMessage(message)) await message.interaction.deferReply(); const confirm = await ConfirmationPrompt.send(message, { content: `Are you sure you want to clear your highlight list?` }); - if (!confirm) return await message.util.reply(`${util.emojis.warn} You decided not to clear your highlight list.`); + if (!confirm) return await message.util.reply(`${emojis.warn} You decided not to clear your highlight list.`); const success = await client.highlightManager.removeAllHighlights(message.guild.id, message.author.id); - if (!success) return await message.util.reply(`${util.emojis.error} There was an error clearing your highlight list.`); + if (!success) return await message.util.reply(`${emojis.error} There was an error clearing your highlight list.`); - return await message.util.reply(`${util.emojis.success} Successfully cleared your highlight list.`); + return await message.util.reply(`${emojis.success} Successfully cleared your highlight list.`); } } diff --git a/src/commands/utilities/highlight-matches.ts b/src/commands/utilities/highlight-matches.ts index 40020cd..b458550 100644 --- a/src/commands/utilities/highlight-matches.ts +++ b/src/commands/utilities/highlight-matches.ts @@ -1,4 +1,4 @@ -import { BushCommand, ButtonPaginator, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; +import { BushCommand, ButtonPaginator, chunk, colors, emojis, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; import { type ArgumentGeneratorReturn } from 'discord-akairo'; import { type APIEmbed } from 'discord.js'; @@ -36,18 +36,16 @@ export default class HighlightMatchesCommand extends BushCommand { const res = await client.highlightManager.checkPhrase(message.guild.id, message.author.id, args.phrase); - if (!res.size) return await message.util.reply(`${util.emojis.error} You are not highlighting any words`); + if (!res.size) return await message.util.reply(`${emojis.error} You are not highlighting any words`); - const lines = res.map( - (passed, hl) => `${passed ? util.emojis.check : util.emojis.cross} ${hl.regex ? `/${hl.word}/gi` : hl.word}` - ); - const chunked = util.chunk(lines, 10); + const lines = res.map((passed, hl) => `${passed ? emojis.check : emojis.cross} ${hl.regex ? `/${hl.word}/gi` : hl.word}`); + const chunked = chunk(lines, 10); const pages = chunked.map( (chunk): APIEmbed => ({ title: `Matches`, description: chunk.join('\n'), - color: util.colors.default + color: colors.default }) ); diff --git a/src/commands/utilities/highlight-remove.ts b/src/commands/utilities/highlight-remove.ts index a2f2367..bb1300a 100644 --- a/src/commands/utilities/highlight-remove.ts +++ b/src/commands/utilities/highlight-remove.ts @@ -1,4 +1,4 @@ -import { AllowedMentions, BushCommand, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; +import { AllowedMentions, BushCommand, emojis, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; import { highlightCommandArgs, highlightSubcommands } from './highlight-!.js'; @@ -34,15 +34,15 @@ export default class HighlightRemoveCommand extends BushCommand { const res = await client.highlightManager.removeHighlight(message.guild.id, message.author.id, args.word); if (typeof res === 'string') - return await message.util.reply({ content: `${util.emojis.error} ${res}`, allowedMentions: AllowedMentions.none() }); + return await message.util.reply({ content: `${emojis.error} ${res}`, allowedMentions: AllowedMentions.none() }); else if (!res) return await message.util.reply({ - content: `${util.emojis.error} There was an error unhighlighting "${args.word}".`, + content: `${emojis.error} There was an error unhighlighting "${args.word}".`, allowedMentions: AllowedMentions.none() }); return await message.util.reply({ - content: `${util.emojis.success} Successfully removed "${args.word}" from your highlight list.`, + content: `${emojis.success} Successfully removed "${args.word}" from your highlight list.`, allowedMentions: AllowedMentions.none() }); } diff --git a/src/commands/utilities/highlight-show.ts b/src/commands/utilities/highlight-show.ts index 80ba4ca..d966f3a 100644 --- a/src/commands/utilities/highlight-show.ts +++ b/src/commands/utilities/highlight-show.ts @@ -1,4 +1,4 @@ -import { AllowedMentions, BushCommand, Highlight, type CommandMessage, type SlashMessage } from '#lib'; +import { AllowedMentions, BushCommand, colors, emojis, Highlight, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; import { EmbedBuilder } from 'discord.js'; import { highlightSubcommands } from './highlight-!.js'; @@ -25,7 +25,7 @@ export default class HighlightShowCommand extends BushCommand { void client.highlightManager.syncCache(); - if (!highlight.words.length) return message.util.reply(`${util.emojis.error} You are not highlighting any words.`); + if (!highlight.words.length) return message.util.reply(`${emojis.error} You are not highlighting any words.`); const embed = new EmbedBuilder() .setTitle('Highlight List') @@ -35,7 +35,7 @@ export default class HighlightShowCommand extends BushCommand { .join('\n') .substring(0, 4096) ) - .setColor(util.colors.default); + .setColor(colors.default); if (highlight.blacklistedChannels.length) embed.addFields([ diff --git a/src/commands/utilities/highlight-unblock.ts b/src/commands/utilities/highlight-unblock.ts index b738ee9..7f416eb 100644 --- a/src/commands/utilities/highlight-unblock.ts +++ b/src/commands/utilities/highlight-unblock.ts @@ -1,4 +1,13 @@ -import { AllowedMentions, BushCommand, Highlight, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; +import { + AllowedMentions, + BushCommand, + emojis, + Highlight, + removeFromArray, + type ArgType, + type CommandMessage, + type SlashMessage +} from '#lib'; import assert from 'assert'; import { Argument, ArgumentGeneratorReturn } from 'discord-akairo'; import { Channel, GuildMember } from 'discord.js'; @@ -35,10 +44,10 @@ export default class HighlightUnblockCommand extends BushCommand { assert(message.inGuild()); if (!(args.target instanceof GuildMember || args.target instanceof Channel)) - return await message.util.reply(`${util.emojis.error} You can only unblock users or channels.`); + return await message.util.reply(`${emojis.error} You can only unblock users or channels.`); if (args.target instanceof Channel && !args.target.isTextBased()) - return await message.util.reply(`${util.emojis.error} You can only unblock text-based channels.`); + return await message.util.reply(`${emojis.error} You can only unblock text-based channels.`); const [highlight] = await Highlight.findOrCreate({ where: { guild: message.guild.id, user: message.author.id } @@ -48,15 +57,15 @@ export default class HighlightUnblockCommand extends BushCommand { if (!highlight[key].includes(args.target.id)) return await message.util.reply({ - content: `${util.emojis.error} ${args.target} is not blocked so cannot be unblock.`, + content: `${emojis.error} ${args.target} is not blocked so cannot be unblock.`, allowedMentions: AllowedMentions.none() }); - highlight[key] = util.removeFromArray(highlight[key], args.target.id); + highlight[key] = removeFromArray(highlight[key], args.target.id); await highlight.save(); return await message.util.reply({ - content: `${util.emojis.success} Successfully allowed ${args.target} to trigger your highlights.`, + content: `${emojis.success} Successfully allowed ${args.target} to trigger your highlights.`, allowedMentions: AllowedMentions.none() }); } diff --git a/src/commands/utilities/price.ts b/src/commands/utilities/price.ts index a4f4c03..c569437 100644 --- a/src/commands/utilities/price.ts +++ b/src/commands/utilities/price.ts @@ -1,4 +1,4 @@ -import { ArgType, BushCommand, type CommandMessage } from '#lib'; +import { ArgType, BushCommand, clientSendAndPermCheck, colors, emojis, format, oxford, type CommandMessage } from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, AutocompleteInteraction, EmbedBuilder, PermissionFlagsBits } from 'discord.js'; import Fuse from 'fuse.js'; @@ -39,7 +39,7 @@ export default class PriceCommand extends BushCommand { } ], slash: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true), + clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true), userPermissions: [], typing: true }); @@ -58,12 +58,12 @@ export default class PriceCommand extends BushCommand { ])) as [Bazaar | undefined, LowestBIN | undefined, LowestBIN | undefined, AuctionAverages | undefined]; let parsedItem = args.item.toString().toUpperCase().replace(/ /g, '_').replace(/'S/g, ''); - const priceEmbed = new EmbedBuilder().setColor(errors?.length ? util.colors.warn : util.colors.success).setTimestamp(); + const priceEmbed = new EmbedBuilder().setColor(errors?.length ? colors.warn : colors.success).setTimestamp(); if (bazaar?.success === false) errors.push('bazaar'); if (errors.length) { - priceEmbed.setFooter({ text: `Could not fetch data for ${util.oxford(errors, 'and')}` }); + priceEmbed.setFooter({ text: `Could not fetch data for ${oxford(errors, 'and')}` }); } // create a set from all the item names so that there are no duplicates for the fuzzy search @@ -86,7 +86,7 @@ export default class PriceCommand extends BushCommand { // if its a bazaar item then it there should not be any ah data if (bazaar?.products?.[parsedItem]) { - priceEmbed.setTitle(`Bazaar Information for ${util.format.input(parsedItem)}`).addFields([ + priceEmbed.setTitle(`Bazaar Information for ${format.input(parsedItem)}`).addFields([ { name: 'Sell Price', value: addBazaarInformation('sellPrice', 2, true) }, { name: 'Buy Price', value: addBazaarInformation('buyPrice', 2, true) }, { @@ -103,7 +103,7 @@ export default class PriceCommand extends BushCommand { // checks if the item exists in any of the action information otherwise it is not a valid item if (currentLowestBIN?.[parsedItem] || averageLowestBIN?.[parsedItem] || auctionAverages?.[parsedItem]) { - priceEmbed.setTitle(`Price Information for ${util.format.input(parsedItem)}`).setFooter({ + priceEmbed.setTitle(`Price Information for ${format.input(parsedItem)}`).setFooter({ text: `${ priceEmbed.data.footer?.text ? `${priceEmbed.data.footer.text} | ` : '' }All information is based on the last 3 days.` @@ -111,10 +111,8 @@ export default class PriceCommand extends BushCommand { } else { const errorEmbed = new EmbedBuilder(); errorEmbed - .setColor(util.colors.error) - .setDescription( - `${util.emojis.error} ${util.format.input(parsedItem)} is not a valid item id, or it has no auction data.` - ); + .setColor(colors.error) + .setDescription(`${emojis.error} ${format.input(parsedItem)} is not a valid item id, or it has no auction data.`); return await message.util.reply({ embeds: [errorEmbed] }); } diff --git a/src/commands/utilities/remind.ts b/src/commands/utilities/remind.ts index 8727879..3a1cd18 100644 --- a/src/commands/utilities/remind.ts +++ b/src/commands/utilities/remind.ts @@ -1,4 +1,17 @@ -import { BushCommand, Reminder, Time, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; +import { + BushCommand, + castDurationContent, + clientSendAndPermCheck, + dateDelta, + emojis, + format, + Reminder, + Time, + timestamp, + type CommandMessage, + type OptArgType, + type SlashMessage +} from '#lib'; import { ApplicationCommandOptionType } from 'discord.js'; export default class RemindCommand extends BushCommand { @@ -22,7 +35,7 @@ export default class RemindCommand extends BushCommand { } ], slash: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [] }); } @@ -31,13 +44,13 @@ export default class RemindCommand extends BushCommand { message: CommandMessage | SlashMessage, args: { reminder: OptArgType<'contentWithDuration'> | string } ) { - const { duration, content } = await util.castDurationContent(args.reminder, message); + const { duration, content } = await castDurationContent(args.reminder, message); - if (!content.trim()) return await message.util.reply(`${util.emojis.error} Please enter a reason to be reminded about.`); - if (!duration) return await message.util.reply(`${util.emojis.error} Please enter a time to remind you in.`); + if (!content.trim()) return await message.util.reply(`${emojis.error} Please enter a reason to be reminded about.`); + if (!duration) return await message.util.reply(`${emojis.error} Please enter a time to remind you in.`); if (duration < Time.Second * 30) - return await message.util.reply(`${util.emojis.error} You cannot be reminded in less than 30 seconds.`); + return await message.util.reply(`${emojis.error} You cannot be reminded in less than 30 seconds.`); const expires = new Date(Date.now() + duration); @@ -49,10 +62,10 @@ export default class RemindCommand extends BushCommand { expires: expires }).catch(() => false); - if (!success) return await message.util.reply(`${util.emojis.error} Could not create a reminder.`); + if (!success) return await message.util.reply(`${emojis.error} Could not create a reminder.`); // This isn't technically accurate, but it prevents it from being .99 seconds - const delta = util.format.bold(util.dateDelta(new Date(Date.now() + duration))); - return await message.util.reply(`${util.emojis.success} I will remind you in ${delta} (${util.timestamp(expires, 'T')}).`); + const delta = format.bold(dateDelta(new Date(Date.now() + duration))); + return await message.util.reply(`${emojis.success} I will remind you in ${delta} (${timestamp(expires, 'T')}).`); } } diff --git a/src/commands/utilities/reminders.ts b/src/commands/utilities/reminders.ts index 79284ac..18243fe 100644 --- a/src/commands/utilities/reminders.ts +++ b/src/commands/utilities/reminders.ts @@ -1,4 +1,15 @@ -import { BushCommand, ButtonPaginator, Reminder, type CommandMessage, type SlashMessage } from '#lib'; +import { + BushCommand, + ButtonPaginator, + chunk, + clientSendAndPermCheck, + colors, + emojis, + Reminder, + timestamp, + type CommandMessage, + type SlashMessage +} from '#lib'; import assert from 'assert'; import { PermissionFlagsBits, type APIEmbed } from 'discord.js'; import { Op } from 'sequelize'; @@ -14,22 +25,22 @@ export default class RemindersCommand extends BushCommand { usage: ['reminder'], examples: ['reminders'], slash: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks]), + clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks]), userPermissions: [] }); } public override async exec(message: CommandMessage | SlashMessage) { const reminders = await Reminder.findAll({ where: { user: message.author.id, expires: { [Op.gt]: new Date() } } }); - if (!reminders.length) return message.util.send(`${util.emojis.error} You don't have any reminders set.`); + if (!reminders.length) return message.util.send(`${emojis.error} You don't have any reminders set.`); - const formattedReminders = reminders.map((reminder) => `${util.timestamp(reminder.expires, 't')} - ${reminder.content}`); + const formattedReminders = reminders.map((reminder) => `${timestamp(reminder.expires, 't')} - ${reminder.content}`); - const chunked = util.chunk(formattedReminders, 15); + const chunked = chunk(formattedReminders, 15); const embeds: APIEmbed[] = chunked.map((chunk) => ({ title: `Reminders`, description: chunk.join('\n'), - color: util.colors.default + color: colors.default })); return await ButtonPaginator.send(message, embeds); } diff --git a/src/commands/utilities/steal.ts b/src/commands/utilities/steal.ts index 69d3054..83ec338 100644 --- a/src/commands/utilities/steal.ts +++ b/src/commands/utilities/steal.ts @@ -1,4 +1,13 @@ -import { BushCommand, OptArgType, type CommandMessage, type SlashMessage } from '#lib'; +import { + Arg, + BushCommand, + clientSendAndPermCheck, + emojis, + OptArgType, + regex, + type CommandMessage, + type SlashMessage +} from '#lib'; import assert from 'assert'; import { type ArgumentGeneratorReturn, type ArgumentType, type ArgumentTypeCaster } from 'discord-akairo'; import { ApplicationCommandOptionType, Attachment, PermissionFlagsBits } from 'discord.js'; @@ -36,7 +45,7 @@ export default class StealCommand extends BushCommand { ], slash: true, channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m, [PermissionFlagsBits.ManageEmojisAndStickers]), + clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.ManageEmojisAndStickers]), userPermissions: [PermissionFlagsBits.ManageEmojisAndStickers] }); } @@ -47,7 +56,7 @@ export default class StealCommand extends BushCommand { const emoji = hasImage ? message.attachments.first()!.url : yield { - type: util.arg.union('discordEmoji', 'snowflake', 'url') as ArgumentType | ArgumentTypeCaster, + type: Arg.union('discordEmoji', 'snowflake', 'url') as ArgumentType | ArgumentTypeCaster, prompt: { start: lang.emojiStart, retry: lang.emojiRetry } }; @@ -65,20 +74,20 @@ export default class StealCommand extends BushCommand { ) { assert(message.inGuild()); - if (!args.emoji) return await message.util.reply(`${util.emojis.error} You must provide an emoji to steal.`); + if (!args.emoji) return await message.util.reply(`${emojis.error} You must provide an emoji to steal.`); const image = args.emoji instanceof URL ? args.emoji.href : typeof args.emoji === 'object' ? `https://cdn.discordapp.com/emojis/${args.emoji.id}` - : client.consts.regex.snowflake.test(args.emoji ?? '') + : regex.snowflake.test(args.emoji ?? '') ? `https://cdn.discordapp.com/emojis/${args!.emoji}` : (args.emoji ?? '').match(/https?:\/\//) ? args.emoji : undefined; - if (image === undefined) return await message.util.reply(`${util.emojis.error} You must provide an emoji to steal.`); + if (image === undefined) return await message.util.reply(`${emojis.error} You must provide an emoji to steal.`); const emojiName = args.name ?? args.emoji instanceof URL @@ -96,11 +105,9 @@ export default class StealCommand extends BushCommand { .catch((e: Error) => e); if (!(creationSuccess instanceof Error)) - return await message.util.reply(`${util.emojis.success} You successfully stole ${creationSuccess}.`); + return await message.util.reply(`${emojis.success} You successfully stole ${creationSuccess}.`); else { - return await message.util.reply( - `${util.emojis.error} The was an error stealing that emoji \`${creationSuccess.message}\`.` - ); + return await message.util.reply(`${emojis.error} The was an error stealing that emoji \`${creationSuccess.message}\`.`); } } @@ -129,11 +136,9 @@ export default class StealCommand extends BushCommand { .catch((e: Error) => e); if (!(creationSuccess instanceof Error)) - return await message.util.reply(`${util.emojis.success} You successfully stole ${creationSuccess}.`); + return await message.util.reply(`${emojis.success} You successfully stole ${creationSuccess}.`); else { - return await message.util.reply( - `${util.emojis.error} The was an error stealing that emoji \`${creationSuccess.message}\`.` - ); + return await message.util.reply(`${emojis.error} The was an error stealing that emoji \`${creationSuccess.message}\`.`); } } } diff --git a/src/commands/utilities/suicide.ts b/src/commands/utilities/suicide.ts index c4151e8..d2510cc 100644 --- a/src/commands/utilities/suicide.ts +++ b/src/commands/utilities/suicide.ts @@ -1,4 +1,4 @@ -import { AllowedMentions, BushCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { AllowedMentions, BushCommand, clientSendAndPermCheck, colors, type CommandMessage, type SlashMessage } from '#lib'; import { stripIndent } from '#tags'; import { EmbedBuilder } from 'discord.js'; @@ -11,7 +11,7 @@ export default class SuicideCommand extends BushCommand { usage: ['suicide'], examples: ['suicide'], slash: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [], bypassChannelBlacklist: true }); @@ -21,7 +21,7 @@ export default class SuicideCommand extends BushCommand { // stolen from https://github.com/dexbiobot/Zeppelin const suicideEmbed = new EmbedBuilder() .setTitle('Mental Health Resources') - .setColor(util.colors.red) + .setColor(colors.red) .setAuthor({ name: 'Remember, You Matter <3', iconURL: diff --git a/src/commands/utilities/uuid.ts b/src/commands/utilities/uuid.ts index 1e70e91..44cfeda 100644 --- a/src/commands/utilities/uuid.ts +++ b/src/commands/utilities/uuid.ts @@ -1,4 +1,14 @@ -import { AllowedMentions, ArgType, BushCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { + AllowedMentions, + ArgType, + BushCommand, + clientSendAndPermCheck, + emojis, + format, + mcUUID, + type CommandMessage, + type SlashMessage +} from '#lib'; import { ApplicationCommandOptionType } from 'discord.js'; export default class UuidCommand extends BushCommand { @@ -30,7 +40,7 @@ export default class UuidCommand extends BushCommand { } ], slash: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [] }); } @@ -41,17 +51,17 @@ export default class UuidCommand extends BushCommand { ) { if (typeof args.ign === 'string') args.ign = { match: /\w{1,16}/im.exec(args.ign)!, matches: [] }; - if (!args.ign.match) return await message.util.reply(`${util.emojis.error} Please enter a valid ign.`); + if (!args.ign.match) return await message.util.reply(`${emojis.error} Please enter a valid ign.`); const readableIGN = args.ign.match[0]; try { - const uuid = await util.mcUUID(readableIGN, args.dashed); + const uuid = await mcUUID(readableIGN, args.dashed); return await message.util.reply({ - content: `The uuid for ${util.format.input(readableIGN)} is ${util.format.input(uuid)}`, + content: `The uuid for ${format.input(readableIGN)} is ${format.input(uuid)}`, allowedMentions: AllowedMentions.none() }); } catch (e) { return await message.util.reply({ - content: `${util.emojis.error} Could not find an uuid for ${util.format.input(readableIGN)}.`, + content: `${emojis.error} Could not find an uuid for ${format.input(readableIGN)}.`, allowedMentions: AllowedMentions.none() }); } diff --git a/src/commands/utilities/viewRaw.ts b/src/commands/utilities/viewRaw.ts index 5c2c146..8114cef 100644 --- a/src/commands/utilities/viewRaw.ts +++ b/src/commands/utilities/viewRaw.ts @@ -1,4 +1,16 @@ -import { BushCommand, type ArgType, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; +import { + Arg, + BushCommand, + clientSendAndPermCheck, + codeblock, + colors, + emojis, + inspect, + type ArgType, + type CommandMessage, + type OptArgType, + type SlashMessage +} from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, ChannelType, EmbedBuilder, Message, PermissionFlagsBits } from 'discord.js'; @@ -14,7 +26,7 @@ export default class ViewRawCommand extends BushCommand { { id: 'message', description: 'The message to view the raw content of.', - type: util.arg.union('message', 'messageLink'), + type: Arg.union('message', 'messageLink'), readableType: 'message|messageLink', prompt: 'What message would you like to view?', retry: '{error} Choose a valid message.', @@ -23,7 +35,7 @@ export default class ViewRawCommand extends BushCommand { { id: 'channel', description: 'The channel that the message is in.', - type: util.arg.union('textChannel', 'newsChannel', 'threadChannel', 'voiceChannel'), + type: Arg.union('textChannel', 'newsChannel', 'threadChannel', 'voiceChannel'), prompt: 'What channel is the message in?', retry: '{error} Choose a valid channel.', optional: true, @@ -59,7 +71,7 @@ export default class ViewRawCommand extends BushCommand { ], slash: true, channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true), + clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true), userPermissions: [] }); } @@ -81,7 +93,7 @@ export default class ViewRawCommand extends BushCommand { args.message instanceof Message ? args.message : await args.channel!.messages.fetch(`${args.message}`).catch(() => null); if (!newMessage) return await message.util.reply( - `${util.emojis.error} There was an error fetching that message, make sure that is a valid id and if the message is not in this channel, please provide a channel.` + `${emojis.error} There was an error fetching that message, make sure that is a valid id and if the message is not in this channel, please provide a channel.` ); const Embed = await ViewRawCommand.getRawData(newMessage, { json: args.json, js: args.js }); @@ -94,14 +106,14 @@ export default class ViewRawCommand extends BushCommand { options.json || options.js ? options.json ? JSON.stringify(message.toJSON(), undefined, 2) - : util.inspect(message.toJSON()) || '[No Content]' + : inspect(message.toJSON()) || '[No Content]' : message.content || '[No Content]'; const lang = options.json ? 'json' : options.js ? 'js' : undefined; return new EmbedBuilder() .setFooter({ text: message.author.tag, iconURL: message.author.avatarURL() ?? undefined }) .setTimestamp(message.createdTimestamp) - .setColor(message.member?.roles?.color?.color ?? util.colors.default) + .setColor(message.member?.roles?.color?.color ?? colors.default) .setTitle('Raw Message Information') - .setDescription(await util.codeblock(content, 2048, lang)); + .setDescription(await codeblock(content, 2048, lang)); } } diff --git a/src/commands/utilities/whoHasRole.ts b/src/commands/utilities/whoHasRole.ts index ae96a65..851411a 100644 --- a/src/commands/utilities/whoHasRole.ts +++ b/src/commands/utilities/whoHasRole.ts @@ -1,6 +1,17 @@ -import { BushCommand, ButtonPaginator, OptArgType, type CommandMessage, type SlashMessage } from '#lib'; +import { + BushCommand, + ButtonPaginator, + chunk, + clientSendAndPermCheck, + colors, + emojis, + OptArgType, + oxford, + type CommandMessage, + type SlashMessage +} from '#lib'; import assert from 'assert'; -import { ApplicationCommandOptionType, Util, type CommandInteraction, type Role } from 'discord.js'; +import { ApplicationCommandOptionType, escapeMarkdown, type CommandInteraction, type Role } from 'discord.js'; export default class WhoHasRoleCommand extends BushCommand { public constructor() { @@ -24,7 +35,7 @@ export default class WhoHasRoleCommand extends BushCommand { ), slash: true, channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [], typing: true }); @@ -44,18 +55,18 @@ export default class WhoHasRoleCommand extends BushCommand { const members = message.guild.members.cache.filter((m) => roles.every((r) => m.roles.cache.has(r))); - const roleMembers = members.map((member) => `${member.user} (${Util.escapeMarkdown(member.user.tag)})`); - const chunkedRoleMembers = util.chunk(roleMembers, 30); + const roleMembers = members.map((member) => `${member.user} (${escapeMarkdown(member.user.tag)})`); + const chunkedRoleMembers = chunk(roleMembers, 30); const title = `Members with ${ roles.length < 4 - ? util.oxford( + ? oxford( rawRoles.map((r) => r.name), 'and' ) : `${rawRoles.length} Roles` } [\`${members.size.toLocaleString()}\`]`; - const color = util.colors.default; + const color = colors.default; const embedPages = chunkedRoleMembers.map((chunk) => ({ title, description: chunk.join('\n'), @@ -63,7 +74,7 @@ export default class WhoHasRoleCommand extends BushCommand { })); if (embedPages.length === 0) { - return await message.util.reply(`${util.emojis.error} No members found matching the given roles.`); + return await message.util.reply(`${emojis.error} No members found matching the given roles.`); } return await ButtonPaginator.send(message, embedPages, null, true); diff --git a/src/commands/utilities/wolframAlpha.ts b/src/commands/utilities/wolframAlpha.ts index 98cac69..b682c85 100644 --- a/src/commands/utilities/wolframAlpha.ts +++ b/src/commands/utilities/wolframAlpha.ts @@ -1,4 +1,15 @@ -import { AllowedMentions, BushCommand, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; +import { + AllowedMentions, + BushCommand, + clientSendAndPermCheck, + colors, + emojis, + inspectCleanRedactCodeblock, + uploadImageToImgur, + type ArgType, + type CommandMessage, + type SlashMessage +} from '#lib'; import { initializeClass as WolframAlphaAPI } from '@notenoughupdates/wolfram-alpha-api'; import assert from 'assert'; import { ApplicationCommandOptionType, EmbedBuilder, type MessageOptions } from 'discord.js'; @@ -34,7 +45,7 @@ export default class WolframAlphaCommand extends BushCommand { } ], slash: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [] }); } @@ -45,13 +56,13 @@ export default class WolframAlphaCommand extends BushCommand { ) { if (message.util.isSlashMessage(message)) await message.interaction.deferReply(); - args.image && void message.util.reply({ content: `${util.emojis.loading} Loading...`, embeds: [] }); + args.image && void message.util.reply({ content: `${emojis.loading} Loading...`, embeds: [] }); const waApi = WolframAlphaAPI(client.config.credentials.wolframAlphaAppId); const decodedEmbed = new EmbedBuilder().addFields([ { name: '📥 Input', - value: await util.inspectCleanRedactCodeblock(args.expression) + value: await inspectCleanRedactCodeblock(args.expression) } ]); const sendOptions: MessageOptions = { content: null, allowedMentions: AllowedMentions.none() }; @@ -59,21 +70,19 @@ export default class WolframAlphaCommand extends BushCommand { const calculated = await (args.image ? waApi.getSimple({ i: args.expression, timeout: 1, background: '2C2F33', foreground: 'white' }) : waApi.getShort(args.expression)); - decodedEmbed.setTitle(`${util.emojis.successFull} Successfully Queried Expression`).setColor(util.colors.success); + decodedEmbed.setTitle(`${emojis.successFull} Successfully Queried Expression`).setColor(colors.success); if (args.image) { - decodedEmbed.setImage(await util.uploadImageToImgur(calculated.split(',')[1])); + decodedEmbed.setImage(await uploadImageToImgur(calculated.split(',')[1])); decodedEmbed.addFields([{ name: '📤 Output', value: '​' }]); } else { - decodedEmbed.addFields([{ name: '📤 Output', value: await util.inspectCleanRedactCodeblock(calculated.toString()) }]); + decodedEmbed.addFields([{ name: '📤 Output', value: await inspectCleanRedactCodeblock(calculated.toString()) }]); } } catch (error) { decodedEmbed - .setTitle(`${util.emojis.errorFull} Unable to Query Expression`) - .setColor(util.colors.error) - .addFields([ - { name: `📤 Error`, value: await util.inspectCleanRedactCodeblock(`${error.name}: ${error.message}`, 'js') } - ]); + .setTitle(`${emojis.errorFull} Unable to Query Expression`) + .setColor(colors.error) + .addFields([{ name: `📤 Error`, value: await inspectCleanRedactCodeblock(`${error.name}: ${error.message}`, 'js') }]); } sendOptions.embeds = [decodedEmbed]; |