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/arguments/contentWithDuration.ts | 4 +- src/arguments/discordEmoji.ts | 4 +- src/arguments/duration.ts | 4 +- src/arguments/durationSeconds.ts | 4 +- src/arguments/messageLink.ts | 4 +- src/arguments/roleWithDuration.ts | 6 +- src/arguments/snowflake.ts | 4 +- src/bot.ts | 3 +- 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 +- src/config/example-options.ts | 42 - src/context-menu-commands/user/modlog.ts | 6 +- src/context-menu-commands/user/userInfo.ts | 3 +- src/inhibitors/blacklist/channelGlobalBlacklist.ts | 2 +- src/inhibitors/blacklist/channelGuildBlacklist.ts | 2 +- src/inhibitors/blacklist/guildBlacklist.ts | 2 +- src/inhibitors/blacklist/userGlobalBlacklist.ts | 2 +- src/inhibitors/blacklist/userGuildBlacklist.ts | 2 +- src/inhibitors/checks/fatal.ts | 2 +- src/inhibitors/checks/guildUnavailable.ts | 2 +- src/inhibitors/command/dm.ts | 2 +- src/inhibitors/command/globalDisabledCommand.ts | 2 +- src/inhibitors/command/guild.ts | 2 +- src/inhibitors/command/guildDisabledCommand.ts | 2 +- src/inhibitors/command/nsfw.ts | 2 +- src/inhibitors/command/owner.ts | 2 +- src/inhibitors/command/restrictedChannel.ts | 2 +- src/inhibitors/command/restrictedGuild.ts | 2 +- src/inhibitors/command/superUser.ts | 2 +- src/lib/common/AutoMod.ts | 51 +- src/lib/common/ButtonPaginator.ts | 47 +- src/lib/common/ConfirmationPrompt.ts | 27 +- src/lib/common/DeleteButton.ts | 27 +- src/lib/common/HighlightManager.ts | 16 +- src/lib/common/Sentry.ts | 2 +- src/lib/common/util/Arg.ts | 269 +++-- src/lib/common/util/Format.ts | 187 +-- src/lib/common/util/Moderation.ts | 517 ++++----- src/lib/extensions/discord-akairo/BushClient.ts | 52 +- .../extensions/discord-akairo/BushClientUtil.ts | 1187 -------------------- src/lib/extensions/discord-akairo/BushInhibitor.ts | 8 +- src/lib/extensions/discord-akairo/BushListener.ts | 15 +- src/lib/extensions/discord-akairo/BushTask.ts | 2 +- src/lib/extensions/discord.js/ExtendedGuild.ts | 33 +- .../extensions/discord.js/ExtendedGuildMember.ts | 26 +- src/lib/extensions/global.ts | 7 +- src/lib/index.ts | 19 +- src/lib/utils/BushConstants.ts | 813 +++++++------- src/lib/utils/BushLogger.ts | 256 ++--- src/lib/utils/BushUtils.ts | 1058 +++++++++++++++++ src/lib/utils/Config.ts | 93 -- src/listeners/bush/appealListener.ts | 10 +- src/listeners/bush/joinAutoBan.ts | 16 +- src/listeners/bush/supportThread.ts | 6 +- src/listeners/bush/userUpdateAutoBan.ts | 16 +- src/listeners/client/akairoDebug.ts | 2 +- src/listeners/client/dcjsDebug.ts | 2 +- src/listeners/client/dcjsError.ts | 2 +- src/listeners/client/dcjsWarn.ts | 2 +- src/listeners/client/ready.ts | 2 +- src/listeners/commands/commandBlocked.ts | 73 +- src/listeners/commands/commandCooldown.ts | 2 +- src/listeners/commands/commandError.ts | 38 +- src/listeners/commands/commandLocked.ts | 6 +- .../commands/commandMissingPermissions.ts | 16 +- src/listeners/commands/commandStarted.ts | 2 +- src/listeners/commands/messageBlocked.ts | 2 +- src/listeners/commands/slashBlocked.ts | 2 +- src/listeners/commands/slashCommandError.ts | 2 +- src/listeners/commands/slashMissingPermissions.ts | 2 +- src/listeners/commands/slashNotFound.ts | 2 +- src/listeners/commands/slashStarted.ts | 2 +- .../contextCommands/contextCommandBlocked.ts | 14 +- .../contextCommands/contextCommandError.ts | 16 +- .../contextCommands/contextCommandNotFound.ts | 2 +- .../contextCommands/contextCommandStarted.ts | 2 +- src/listeners/guild-custom/bushLockdown.ts | 8 +- src/listeners/guild-custom/bushUnlockdown.ts | 8 +- src/listeners/guild/guildCreate.ts | 10 +- src/listeners/guild/guildDelete.ts | 10 +- src/listeners/guild/guildMemberAdd.ts | 12 +- src/listeners/guild/guildMemberRemove.ts | 16 +- src/listeners/guild/joinRoles.ts | 18 +- src/listeners/guild/syncUnbanPunishmentModel.ts | 2 +- src/listeners/interaction/interactionCreate.ts | 18 +- src/listeners/member-custom/bushBan.ts | 8 +- src/listeners/member-custom/bushBlock.ts | 10 +- src/listeners/member-custom/bushKick.ts | 6 +- src/listeners/member-custom/bushLevelUpdate.ts | 6 +- src/listeners/member-custom/bushMute.ts | 8 +- src/listeners/member-custom/bushPunishRole.ts | 8 +- .../member-custom/bushPunishRoleRemove.ts | 6 +- src/listeners/member-custom/bushPurge.ts | 10 +- src/listeners/member-custom/bushRemoveTimeout.ts | 6 +- src/listeners/member-custom/bushTimeout.ts | 10 +- src/listeners/member-custom/bushUnban.ts | 6 +- src/listeners/member-custom/bushUnblock.ts | 6 +- src/listeners/member-custom/bushUnmute.ts | 6 +- src/listeners/member-custom/bushUpdateModlog.ts | 10 +- src/listeners/member-custom/bushUpdateSettings.ts | 10 +- src/listeners/member-custom/bushWarn.ts | 6 +- src/listeners/member-custom/massBan.ts | 11 +- src/listeners/member-custom/massEvidence.ts | 8 +- src/listeners/message/autoPublisher.ts | 2 +- src/listeners/message/automodCreate.ts | 2 +- src/listeners/message/automodUpdate.ts | 2 +- src/listeners/message/blacklistedFile.ts | 2 +- src/listeners/message/boosterMessage.ts | 2 +- src/listeners/message/directMessage.ts | 10 +- src/listeners/message/highlight.ts | 2 +- src/listeners/message/level.ts | 6 +- src/listeners/message/quoteCreate.ts | 6 +- src/listeners/message/quoteEdit.ts | 2 +- src/listeners/message/verbose.ts | 2 +- src/listeners/other/consoleListener.ts | 3 +- src/listeners/other/exit.ts | 2 +- src/listeners/other/promiseRejection.ts | 10 +- src/listeners/other/uncaughtException.ts | 6 +- src/listeners/other/warning.ts | 8 +- src/listeners/rest/rateLimit.ts | 2 +- .../track-manual-punishments/modlogSyncBan.ts | 12 +- .../track-manual-punishments/modlogSyncKick.ts | 12 +- .../track-manual-punishments/modlogSyncTimeout.ts | 12 +- .../track-manual-punishments/modlogSyncUnban.ts | 12 +- src/listeners/ws/INTERACTION_CREATE.ts | 16 +- src/tasks/cpuUsage.ts | 8 +- src/tasks/handleReminders.ts | 8 +- src/tasks/removeExpiredPunishements.ts | 6 +- src/tasks/updateCache.ts | 4 +- src/tasks/updateHighlightCache.ts | 2 +- src/tasks/updatePriceItemCache.ts | 2 +- src/tasks/updateStats.ts | 2 +- 221 files changed, 3846 insertions(+), 3653 deletions(-) delete mode 100644 src/config/example-options.ts delete mode 100644 src/lib/extensions/discord-akairo/BushClientUtil.ts create mode 100644 src/lib/utils/BushUtils.ts delete mode 100644 src/lib/utils/Config.ts (limited to 'src') diff --git a/src/arguments/contentWithDuration.ts b/src/arguments/contentWithDuration.ts index e92997a..0efba39 100644 --- a/src/arguments/contentWithDuration.ts +++ b/src/arguments/contentWithDuration.ts @@ -1,5 +1,5 @@ -import type { BushArgumentTypeCaster, ParsedDuration } from '#lib'; +import { parseDuration, type BushArgumentTypeCaster, type ParsedDuration } from '#lib'; export const contentWithDuration: BushArgumentTypeCaster> = async (_, phrase) => { - return client.util.parseDuration(phrase); + return parseDuration(phrase); }; diff --git a/src/arguments/discordEmoji.ts b/src/arguments/discordEmoji.ts index 57710e4..92d6502 100644 --- a/src/arguments/discordEmoji.ts +++ b/src/arguments/discordEmoji.ts @@ -1,9 +1,9 @@ -import type { BushArgumentTypeCaster } from '#lib'; +import { regex, type BushArgumentTypeCaster } from '#lib'; import type { Snowflake } from 'discord.js'; export const discordEmoji: BushArgumentTypeCaster = (_, phrase) => { if (!phrase) return null; - const validEmoji: RegExpExecArray | null = client.consts.regex.discordEmoji.exec(phrase); + const validEmoji: RegExpExecArray | null = regex.discordEmoji.exec(phrase); if (!validEmoji || !validEmoji.groups) return null; return { name: validEmoji.groups.name, id: validEmoji.groups.id }; }; diff --git a/src/arguments/duration.ts b/src/arguments/duration.ts index ffd9159..09dd3d5 100644 --- a/src/arguments/duration.ts +++ b/src/arguments/duration.ts @@ -1,5 +1,5 @@ -import type { BushArgumentTypeCaster } from '#lib'; +import { parseDuration, type BushArgumentTypeCaster } from '#lib'; export const duration: BushArgumentTypeCaster = (_, phrase) => { - return client.util.parseDuration(phrase).duration; + return parseDuration(phrase).duration; }; diff --git a/src/arguments/durationSeconds.ts b/src/arguments/durationSeconds.ts index 432fd8c..d8d6749 100644 --- a/src/arguments/durationSeconds.ts +++ b/src/arguments/durationSeconds.ts @@ -1,6 +1,6 @@ -import type { BushArgumentTypeCaster } from '#lib'; +import { parseDuration, type BushArgumentTypeCaster } from '#lib'; export const durationSeconds: BushArgumentTypeCaster = (_, phrase) => { phrase += 's'; - return client.util.parseDuration(phrase).duration; + return parseDuration(phrase).duration; }; diff --git a/src/arguments/messageLink.ts b/src/arguments/messageLink.ts index 457410e..a473485 100644 --- a/src/arguments/messageLink.ts +++ b/src/arguments/messageLink.ts @@ -1,8 +1,8 @@ -import type { BushArgumentTypeCaster } from '#lib'; +import { BushArgumentTypeCaster, regex } from '#lib'; import type { Message } from 'discord.js'; export const messageLink: BushArgumentTypeCaster> = async (_, phrase) => { - const match = new RegExp(client.consts.regex.messageLink).exec(phrase); + const match = new RegExp(regex.messageLink).exec(phrase); if (!match || !match.groups) return null; const { guild_id, channel_id, message_id } = match.groups; diff --git a/src/arguments/roleWithDuration.ts b/src/arguments/roleWithDuration.ts index e338b79..b97f205 100644 --- a/src/arguments/roleWithDuration.ts +++ b/src/arguments/roleWithDuration.ts @@ -1,12 +1,12 @@ -import type { BushArgumentTypeCaster } from '#lib'; +import { Arg, BushArgumentTypeCaster, parseDuration } from '#lib'; import type { Role } from 'discord.js'; export const roleWithDuration: BushArgumentTypeCaster> = async (message, phrase) => { // eslint-disable-next-line prefer-const - let { duration, content } = client.util.parseDuration(phrase); + let { duration, content } = parseDuration(phrase); if (content === null || content === undefined) return null; content = content.trim(); - const role = await util.arg.cast('role', message, content); + const role = await Arg.cast('role', message, content); if (!role) return null; return { duration, role }; }; diff --git a/src/arguments/snowflake.ts b/src/arguments/snowflake.ts index dc83909..b98a20f 100644 --- a/src/arguments/snowflake.ts +++ b/src/arguments/snowflake.ts @@ -1,8 +1,8 @@ -import type { BushArgumentTypeCaster } from '#lib'; +import { BushArgumentTypeCaster, regex } from '#lib'; import type { Snowflake } from 'discord.js'; export const snowflake: BushArgumentTypeCaster = (_, phrase) => { if (!phrase) return null; - if (client.consts.regex.snowflake.test(phrase)) return phrase; + if (regex.snowflake.test(phrase)) return phrase; return null; }; diff --git a/src/bot.ts b/src/bot.ts index 752075b..ed0a33f 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -5,7 +5,7 @@ init(); const { dirname } = await import('path'); const { fileURLToPath } = await import('url'); -const { default: config } = await import('./config/options.js'); +const { default: config } = await import('../config/options.js'); const { Sentry } = await import('./lib/common/Sentry.js'); const { BushClient } = await import('./lib/index.js'); @@ -14,7 +14,6 @@ if (!isDry) new Sentry(dirname(fileURLToPath(import.meta.url)) || process.cwd()) BushClient.extendStructures(); const client = new BushClient(config); global.client = client; -global.util = client.util; if (!isDry) await client.dbPreInit(); await client.init(); if (isDry) { 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( - `$