From 0e87bbd3940d89defcb04926587b35c8f4d1947f Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Thu, 16 Jun 2022 14:32:18 -0400 Subject: remove util classes, move config out of src --- src/commands/admin/channelPermissions.ts | 22 +++++-- src/commands/admin/roleAll.ts | 22 ++++--- src/commands/config/_customAutomodPhrases.ts | 2 +- src/commands/config/blacklist.ts | 41 ++++++++----- src/commands/config/config.ts | 29 +++++---- src/commands/config/disable.ts | 39 ++++++++----- src/commands/config/features.ts | 10 ++-- src/commands/config/log.ts | 20 +++++-- src/commands/dev/__template.ts | 14 ++++- src/commands/dev/debug.ts | 6 +- src/commands/dev/dm.ts | 8 +-- src/commands/dev/eval.ts | 24 ++++---- src/commands/dev/javascript.ts | 27 ++++++--- src/commands/dev/reload.ts | 22 ++++--- src/commands/dev/say.ts | 17 ++++-- src/commands/dev/servers.ts | 19 ++++-- src/commands/dev/sh.ts | 42 +++++++------ src/commands/dev/superUser.ts | 30 ++++++---- src/commands/dev/syncAutomod.ts | 8 +-- src/commands/dev/test.ts | 29 +++++---- src/commands/fun/coinFlip.ts | 4 +- src/commands/fun/dice.ts | 4 +- src/commands/fun/eightBall.ts | 4 +- src/commands/fun/minesweeper.ts | 18 ++++-- src/commands/info/avatar.ts | 8 +-- src/commands/info/botInfo.ts | 23 +++++--- src/commands/info/color.ts | 22 ++++--- src/commands/info/guildInfo.ts | 50 ++++++++++------ src/commands/info/help.ts | 27 ++++++--- src/commands/info/icon.ts | 10 ++-- src/commands/info/links.ts | 6 +- src/commands/info/ping.ts | 10 ++-- src/commands/info/pronouns.ts | 26 +++++---- src/commands/info/snowflake.ts | 49 +++++++++------- src/commands/info/userInfo.ts | 81 ++++++++++++++++---------- src/commands/leveling/leaderboard.ts | 21 +++++-- src/commands/leveling/level.ts | 11 ++-- src/commands/leveling/levelRoles.ts | 33 +++++++---- src/commands/leveling/setLevel.ts | 20 +++++-- src/commands/leveling/setXp.ts | 24 +++++--- src/commands/moderation/_activePunishments.ts | 6 +- src/commands/moderation/ban.ts | 35 ++++++----- src/commands/moderation/block.ts | 33 ++++++----- src/commands/moderation/evidence.ts | 34 +++++++---- src/commands/moderation/hideCase.ts | 21 +++++-- src/commands/moderation/kick.ts | 21 ++++--- src/commands/moderation/lockdown.ts | 31 +++++----- src/commands/moderation/massBan.ts | 23 +++++--- src/commands/moderation/massEvidence.ts | 29 ++++++--- src/commands/moderation/modlog.ts | 46 ++++++++++----- src/commands/moderation/mute.ts | 38 +++++++----- src/commands/moderation/purge.ts | 23 +++++--- src/commands/moderation/removeReactionEmoji.ts | 27 ++++++--- src/commands/moderation/role.ts | 36 +++++++----- src/commands/moderation/slowmode.ts | 27 ++++++--- src/commands/moderation/timeout.ts | 28 +++++---- src/commands/moderation/unban.ts | 21 ++++--- src/commands/moderation/unblock.ts | 30 +++++----- src/commands/moderation/unlockdown.ts | 14 ++++- src/commands/moderation/unmute.ts | 27 +++++---- src/commands/moderation/untimeout.ts | 23 ++++---- src/commands/moderation/warn.ts | 21 ++++--- src/commands/moulberry-bush/capePermissions.ts | 31 ++++++---- src/commands/moulberry-bush/capes.ts | 17 ++++-- src/commands/moulberry-bush/giveawayPing.ts | 6 +- src/commands/moulberry-bush/moulHammer.ts | 6 +- src/commands/moulberry-bush/report.ts | 39 ++++++++----- src/commands/moulberry-bush/rule.ts | 14 ++++- src/commands/moulberry-bush/serverStatus.ts | 18 +++--- src/commands/utilities/_poll.ts | 10 ++-- src/commands/utilities/activity.ts | 26 +++++---- src/commands/utilities/calculator.ts | 29 +++++---- src/commands/utilities/decode.ts | 26 ++++++--- src/commands/utilities/hash.ts | 4 +- src/commands/utilities/highlight-!.ts | 4 +- src/commands/utilities/highlight-add.ts | 14 ++--- src/commands/utilities/highlight-block.ts | 26 ++++++--- src/commands/utilities/highlight-clear.ts | 8 +-- src/commands/utilities/highlight-matches.ts | 12 ++-- src/commands/utilities/highlight-remove.ts | 8 +-- src/commands/utilities/highlight-show.ts | 6 +- src/commands/utilities/highlight-unblock.ts | 21 +++++-- src/commands/utilities/price.ts | 18 +++--- src/commands/utilities/remind.ts | 31 +++++++--- src/commands/utilities/reminders.ts | 23 ++++++-- src/commands/utilities/steal.ts | 33 ++++++----- src/commands/utilities/suicide.ts | 6 +- src/commands/utilities/uuid.ts | 22 +++++-- src/commands/utilities/viewRaw.ts | 28 ++++++--- src/commands/utilities/whoHasRole.ts | 27 ++++++--- src/commands/utilities/wolframAlpha.ts | 33 +++++++---- 91 files changed, 1267 insertions(+), 755 deletions(-) (limited to 'src/commands') diff --git a/src/commands/admin/channelPermissions.ts b/src/commands/admin/channelPermissions.ts index f6240a5..12245a9 100644 --- a/src/commands/admin/channelPermissions.ts +++ b/src/commands/admin/channelPermissions.ts @@ -1,4 +1,14 @@ -import { BushCommand, ButtonPaginator, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; +import { + Arg, + BushCommand, + ButtonPaginator, + clientSendAndPermCheck, + emojis, + formatError, + type ArgType, + type CommandMessage, + type SlashMessage +} from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, EmbedBuilder, PermissionFlagsBits } from 'discord.js'; @@ -15,7 +25,7 @@ export default class ChannelPermissionsCommand extends BushCommand { { id: 'target', description: 'The user/role to change the permissions of.', - type: util.arg.union('member', 'role'), + type: Arg.union('member', 'role'), readableType: 'member|role', prompt: 'What user/role would you like to change?', retry: '{error} Choose a valid user/role to change.', @@ -48,7 +58,7 @@ export default class ChannelPermissionsCommand extends BushCommand { ] } ], - clientPermissions: (m) => util.clientSendAndPermCheck(m, [PermissionFlagsBits.ManageChannels]), + clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.ManageChannels]), userPermissions: [PermissionFlagsBits.Administrator], channel: 'guild', slash: true, @@ -64,9 +74,9 @@ export default class ChannelPermissionsCommand extends BushCommand { if (message.util.isSlashMessage(message)) await message.interaction.deferReply(); const permission = message.util.isSlashMessage(message) - ? await util.arg.cast('permission', message, args.permission) + ? await Arg.cast('permission', message, args.permission) : args.permission; - if (!permission) return await message.util.reply(`${util.emojis.error} Invalid permission.`); + if (!permission) return await message.util.reply(`${emojis.error} Invalid permission.`); const failedChannels = []; for (const [, channel] of message.guild.channels.cache) { try { @@ -79,7 +89,7 @@ export default class ChannelPermissionsCommand extends BushCommand { { reason: 'Changing overwrites for mass channel perms command' } ); } catch (e) { - void client.console.error('channelPermissions', util.formatError(e, false)); + void client.console.error('channelPermissions', formatError(e, false)); failedChannels.push(channel); } } diff --git a/src/commands/admin/roleAll.ts b/src/commands/admin/roleAll.ts index 80952cc..c731f08 100644 --- a/src/commands/admin/roleAll.ts +++ b/src/commands/admin/roleAll.ts @@ -1,4 +1,12 @@ -import { AllowedMentions, BushCommand, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; +import { + AllowedMentions, + BushCommand, + clientSendAndPermCheck, + emojis, + type ArgType, + type CommandMessage, + type SlashMessage +} from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, PermissionFlagsBits, type GuildMember } from 'discord.js'; @@ -32,7 +40,7 @@ export default class RoleAllCommand extends BushCommand { } ], channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m, [PermissionFlagsBits.ManageRoles]), + clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.ManageRoles]), userPermissions: [PermissionFlagsBits.Administrator], typing: true, slash: true, @@ -43,11 +51,11 @@ export default class RoleAllCommand extends BushCommand { public override async exec(message: CommandMessage | SlashMessage, args: { role: ArgType<'role'>; bots: ArgType<'flag'> }) { assert(message.inGuild()); if (!message.member!.permissions.has(PermissionFlagsBits.Administrator) && !message.member!.user.isOwner()) - return await message.util.reply(`${util.emojis.error} You must have admin perms to use this command.`); + return await message.util.reply(`${emojis.error} You must have admin perms to use this command.`); if (message.util.isSlashMessage(message)) await message.interaction.deferReply(); if (args.role.comparePositionTo(message.guild.members.me!.roles.highest) >= 0 && !args.role) { - return await message.util.reply(`${util.emojis.error} I cannot assign a role higher or equal to my highest role.`); + return await message.util.reply(`${emojis.error} I cannot assign a role higher or equal to my highest role.`); } let members = await message.guild.members.fetch(); @@ -62,7 +70,7 @@ export default class RoleAllCommand extends BushCommand { return true; }); - await message.util.reply(`${util.emojis.loading} adding roles to ${members.size} members`); + await message.util.reply(`${emojis.loading} adding roles to ${members.size} members`); const promises = members.map((member: GuildMember) => { return member.roles.add(args.role, `RoleAll Command - triggered by ${message.author.tag} (${message.author.id})`); @@ -72,7 +80,7 @@ export default class RoleAllCommand extends BushCommand { if (!failed.length) { await message.util.sendNew({ - content: `${util.emojis.success} Finished adding <@&${args.role.id}> to **${members.size}** member${ + content: `${emojis.success} Finished adding <@&${args.role.id}> to **${members.size}** member${ members.size > 1 ? 's' : '' }.`, allowedMentions: AllowedMentions.none() @@ -80,7 +88,7 @@ export default class RoleAllCommand extends BushCommand { } else { const array = [...members.values()]; await message.util.sendNew({ - content: `${util.emojis.warn} Finished adding <@&${args.role.id}> to **${members.size - failed.length}** member${ + content: `${emojis.warn} Finished adding <@&${args.role.id}> to **${members.size - failed.length}** member${ members.size - failed.length > 1 ? 's' : '' }! Failed members:\n${failed.map((_, index) => `<@${array[index].id}>`).join(' ')}`, allowedMentions: AllowedMentions.none() diff --git a/src/commands/config/_customAutomodPhrases.ts b/src/commands/config/_customAutomodPhrases.ts index 13887ae..d60688c 100644 --- a/src/commands/config/_customAutomodPhrases.ts +++ b/src/commands/config/_customAutomodPhrases.ts @@ -30,7 +30,7 @@ // ], // slash: true, // channel: 'guild', -// clientPermissions: (m) => util.clientSendAndPermCheck(m), +// clientPermissions: (m) => clientSendAndPermCheck(m), // userPermissions: [PermissionFlagsBits.ManageGuild] // }); // } diff --git a/src/commands/config/blacklist.ts b/src/commands/config/blacklist.ts index de457c0..80acd0b 100644 --- a/src/commands/config/blacklist.ts +++ b/src/commands/config/blacklist.ts @@ -1,4 +1,17 @@ -import { AllowedMentions, BushCommand, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; +import { + addOrRemoveFromArray, + AllowedMentions, + Arg, + BushCommand, + clientSendAndPermCheck, + emojis, + format, + getGlobal, + setGlobal, + type ArgType, + type CommandMessage, + type SlashMessage +} from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, GuildMember, PermissionFlagsBits, User } from 'discord.js'; @@ -23,7 +36,7 @@ export default class BlacklistCommand extends BushCommand { { id: 'target', description: 'The channel/user to blacklist.', - type: util.arg.union('channel', 'user'), + type: Arg.union('channel', 'user'), readableType: 'channel|user', prompt: 'What channel or user that you would like to blacklist/unblacklist?', retry: '{error} Pick a valid user or channel.', @@ -41,7 +54,7 @@ export default class BlacklistCommand extends BushCommand { } ], slash: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [PermissionFlagsBits.ManageGuild] }); } @@ -59,26 +72,26 @@ export default class BlacklistCommand extends BushCommand { const global = args.global && message.author.isOwner(); const target = typeof args.target === 'string' - ? (await util.arg.cast('textChannel', message, args.target)) ?? (await util.arg.cast('user', message, args.target)) + ? (await Arg.cast('textChannel', message, args.target)) ?? (await Arg.cast('user', message, args.target)) : args.target; - if (!target) return await message.util.reply(`${util.emojis.error} Choose a valid channel or user.`); + if (!target) return await message.util.reply(`${emojis.error} Choose a valid channel or user.`); const targetID = target.id; if (!message.inGuild() && !global) - return await message.util.reply(`${util.emojis.error} You have to be in a guild to disable commands.`); + return await message.util.reply(`${emojis.error} You have to be in a guild to disable commands.`); if (!global) assert(message.inGuild()); const blacklistedUsers = global - ? util.getGlobal('blacklistedUsers') + ? getGlobal('blacklistedUsers') : (await message.guild!.getSetting('blacklistedChannels')) ?? []; const blacklistedChannels = global - ? util.getGlobal('blacklistedChannels') + ? getGlobal('blacklistedChannels') : (await message.guild!.getSetting('blacklistedUsers')) ?? []; if (action === 'toggle') { action = blacklistedUsers.includes(targetID) || blacklistedChannels.includes(targetID) ? 'unblacklist' : 'blacklist'; } - const newValue = util.addOrRemoveFromArray( + const newValue = addOrRemoveFromArray( action === 'blacklist' ? 'add' : 'remove', target instanceof User ? blacklistedUsers : blacklistedChannels, targetID @@ -87,22 +100,22 @@ export default class BlacklistCommand extends BushCommand { const key = target instanceof User ? 'blacklistedUsers' : 'blacklistedChannels'; const success = await (global - ? util.setGlobal(key, newValue) + ? setGlobal(key, newValue) : message.guild!.setSetting(key, newValue, message.member as GuildMember) ).catch(() => false); if (!success) return await message.util.reply({ - content: `${util.emojis.error} There was an error${global ? ' globally' : ''} ${action}ing ${util.format.input( + content: `${emojis.error} There was an error${global ? ' globally' : ''} ${action}ing ${format.input( target instanceof User ? target.tag : target.name )}.`, allowedMentions: AllowedMentions.none() }); else return await message.util.reply({ - content: `${util.emojis.success} Successfully ${action}ed ${util.format.input( - target instanceof User ? target.tag : target.name - )}${global ? ' globally' : ''}.`, + content: `${emojis.success} Successfully ${action}ed ${format.input(target instanceof User ? target.tag : target.name)}${ + global ? ' globally' : '' + }.`, allowedMentions: AllowedMentions.none() }); } diff --git a/src/commands/config/config.ts b/src/commands/config/config.ts index 689a3af..f0db467 100644 --- a/src/commands/config/config.ts +++ b/src/commands/config/config.ts @@ -1,7 +1,14 @@ import { + addOrRemoveFromArray, BushCommand, + clientSendAndPermCheck, + colors, + emojis, GuildNoArraySetting, guildSettingsObj, + inspectAndRedact, + oxford, + prefix, settingsArr, type ArgType, type CommandMessage, @@ -145,7 +152,7 @@ export default class ConfigCommand extends BushCommand { }; }), channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [PermissionFlagsBits.ManageGuild] }); } @@ -171,11 +178,11 @@ export default class ConfigCommand extends BushCommand { id: 'action', type: actionType, prompt: { - start: `Would you like to ${util.oxford( + start: `Would you like to ${oxford( actionType!.map((a) => `\`${a}\``), 'or' )} the \`${setting}\` setting?`, - retry: `{error} Choose one of the following actions to perform on the ${setting} setting: ${util.oxford( + retry: `{error} Choose one of the following actions to perform on the ${setting} setting: ${oxford( actionType!.map((a) => `\`${a}\``), 'or' )}`, @@ -219,7 +226,7 @@ export default class ConfigCommand extends BushCommand { assert(message.member); if (!message.member.permissions.has(PermissionFlagsBits.ManageGuild) && !message.member?.user.isOwner()) - return await message.util.reply(`${util.emojis.error} You must have the **Manage Server** permission to run this command.`); + return await message.util.reply(`${emojis.error} You must have the **Manage Server** permission to run this command.`); const setting = message.util.isSlash ? (camelCase(args.subcommandGroup)! as GuildSettings) : args.setting!; const action = message.util.isSlash ? args.subcommand! : args.action!; const value = args.value; @@ -238,15 +245,13 @@ export default class ConfigCommand extends BushCommand { }; if (!value && !(['clear', 'delete'] as const).includes(action)) - return await message.util.reply( - `${util.emojis.error} You must choose a value to ${action} ${this.grammar(action, setting)}` - ); + return await message.util.reply(`${emojis.error} You must choose a value to ${action} ${this.grammar(action, setting)}`); switch (action) { case 'add': case 'remove': { const existing = (await message.guild.getSetting(setting)) as string[]; - const updated = util.addOrRemoveFromArray(action, existing, parseVal(value)); + const updated = addOrRemoveFromArray(action, existing, parseVal(value)); await message.guild.setSetting(setting, updated, message.member); const messageOptions = await this.generateMessageOptions(message, setting); msg = (await message.util.reply(messageOptions)) as Message; @@ -311,7 +316,7 @@ export default class ConfigCommand extends BushCommand { ): Promise { assert(message.inGuild()); - const settingsEmbed = new EmbedBuilder().setColor(util.colors.default); + const settingsEmbed = new EmbedBuilder().setColor(colors.default); if (!setting) { settingsEmbed.setTitle(`${message.guild.name}'s Settings`); const desc = settingsArr.map((s) => `:wrench: **${guildSettingsObj[s].name}**`).join('\n'); @@ -341,7 +346,7 @@ export default class ConfigCommand extends BushCommand { const func = ((): ((v: string | any) => string) => { switch (type.replace('-array', '') as BaseSettingTypes) { case 'string': - return (v) => util.inspectAndRedact(v); + return (v) => inspectAndRedact(v); case 'channel': return (v) => `<#${v}>`; case 'role': @@ -349,7 +354,7 @@ export default class ConfigCommand extends BushCommand { case 'user': return (v) => `<@${v}>`; case 'custom': - return util.inspectAndRedact; + return inspectAndRedact; default: return (v) => v; } @@ -372,7 +377,7 @@ export default class ConfigCommand extends BushCommand { ); settingsEmbed.setFooter({ - text: `Run "${util.prefix(message)}${message.util.parsed?.alias ?? 'config'} ${ + text: `Run "${prefix(message)}${message.util.parsed?.alias ?? 'config'} ${ message.util.isSlash ? snakeCase(setting) : setting } ${guildSettingsObj[setting].type.includes('-array') ? 'add/remove' : 'set'} " to set this setting.` }); diff --git a/src/commands/config/disable.ts b/src/commands/config/disable.ts index 373b5f6..4f52b7c 100644 --- a/src/commands/config/disable.ts +++ b/src/commands/config/disable.ts @@ -1,4 +1,16 @@ -import { AllowedMentions, BushCommand, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; +import { + addOrRemoveFromArray, + AllowedMentions, + Arg, + BushCommand, + clientSendAndPermCheck, + emojis, + getGlobal, + setGlobal, + type ArgType, + type CommandMessage, + type SlashMessage +} from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, AutocompleteInteraction, PermissionFlagsBits } from 'discord.js'; import Fuse from 'fuse.js'; @@ -28,7 +40,7 @@ export default class DisableCommand extends BushCommand { { id: 'command', description: 'The command to disable/enable.', - type: util.arg.union('commandAlias', 'command'), + type: Arg.union('commandAlias', 'command'), readableType: 'command|commandAlias', prompt: 'What command would you like to enable/disable?', retry: '{error} Pick a valid command.', @@ -48,7 +60,7 @@ export default class DisableCommand extends BushCommand { ], slash: true, channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [PermissionFlagsBits.ManageGuild] }); } @@ -62,23 +74,23 @@ export default class DisableCommand extends BushCommand { let action = (args.action ?? message.util?.parsed?.alias ?? 'toggle') as 'disable' | 'enable' | 'toggle'; const global = args.global && message.author.isOwner(); const commandID = - args.command instanceof BushCommand ? args.command.id : (await util.arg.cast('commandAlias', message, args.command))?.id; + args.command instanceof BushCommand ? args.command.id : (await Arg.cast('commandAlias', message, args.command))?.id; - if (!commandID) return await message.util.reply(`${util.emojis.error} Invalid command.`); + if (!commandID) return await message.util.reply(`${emojis.error} Invalid command.`); if (DisableCommand.blacklistedCommands.includes(commandID)) - return message.util.send(`${util.emojis.error} the ${commandID} command cannot be disabled.`); + return message.util.send(`${emojis.error} the ${commandID} command cannot be disabled.`); - const disabledCommands = global ? util.getGlobal('disabledCommands') : await message.guild.getSetting('disabledCommands'); + const disabledCommands = global ? getGlobal('disabledCommands') : await message.guild.getSetting('disabledCommands'); if (action === 'toggle') action = disabledCommands.includes(commandID) ? 'disable' : 'enable'; - const newValue = util.addOrRemoveFromArray(action === 'disable' ? 'add' : 'remove', disabledCommands, commandID); + const newValue = addOrRemoveFromArray(action === 'disable' ? 'add' : 'remove', disabledCommands, commandID); const success = global - ? await util.setGlobal('disabledCommands', newValue).catch(() => false) + ? await setGlobal('disabledCommands', newValue).catch(() => false) : await message.guild.setSetting('disabledCommands', newValue, message.member!).catch(() => false); if (!success) return await message.util.reply({ - content: `${util.emojis.error} There was an error${global ? ' globally' : ''} **${action.substring( + content: `${emojis.error} There was an error${global ? ' globally' : ''} **${action.substring( 0, action.length - 2 )}ing** the **${commandID}** command.`, @@ -86,10 +98,9 @@ export default class DisableCommand extends BushCommand { }); else return await message.util.reply({ - content: `${util.emojis.success} Successfully **${action.substring( - 0, - action.length - 2 - )}ed** the **${commandID}** command${global ? ' globally' : ''}.`, + content: `${emojis.success} Successfully **${action.substring(0, action.length - 2)}ed** the **${commandID}** command${ + global ? ' globally' : '' + }.`, allowedMentions: AllowedMentions.none() }); } diff --git a/src/commands/config/features.ts b/src/commands/config/features.ts index 95ae544..e88f4b7 100644 --- a/src/commands/config/features.ts +++ b/src/commands/config/features.ts @@ -1,5 +1,8 @@ import { BushCommand, + clientSendAndPermCheck, + colors, + emojis, guildFeaturesArr, guildFeaturesObj, type CommandMessage, @@ -27,7 +30,7 @@ export default class FeaturesCommand extends BushCommand { examples: ['features'], slash: true, channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true), + clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true), userPermissions: [PermissionFlagsBits.ManageGuild] }); } @@ -35,7 +38,7 @@ export default class FeaturesCommand extends BushCommand { public override async exec(message: CommandMessage | SlashMessage) { assert(message.inGuild()); - const featureEmbed = new EmbedBuilder().setTitle(`${message.guild.name}'s Features`).setColor(util.colors.default); + const featureEmbed = new EmbedBuilder().setTitle(`${message.guild.name}'s Features`).setColor(colors.default); const enabledFeatures = await message.guild.getSetting('enabledFeatures'); this.generateDescription(guildFeaturesArr, enabledFeatures, featureEmbed); @@ -76,8 +79,7 @@ export default class FeaturesCommand extends BushCommand { embed.setDescription( allFeatures .map( - (feature) => - `${currentFeatures.includes(feature) ? util.emojis.check : util.emojis.cross} **${guildFeaturesObj[feature].name}**` + (feature) => `${currentFeatures.includes(feature) ? emojis.check : emojis.cross} **${guildFeaturesObj[feature].name}**` ) .join('\n') ); diff --git a/src/commands/config/log.ts b/src/commands/config/log.ts index 7c76bdf..3726105 100644 --- a/src/commands/config/log.ts +++ b/src/commands/config/log.ts @@ -1,4 +1,14 @@ -import { BushCommand, guildLogsArr, type ArgType, type CommandMessage, type GuildLogType, type SlashMessage } from '#lib'; +import { + BushCommand, + clientSendAndPermCheck, + emojis, + guildLogsArr, + oxford, + type ArgType, + type CommandMessage, + type GuildLogType, + type SlashMessage +} from '#lib'; import assert from 'assert'; import { ArgumentGeneratorReturn } from 'discord-akairo'; import { ApplicationCommandOptionType, ChannelType, PermissionFlagsBits } from 'discord.js'; @@ -38,7 +48,7 @@ export default class LogCommand extends BushCommand { } ], channel: 'guild', - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [PermissionFlagsBits.ManageGuild] }); } @@ -49,7 +59,7 @@ export default class LogCommand extends BushCommand { type: guildLogsArr, prompt: { start: 'What log type would you like to change?', - retry: `{error} Choose either ${util.oxford( + retry: `{error} Choose either ${oxford( guildLogsArr.map((l) => `\`${l}\``), 'or' )}`, @@ -87,8 +97,8 @@ export default class LogCommand extends BushCommand { return await message.util.reply( `${ success - ? `${util.emojis.success} Successfully ${oldChannel ? 'changed' : 'set'}` - : `${util.emojis.error} Unable to ${oldChannel ? 'change' : 'set'}` + ? `${emojis.success} Successfully ${oldChannel ? 'changed' : 'set'}` + : `${emojis.error} Unable to ${oldChannel ? 'change' : 'set'}` } ${ oldChannel ? `the **${args.log_type}** log channel from <#${oldChannel}>` : `the **${args.log_type}** log channel` } to ${args.channel ? `<#${args.channel.id}>` : '`disabled`'}` diff --git a/src/commands/dev/__template.ts b/src/commands/dev/__template.ts index 7bcce32..df4d146 100644 --- a/src/commands/dev/__template.ts +++ b/src/commands/dev/__template.ts @@ -1,4 +1,12 @@ -import { BushCommand, type ArgType, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; +import { + BushCommand, + clientSendAndPermCheck, + emojis, + type ArgType, + type CommandMessage, + type OptArgType, + type SlashMessage +} from '#lib'; import { ApplicationCommandOptionType } from 'discord.js'; export default class TemplateCommand extends BushCommand { @@ -33,7 +41,7 @@ export default class TemplateCommand extends BushCommand { ownerOnly: true, channel: 'guild', hidden: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [] }); } @@ -42,7 +50,7 @@ export default class TemplateCommand extends BushCommand { message: CommandMessage | SlashMessage, args: { required_argument: ArgType<'string'>; optional_argument: OptArgType<'string'> } ) { - return await message.util.reply(`${util.emojis.error} Do not use the template command.`); + return await message.util.reply(`${emojis.error} Do not use the template command.`); args; } } diff --git a/src/commands/dev/debug.ts b/src/commands/dev/debug.ts index 682a93d..dd9109c 100644 --- a/src/commands/dev/debug.ts +++ b/src/commands/dev/debug.ts @@ -1,4 +1,4 @@ -// import { BushCommand, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; +// import { BushCommand, clientSendAndPermCheck, emojis, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; // import { ApplicationCommandOptionType, AutocompleteInteraction, ChatInputCommandInteraction } from 'discord.js'; // import Fuse from 'fuse.js'; @@ -24,7 +24,7 @@ // slash: true, // slashGuilds: ['516977525906341928'], // superUserOnly: true, -// clientPermissions: (m) => util.clientSendAndPermCheck(m), +// clientPermissions: (m) => clientSendAndPermCheck(m), // userPermissions: [] // }); // } @@ -52,7 +52,7 @@ // embeds: [{ description: 'And an embed' }] // }); // } else { -// return await message.util.reply(`${util.emojis.error} Invalid action.`); +// return await message.util.reply(`${emojis.error} Invalid action.`); // } // } diff --git a/src/commands/dev/dm.ts b/src/commands/dev/dm.ts index 468fb20..f1e2bce 100644 --- a/src/commands/dev/dm.ts +++ b/src/commands/dev/dm.ts @@ -1,4 +1,4 @@ -import { BushCommand, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; +import { BushCommand, clientSendAndPermCheck, emojis, format, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; import { ApplicationCommandOptionType } from 'discord.js'; export default class DMCommand extends BushCommand { @@ -31,7 +31,7 @@ export default class DMCommand extends BushCommand { slash: false, ownerOnly: true, hidden: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [] }); } @@ -43,8 +43,8 @@ export default class DMCommand extends BushCommand { try { await client.users.send(args.user.id, args.content); } catch (e) { - return message.util.reply(`${util.emojis.error} There was an error sending ${util.format.input(args.user.tag)} a dm.`); + return message.util.reply(`${emojis.error} There was an error sending ${format.input(args.user.tag)} a dm.`); } - return message.util.reply(`${util.emojis.success} Successfully sent ${util.format.input(args.user.tag)} a dm.`); + return message.util.reply(`${emojis.success} Successfully sent ${format.input(args.user.tag)} a dm.`); } } diff --git a/src/commands/dev/eval.ts b/src/commands/dev/eval.ts index b8ee9e4..239a06a 100644 --- a/src/commands/dev/eval.ts +++ b/src/commands/dev/eval.ts @@ -1,11 +1,17 @@ /* eslint-disable @typescript-eslint/no-unused-vars */ import { ActivePunishment, + assertAll, BushCommand, BushInspectOptions, + clientSendAndPermCheck, CodeBlockLang, + colors, + emojis, + getMethods, Global, Guild, + inspectCleanRedactCodeblock, Level, ModLog, Shared, @@ -40,8 +46,7 @@ import { PermissionFlagsBits, PermissionsBitField, ReactionCollector, - SelectMenuComponent, - Util + SelectMenuComponent } from 'discord.js'; import got from 'got'; import path from 'path'; @@ -49,15 +54,13 @@ import ts from 'typescript'; import { fileURLToPath } from 'url'; import { promisify } from 'util'; const { transpile } = ts, - emojis = util.emojis, - colors = util.colors, sh = promisify(exec), SnowflakeUtil = new Snowflake_(1420070400000n), __dirname = path.dirname(fileURLToPath(import.meta.url)); /* eslint-enable @typescript-eslint/no-unused-vars */ // prettier-ignore -util.assertAll(ActivePunishment, BushCommand, Global, Guild, Level, ModLog, Shared, StickyRole, Snowflake_, Canvas, exec, ActionRow, ButtonComponent, ButtonInteraction, Collection, Collector, CommandInteraction, ContextMenuCommandInteraction, DMChannel, Embed, Emoji, Interaction, InteractionCollector, Message, Attachment, MessageCollector, OAuth2Scopes, PermissionFlagsBits, PermissionsBitField, ReactionCollector, SelectMenuComponent, Util, path, ts, fileURLToPath, promisify, assert, got, transpile, emojis, colors, sh, SnowflakeUtil, __dirname); +assertAll(ActivePunishment, BushCommand, Global, Guild, Level, ModLog, Shared, StickyRole, Snowflake_, Canvas, exec, ActionRow, ButtonComponent, ButtonInteraction, Collection, Collector, CommandInteraction, ContextMenuCommandInteraction, DMChannel, Embed, Emoji, Interaction, InteractionCollector, Message, Attachment, MessageCollector, OAuth2Scopes, PermissionFlagsBits, PermissionsBitField, ReactionCollector, SelectMenuComponent, path, ts, fileURLToPath, promisify, assert, got, transpile, sh, SnowflakeUtil, __dirname); export default class EvalCommand extends BushCommand { public constructor() { @@ -174,7 +177,7 @@ export default class EvalCommand extends BushCommand { ], slash: true, ownerOnly: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [] }); } @@ -207,12 +210,11 @@ export default class EvalCommand extends BushCommand { no_inspect_strings: ArgType<'flag'>; } ) { - if (!message.author.isOwner()) - return await message.util.reply(`${util.emojis.error} Only my developers can run this command.`); + if (!message.author.isOwner()) return await message.util.reply(`${emojis.error} Only my developers can run this command.`); if (message.util.isSlashMessage(message)) await message.interaction.deferReply({ ephemeral: silent }); if (!sudo && ['delete', 'destroy'].some((p) => argCode.includes(p))) { - return await message.util.send(`${util.emojis.error} This eval was blocked by smooth brain protection™.`); + return await message.util.send(`${emojis.error} This eval was blocked by smooth brain protection™.`); } const isTypescript = typescript || argCode.includes('```ts'); @@ -308,12 +310,12 @@ export default class EvalCommand extends BushCommand { private async codeblock(obj: any, language: CodeBlockLang, options: CodeBlockCustomOptions = {}) { if (options.prototype) obj = Object.getPrototypeOf(obj); - if (options.methods) obj = util.getMethods(obj); + if (options.methods) obj = getMethods(obj); options.depth ??= 1; options.getters ??= true; - return util.inspectCleanRedactCodeblock(obj, language, options); + return inspectCleanRedactCodeblock(obj, language, options); } } diff --git a/src/commands/dev/javascript.ts b/src/commands/dev/javascript.ts index fd1894b..7c47f2f 100644 --- a/src/commands/dev/javascript.ts +++ b/src/commands/dev/javascript.ts @@ -1,4 +1,14 @@ -import { BushCommand, type ArgType, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; +import { + BushCommand, + clientSendAndPermCheck, + colors, + emojis, + inspectCleanRedactCodeblock, + type ArgType, + type CommandMessage, + type OptArgType, + type SlashMessage +} from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, EmbedBuilder } from 'discord.js'; import { VM } from 'vm2'; @@ -35,7 +45,7 @@ export default class JavascriptCommand extends BushCommand { ], slash: true, superUserOnly: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [] }); } @@ -44,36 +54,35 @@ export default class JavascriptCommand extends BushCommand { message: CommandMessage | SlashMessage, args: { code: ArgType<'string'>; sel_depth: OptArgType<'integer'> } ) { - if (!message.author.isSuperUser()) - return await message.util.reply(`${util.emojis.error} Only super users can run this command.`); + if (!message.author.isSuperUser()) return await message.util.reply(`${emojis.error} Only super users can run this command.`); if (message.util.isSlashMessage(message)) { await message.interaction.deferReply({ ephemeral: false }); } const code = args.code.replace(/[“”]/g, '"').replace(/```*(?:js)?/g, ''); const embed = new EmbedBuilder(); - const input = await util.inspectCleanRedactCodeblock(code, 'js'); + const input = await inspectCleanRedactCodeblock(code, 'js'); try { const rawOutput = /^(9\s*?\+\s*?10)|(10\s*?\+\s*?9)$/.test(code) ? '21' : new VM({ eval: true, wasm: true, timeout: 1_000, fixAsync: true }).run(`${code}`); - const output = await util.inspectCleanRedactCodeblock(rawOutput, 'js', { + const output = await inspectCleanRedactCodeblock(rawOutput, 'js', { depth: args.sel_depth ?? 0, getters: true, inspectStrings: true, colors: false }); - embed.setTitle(`${util.emojis.successFull} Successfully Evaluated Expression`).setColor(util.colors.success); + embed.setTitle(`${emojis.successFull} Successfully Evaluated Expression`).setColor(colors.success); embed.addFields([ { name: '📥 Input', value: input }, { name: '📤 Output', value: output } ]); } catch (e) { - embed.setTitle(`${util.emojis.errorFull} Unable to Evaluate Expression`).setColor(util.colors.error); + embed.setTitle(`${emojis.errorFull} Unable to Evaluate Expression`).setColor(colors.error); embed.addFields([ { name: '📥 Input', value: input }, - { name: '📤 Error', value: await util.inspectCleanRedactCodeblock(e, 'js', { colors: false }) } + { name: '📤 Error', value: await inspectCleanRedactCodeblock(e, 'js', { colors: false }) } ]); } diff --git a/src/commands/dev/reload.ts b/src/commands/dev/reload.ts index 96c395f..8c2000f 100644 --- a/src/commands/dev/reload.ts +++ b/src/commands/dev/reload.ts @@ -1,4 +1,13 @@ -import { BushCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { + BushCommand, + clientSendAndPermCheck, + codeblock, + emojis, + formatError, + shell, + type CommandMessage, + type SlashMessage +} from '#lib'; export default class ReloadCommand extends BushCommand { public constructor() { @@ -22,19 +31,18 @@ export default class ReloadCommand extends BushCommand { ownerOnly: true, typing: true, slash: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [] }); } public override async exec(message: CommandMessage | SlashMessage /* args: { fast: ArgType<'flag'> } */) { - if (!message.author.isOwner()) - return await message.util.reply(`${util.emojis.error} Only my developers can run this command.`); + if (!message.author.isOwner()) return await message.util.reply(`${emojis.error} Only my developers can run this command.`); let output: { stdout: string; stderr: string }; try { const s = new Date(); - output = await util.shell(`yarn build:${/* args.fast ? 'esbuild' : */ 'tsc'}`); + output = await shell(`yarn build:${/* args.fast ? 'esbuild' : */ 'tsc'}`); await Promise.all([ client.commandHandler.reloadAll(), client.listenerHandler.reloadAll(), @@ -46,9 +54,7 @@ export default class ReloadCommand extends BushCommand { return message.util.send(`🔁 Successfully reloaded! (${new Date().getTime() - s.getTime()}ms)`); } catch (e) { if (output!) void client.logger.error('reloadCommand', output); - return message.util.send( - `An error occurred while reloading:\n${await util.codeblock(util.formatError(e), 2048 - 34, 'js', true)}` - ); + return message.util.send(`An error occurred while reloading:\n${await codeblock(formatError(e), 2048 - 34, 'js', true)}`); } } } diff --git a/src/commands/dev/say.ts b/src/commands/dev/say.ts index a452126..6ec52a1 100644 --- a/src/commands/dev/say.ts +++ b/src/commands/dev/say.ts @@ -1,4 +1,12 @@ -import { AllowedMentions, BushCommand, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; +import { + AllowedMentions, + BushCommand, + clientSendAndPermCheck, + emojis, + type ArgType, + type CommandMessage, + type SlashMessage +} from '#lib'; import { ApplicationCommandOptionType } from 'discord.js'; export default class SayCommand extends BushCommand { @@ -21,15 +29,14 @@ export default class SayCommand extends BushCommand { } ], ownerOnly: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [], slash: true }); } public override async exec(message: CommandMessage | SlashMessage, args: { content: ArgType<'string'> }) { - if (!message.author.isOwner()) - return await message.util.reply(`${util.emojis.error} Only my developers can run this command.`); + if (!message.author.isOwner()) return await message.util.reply(`${emojis.error} Only my developers can run this command.`); await message.delete().catch(() => null); await message.util.send({ content: args.content, allowedMentions: AllowedMentions.none() }).catch(() => null); @@ -38,7 +45,7 @@ export default class SayCommand extends BushCommand { public override async execSlash(message: SlashMessage, args: { content: string }) { if (!client.config.owners.includes(message.author.id)) { return await message.interaction.reply({ - content: `${util.emojis.error} Only my developers can run this command.`, + content: `${emojis.error} Only my developers can run this command.`, ephemeral: true }); } diff --git a/src/commands/dev/servers.ts b/src/commands/dev/servers.ts index e99bcda..28a4e5d 100644 --- a/src/commands/dev/servers.ts +++ b/src/commands/dev/servers.ts @@ -1,4 +1,13 @@ -import { BushCommand, ButtonPaginator, type CommandMessage, type SlashMessage } from '#lib'; +import { + BushCommand, + ButtonPaginator, + chunk, + clientSendAndPermCheck, + colors, + format, + type CommandMessage, + type SlashMessage +} from '#lib'; import { stripIndent } from '#tags'; import { type APIEmbed, type Guild } from 'discord.js'; @@ -10,7 +19,7 @@ export default class ServersCommand extends BushCommand { description: 'Displays all the severs the bot is in', usage: ['servers'], examples: ['servers'], - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [], ownerOnly: true }); @@ -18,13 +27,13 @@ export default class ServersCommand extends BushCommand { public override async exec(message: CommandMessage | SlashMessage) { const guilds = [...client.guilds.cache.sort((a, b) => (a.memberCount < b.memberCount ? 1 : -1)).values()]; - const chunkedGuilds: Guild[][] = util.chunk(guilds, 10); + const chunkedGuilds: Guild[][] = chunk(guilds, 10); const embeds: APIEmbed[] = chunkedGuilds.map((chunk) => { return { title: `Server List [\`${guilds.length.toLocaleString()}\`]`, - color: util.colors.default, + color: colors.default, fields: chunk.map((guild) => ({ - name: util.format.input(guild.name), + name: format.input(guild.name), value: stripIndent` **ID:** ${guild.id} **Owner:** ${client.users.cache.has(guild.ownerId) ? client.users.cache.get(guild.ownerId)!.tag : guild.ownerId} diff --git a/src/commands/dev/sh.ts b/src/commands/dev/sh.ts index 8c62f5d..f7c17bd 100644 --- a/src/commands/dev/sh.ts +++ b/src/commands/dev/sh.ts @@ -1,8 +1,18 @@ -import { ArgType, BushCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { + ArgType, + BushCommand, + clientSendAndPermCheck, + codeblock, + colors, + emojis, + formatError, + type CommandMessage, + type SlashMessage +} from '#lib'; import assert from 'assert'; import chalk from 'chalk'; import { exec } from 'child_process'; -import { ApplicationCommandOptionType, EmbedBuilder, Util } from 'discord.js'; +import { ApplicationCommandOptionType, cleanCodeBlockContent, EmbedBuilder } from 'discord.js'; import { promisify } from 'util'; assert(chalk); @@ -11,7 +21,7 @@ const sh = promisify(exec); const clean = (text: string | any) => { chalk.toString; if (typeof text === 'string') { - return (text = Util.cleanCodeBlockContent(text)); + return (text = cleanCodeBlockContent(text)); } else return text; }; @@ -35,24 +45,24 @@ export default class ShCommand extends BushCommand { } ], ownerOnly: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [] }); } public override async exec(message: CommandMessage | SlashMessage, args: { command: ArgType<'string'> }) { if (!client.config.owners.includes(message.author.id)) - return await message.util.reply(`${util.emojis.error} Only my developers can run this command.`); + return await message.util.reply(`${emojis.error} Only my developers can run this command.`); const input = clean(args.command); const embed = new EmbedBuilder() - .setColor(util.colors.gray) + .setColor(colors.gray) .setFooter({ text: message.author.tag, iconURL: message.author.avatarURL() ?? undefined }) .setTimestamp() .setTitle('Shell Command') .addFields([ - { name: '📥 Input', value: await util.codeblock(input, 1024, 'sh', true) }, - { name: 'Running', value: util.emojis.loading } + { name: '📥 Input', value: await codeblock(input, 1024, 'sh', true) }, + { name: 'Running', value: emojis.loading } ]); await message.util.reply({ embeds: [embed] }); @@ -69,20 +79,14 @@ export default class ShCommand extends BushCommand { const stdout = /* strip( */ clean(output.stdout); /* ) */ const stderr = /* strip( */ clean(output.stderr); /* ) */ - embed - .setTitle(`${util.emojis.successFull} Executed command successfully.`) - .setColor(util.colors.success) - .spliceFields(1, 1); + embed.setTitle(`${emojis.successFull} Executed command successfully.`).setColor(colors.success).spliceFields(1, 1); - if (stdout) embed.addFields([{ name: '📤 stdout', value: await util.codeblock(stdout, 1024, 'ansi', true) }]); - if (stderr) embed.addFields([{ name: '📤 stderr', value: await util.codeblock(stderr, 1024, 'ansi', true) }]); + if (stdout) embed.addFields([{ name: '📤 stdout', value: await codeblock(stdout, 1024, 'ansi', true) }]); + if (stderr) embed.addFields([{ name: '📤 stderr', value: await codeblock(stderr, 1024, 'ansi', true) }]); } catch (e) { - embed - .setTitle(`${util.emojis.errorFull} An error occurred while executing.`) - .setColor(util.colors.error) - .spliceFields(1, 1); + embed.setTitle(`${emojis.errorFull} An error occurred while executing.`).setColor(colors.error).spliceFields(1, 1); - embed.addFields([{ name: '📤 Output', value: await util.codeblock(util.formatError(e, true), 1024, 'ansi', true) }]); + embed.addFields([{ name: '📤 Output', value: await codeblock(formatError(e, true), 1024, 'ansi', true) }]); } await message.util.edit({ embeds: [embed] }); } diff --git a/src/commands/dev/superUser.ts b/src/commands/dev/superUser.ts index 6a2b745..3de04bf 100644 --- a/src/commands/dev/superUser.ts +++ b/src/commands/dev/superUser.ts @@ -1,4 +1,13 @@ -import { BushCommand, type ArgType, type CommandMessage } from '#lib'; +import { + BushCommand, + clientSendAndPermCheck, + emojis, + format, + getShared, + insertOrRemoveFromShared, + type ArgType, + type CommandMessage +} from '#lib'; import { type ArgumentGeneratorReturn, type ArgumentTypeCasterReturn } from 'discord-akairo'; export default class SuperUserCommand extends BushCommand { @@ -9,7 +18,7 @@ export default class SuperUserCommand extends BushCommand { description: 'A command to manage superusers.', usage: ['superuser '], examples: ['superuser add IRONM00N'], - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [], ownerOnly: true, helpArgs: [ @@ -54,29 +63,28 @@ export default class SuperUserCommand extends BushCommand { } public override async exec(message: CommandMessage, args: { action: 'add' | 'remove'; user: ArgType<'user'> }) { - if (!message.author.isOwner()) - return await message.util.reply(`${util.emojis.error} Only my developers can run this command.`); + if (!message.author.isOwner()) return await message.util.reply(`${emojis.error} Only my developers can run this command.`); - const superUsers: string[] = util.getShared('superUsers'); + const superUsers: string[] = getShared('superUsers'); if (args.action === 'add' ? superUsers.includes(args.user.id) : !superUsers.includes(args.user.id)) return message.util.reply( - `${util.emojis.warn} ${util.format.input(args.user.tag)} is ${args.action === 'add' ? 'already' : 'not'} a superuser.` + `${emojis.warn} ${format.input(args.user.tag)} is ${args.action === 'add' ? 'already' : 'not'} a superuser.` ); - const success = await util.insertOrRemoveFromShared(args.action, 'superUsers', args.user.id).catch(() => false); + const success = await insertOrRemoveFromShared(args.action, 'superUsers', args.user.id).catch(() => false); if (success) { return await message.util.reply( - `${util.emojis.success} ${args.action == 'remove' ? '' : 'made'} ${util.format.input(args.user.tag)} ${ + `${emojis.success} ${args.action == 'remove' ? '' : 'made'} ${format.input(args.user.tag)} ${ args.action == 'remove' ? 'is no longer ' : '' }a superuser.` ); } else { return await message.util.reply( - `${util.emojis.error} There was an error ${args.action == 'remove' ? `removing` : 'making'} ${util.format.input( - args.user.tag - )} ${args.action == 'remove' ? `from` : 'to'} the superuser list.` + `${emojis.error} There was an error ${args.action == 'remove' ? `removing` : 'making'} ${format.input(args.user.tag)} ${ + args.action == 'remove' ? `from` : 'to' + } the superuser list.` ); } } diff --git a/src/commands/dev/syncAutomod.ts b/src/commands/dev/syncAutomod.ts index 9954e70..c78e6c0 100644 --- a/src/commands/dev/syncAutomod.ts +++ b/src/commands/dev/syncAutomod.ts @@ -1,4 +1,4 @@ -import { BushCommand, Shared, type CommandMessage, type SlashMessage } from '#lib'; +import { BushCommand, clientSendAndPermCheck, emojis, Shared, type CommandMessage, type SlashMessage } from '#lib'; import got from 'got'; import typescript from 'typescript'; import { NodeVM } from 'vm2'; @@ -13,14 +13,14 @@ export default class SyncAutomodCommand extends BushCommand { examples: ['sync-automod'], slash: false, hidden: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [] }); } public override async exec(message: CommandMessage | SlashMessage) { if (!message.author.isOwner() && message.author.id !== '497789163555389441') - return await message.util.reply(`${util.emojis.error} Only a very select few may use this command.`); + return await message.util.reply(`${emojis.error} Only a very select few may use this command.`); const badLinks = (await got.get('https://raw.githubusercontent.com/NotEnoughUpdates/bush-bot/master/src/lib/badlinks.ts')) .body; @@ -38,6 +38,6 @@ export default class SyncAutomodCommand extends BushCommand { row.badWords = badWordsParsed; await row.save(); - return await message.util.reply(`${util.emojis.success} Automod info synced.`); + return await message.util.reply(`${emojis.success} Automod info synced.`); } } diff --git a/src/commands/dev/test.ts b/src/commands/dev/test.ts index d54d544..9491d19 100644 --- a/src/commands/dev/test.ts +++ b/src/commands/dev/test.ts @@ -1,4 +1,13 @@ -import { BushCommand, ButtonPaginator, OptArgType, Shared, type CommandMessage } from '#lib'; +import { + BushCommand, + ButtonPaginator, + clientSendAndPermCheck, + colors, + emojis, + OptArgType, + Shared, + type CommandMessage +} from '#lib'; import { ActionRowBuilder, ButtonBuilder, @@ -33,7 +42,7 @@ export default class TestCommand extends BushCommand { } ], superUserOnly: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [] }); } @@ -65,7 +74,7 @@ export default class TestCommand extends BushCommand { const embed = new EmbedBuilder() .addFields([{ name: 'Field Name', value: 'Field Content' }]) .setAuthor({ name: 'Author', iconURL: 'https://www.w3schools.com/w3css/img_snowtops.jpg', url: 'https://google.com/' }) - .setColor(message.member?.displayColor ?? util.colors.default) + .setColor(message.member?.displayColor ?? colors.default) .setDescription('Description') .setFooter({ text: 'Footer', iconURL: message.author.avatarURL() ?? undefined }) .setURL('https://duckduckgo.com/') @@ -106,12 +115,12 @@ export default class TestCommand extends BushCommand { const fields = Array(25) .fill(0) .map((_, i) => ({ name: `Field ${i}`, value: 'Field Value' })); - const c = util.colors; const o = { description, author, footer, fields, time: Date.now() }; - const colors = [c.red, c.orange, c.gold, c.yellow, c.green, c.darkGreen, c.aqua, c.blue, c.purple, c.pink]; + const c = colors; + const embedColors = [c.red, c.orange, c.gold, c.yellow, c.green, c.darkGreen, c.aqua, c.blue, c.purple, c.pink]; - const embeds = colors.map((c, i) => ({ ...o, title: `Embed Title ${i}`, color: c })); + const embeds = embedColors.map((c, i) => ({ ...o, title: `Embed Title ${i}`, color: c })); const ButtonRows: ActionRowBuilder[] = []; for (let a = 1; a <= 5; a++) { @@ -125,7 +134,7 @@ export default class TestCommand extends BushCommand { } return await message.util.reply({ content: 'this is content', components: ButtonRows, embeds }); } else if (['delete slash commands'].includes(args.feature?.toLowerCase())) { - if (!message.guild) return await message.util.reply(`${util.emojis.error} This test can only be run in a guild.`); + if (!message.guild) return await message.util.reply(`${emojis.error} This test can only be run in a guild.`); await client.guilds.fetch(); const promises: Promise>[] = []; client.guilds.cache.each((guild) => { @@ -136,16 +145,16 @@ export default class TestCommand extends BushCommand { await client.application!.commands.fetch(); await client.application!.commands.set([]); - return await message.util.reply(`${util.emojis.success} Removed guild commands and global commands.`); + return await message.util.reply(`${emojis.success} Removed guild commands and global commands.`); } else if (['drop down', 'drop downs', 'select menu', 'select menus'].includes(args.feature?.toLowerCase())) { - return message.util.reply(`${util.emojis.error} no`); + return message.util.reply(`${emojis.error} no`); } else if (['sync automod'].includes(args.feature?.toLowerCase())) { const row = (await Shared.findByPk(0))!; row.badLinks = badLinksArray; row.badLinksSecret = badLinksSecretArray; row.badWords = badWords; await row.save(); - return await message.util.reply(`${util.emojis.success} Synced automod.`); + return await message.util.reply(`${emojis.success} Synced automod.`); } else if (['modal'].includes(args.feature?.toLowerCase())) { const m = await message.util.reply({ content: 'Click for modal', diff --git a/src/commands/fun/coinFlip.ts b/src/commands/fun/coinFlip.ts index fea5cb5..3adf7f2 100644 --- a/src/commands/fun/coinFlip.ts +++ b/src/commands/fun/coinFlip.ts @@ -1,4 +1,4 @@ -import { BushCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { BushCommand, clientSendAndPermCheck, type CommandMessage, type SlashMessage } from '#lib'; export default class CoinFlipCommand extends BushCommand { public constructor() { @@ -8,7 +8,7 @@ export default class CoinFlipCommand extends BushCommand { description: 'Flip a virtual coin.', usage: ['coinflip'], examples: ['coinflip'], - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [], slash: true }); diff --git a/src/commands/fun/dice.ts b/src/commands/fun/dice.ts index b2bc7e4..e7e5927 100644 --- a/src/commands/fun/dice.ts +++ b/src/commands/fun/dice.ts @@ -1,4 +1,4 @@ -import { BushCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { BushCommand, clientSendAndPermCheck, type CommandMessage, type SlashMessage } from '#lib'; export default class DiceCommand extends BushCommand { public constructor() { @@ -8,7 +8,7 @@ export default class DiceCommand extends BushCommand { description: 'Roll virtual dice.', usage: ['dice'], examples: ['dice'], - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [], slash: true }); diff --git a/src/commands/fun/eightBall.ts b/src/commands/fun/eightBall.ts index 66fcc45..eb5aee8 100644 --- a/src/commands/fun/eightBall.ts +++ b/src/commands/fun/eightBall.ts @@ -1,4 +1,4 @@ -import { BushCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { BushCommand, clientSendAndPermCheck, type CommandMessage, type SlashMessage } from '#lib'; import { ApplicationCommandOptionType } from 'discord.js'; export default class EightBallCommand extends BushCommand { @@ -21,7 +21,7 @@ export default class EightBallCommand extends BushCommand { } ], slash: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [] }); } diff --git a/src/commands/fun/minesweeper.ts b/src/commands/fun/minesweeper.ts index d25cb5d..c2fdccf 100644 --- a/src/commands/fun/minesweeper.ts +++ b/src/commands/fun/minesweeper.ts @@ -1,4 +1,12 @@ -import { BushCommand, OptArgType, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; +import { + BushCommand, + clientSendAndPermCheck, + emojis, + OptArgType, + type ArgType, + type CommandMessage, + type SlashMessage +} from '#lib'; import { Minesweeper } from '@notenoughupdates/discord.js-minesweeper'; import assert from 'assert'; import { ApplicationCommandOptionType } from 'discord.js'; @@ -63,7 +71,7 @@ export default class MinesweeperCommand extends BushCommand { } ], slash: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m), + clientPermissions: (m) => clientSendAndPermCheck(m), userPermissions: [] }); } @@ -95,14 +103,14 @@ export default class MinesweeperCommand extends BushCommand { if (args.rows * args.columns <= args.mines * 2) return message.util.reply( - `${util.emojis.error} The number of roles multiplied by the number of columns must be greater than or equal to the number of mines multiplied by two.` + `${emojis.error} The number of roles multiplied by the number of columns must be greater than or equal to the number of mines multiplied by two.` ); - if (!matrix) return await message.util.reply(`${util.emojis.error} Something went wrong.`); + if (!matrix) return await message.util.reply(`${emojis.error} Something went wrong.`); const res = matrix.toString().replaceAll(':zero:', ':blue_square:'); - if (res.length > 2000) return message.util.reply(`${util.emojis.error} The minesweeper generated is over 2,000 characters.`); + if (res.length > 2000) return message.util.reply(`${emojis.error} The minesweeper generated is over 2,000 characters.`); return await message.util.reply(res); } diff --git a/src/commands/info/avatar.ts b/src/commands/info/avatar.ts index 544c30a..3eae98c 100644 --- a/src/commands/info/avatar.ts +++ b/src/commands/info/avatar.ts @@ -1,4 +1,4 @@ -import { BushCommand, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; +import { Arg, BushCommand, clientSendAndPermCheck, colors, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; import { ApplicationCommandOptionType, EmbedBuilder, GuildMember, PermissionFlagsBits } from 'discord.js'; export default class AvatarCommand extends BushCommand { @@ -13,7 +13,7 @@ export default class AvatarCommand extends BushCommand { { id: 'user', description: 'The user you would like to find the avatar of.', - type: util.arg.union('member', 'globalUser'), + type: Arg.union('member', 'globalUser'), readableType: 'member|user', prompt: 'Who would you like to see the avatar of?', retry: '{error} Choose a valid user.', @@ -21,7 +21,7 @@ export default class AvatarCommand extends BushCommand { slashType: ApplicationCommandOptionType.User } ], - clientPermissions: (m) => util.clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true), + clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true), userPermissions: [], slash: true }); @@ -37,7 +37,7 @@ export default class AvatarCommand extends BushCommand { const guildAvatar = member?.avatarURL(params); - const embed = new EmbedBuilder().setTimestamp().setColor(util.colors.default).setTitle(`${user.tag}'s Avatar`); + const embed = new EmbedBuilder().setTimestamp().setColor(colors.default).setTitle(`${user.tag}'s Avatar`); guildAvatar ? embed.setImage(guildAvatar).setThumbnail(user.avatarURL(params) ?? defaultAvatar) : embed.setImage(user.avatarURL(params) ?? defaultAvatar); diff --git a/src/commands/info/botInfo.ts b/src/commands/info/botInfo.ts index 4a8a36a..decbe04 100644 --- a/src/commands/info/botInfo.ts +++ b/src/commands/info/botInfo.ts @@ -1,4 +1,13 @@ -import { BushCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { + BushCommand, + clientSendAndPermCheck, + colors, + humanizeDuration, + mapIDs, + shell, + type CommandMessage, + type SlashMessage +} from '#lib'; import assert from 'assert'; import { EmbedBuilder, PermissionFlagsBits, version as discordJSVersion } from 'discord.js'; import * as os from 'os'; @@ -15,7 +24,7 @@ export default class BotInfoCommand extends BushCommand { usage: ['bot-info'], examples: ['bot-info'], slash: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true), + clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true), userPermissions: [] }); } @@ -35,14 +44,14 @@ export default class BotInfoCommand extends BushCommand { haiku = 'Haiku' } - const developers = (await util.mapIDs(client.config.owners)).map((u) => u?.tag).join('\n'); - const currentCommit = (await util.shell('