diff options
| author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-06-17 20:03:05 -0400 |
|---|---|---|
| committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-06-17 20:03:05 -0400 |
| commit | e1c613829950a534d9f45c00a033b83575be3b3c (patch) | |
| tree | 2de1e5231217211ae4087c46cc74dc46c584507a /src/commands | |
| parent | 0e87bbd3940d89defcb04926587b35c8f4d1947f (diff) | |
| download | tanzanite-e1c613829950a534d9f45c00a033b83575be3b3c.tar.gz tanzanite-e1c613829950a534d9f45c00a033b83575be3b3c.tar.bz2 tanzanite-e1c613829950a534d9f45c00a033b83575be3b3c.zip | |
remove global client variable
Diffstat (limited to 'src/commands')
47 files changed, 169 insertions, 176 deletions
diff --git a/src/commands/admin/channelPermissions.ts b/src/commands/admin/channelPermissions.ts index 12245a9..15a1128 100644 --- a/src/commands/admin/channelPermissions.ts +++ b/src/commands/admin/channelPermissions.ts @@ -89,7 +89,7 @@ export default class ChannelPermissionsCommand extends BushCommand { { reason: 'Changing overwrites for mass channel perms command' } ); } catch (e) { - void client.console.error('channelPermissions', formatError(e, false)); + void this.client.console.error('channelPermissions', formatError(e, false)); failedChannels.push(channel); } } diff --git a/src/commands/config/_customAutomodPhrases.ts b/src/commands/config/_customAutomodPhrases.ts index d60688c..0b571e5 100644 --- a/src/commands/config/_customAutomodPhrases.ts +++ b/src/commands/config/_customAutomodPhrases.ts @@ -1,4 +1,4 @@ -// import { BushCommand, type ArgType, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; +// import { BushCommand, clientSendAndPermCheck, type ArgType, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; // import { ApplicationCommandOptionType, PermissionFlagsBits } from 'discord.js'; // export default class CustomAutomodPhrasesCommand extends BushCommand { diff --git a/src/commands/config/blacklist.ts b/src/commands/config/blacklist.ts index 80acd0b..6768a1c 100644 --- a/src/commands/config/blacklist.ts +++ b/src/commands/config/blacklist.ts @@ -6,8 +6,6 @@ import { clientSendAndPermCheck, emojis, format, - getGlobal, - setGlobal, type ArgType, type CommandMessage, type SlashMessage @@ -83,10 +81,10 @@ export default class BlacklistCommand extends BushCommand { if (!global) assert(message.inGuild()); const blacklistedUsers = global - ? getGlobal('blacklistedUsers') + ? this.client.utils.getGlobal('blacklistedUsers') : (await message.guild!.getSetting('blacklistedChannels')) ?? []; const blacklistedChannels = global - ? getGlobal('blacklistedChannels') + ? this.client.utils.getGlobal('blacklistedChannels') : (await message.guild!.getSetting('blacklistedUsers')) ?? []; if (action === 'toggle') { action = blacklistedUsers.includes(targetID) || blacklistedChannels.includes(targetID) ? 'unblacklist' : 'blacklist'; @@ -100,7 +98,7 @@ export default class BlacklistCommand extends BushCommand { const key = target instanceof User ? 'blacklistedUsers' : 'blacklistedChannels'; const success = await (global - ? setGlobal(key, newValue) + ? this.client.utils.setGlobal(key, newValue) : message.guild!.setSetting(key, newValue, message.member as GuildMember) ).catch(() => false); diff --git a/src/commands/config/config.ts b/src/commands/config/config.ts index f0db467..66e10b6 100644 --- a/src/commands/config/config.ts +++ b/src/commands/config/config.ts @@ -6,9 +6,7 @@ import { emojis, GuildNoArraySetting, guildSettingsObj, - inspectAndRedact, oxford, - prefix, settingsArr, type ArgType, type CommandMessage, @@ -284,7 +282,7 @@ export default class ConfigCommand extends BushCommand { }); collector.on('collect', async (interaction: MessageComponentInteraction) => { - if (interaction.user.id === message.author.id || client.config.owners.includes(interaction.user.id)) { + if (interaction.user.id === message.author.id || this.client.config.owners.includes(interaction.user.id)) { assert(message.inGuild()); switch (interaction.customId) { @@ -346,7 +344,7 @@ export default class ConfigCommand extends BushCommand { const func = ((): ((v: string | any) => string) => { switch (type.replace('-array', '') as BaseSettingTypes) { case 'string': - return (v) => inspectAndRedact(v); + return (v) => this.client.utils.inspectAndRedact(v); case 'channel': return (v) => `<#${v}>`; case 'role': @@ -354,7 +352,7 @@ export default class ConfigCommand extends BushCommand { case 'user': return (v) => `<@${v}>`; case 'custom': - return inspectAndRedact; + return this.client.utils.inspectAndRedact; default: return (v) => v; } @@ -377,7 +375,7 @@ export default class ConfigCommand extends BushCommand { ); settingsEmbed.setFooter({ - text: `Run "${prefix(message)}${message.util.parsed?.alias ?? 'config'} ${ + text: `Run "${this.client.utils.prefix(message)}${message.util.parsed?.alias ?? 'config'} ${ message.util.isSlash ? snakeCase(setting) : setting } ${guildSettingsObj[setting].type.includes('-array') ? 'add/remove' : 'set'} <value>" to set this setting.` }); diff --git a/src/commands/config/disable.ts b/src/commands/config/disable.ts index 4f52b7c..e9866d5 100644 --- a/src/commands/config/disable.ts +++ b/src/commands/config/disable.ts @@ -5,8 +5,6 @@ import { BushCommand, clientSendAndPermCheck, emojis, - getGlobal, - setGlobal, type ArgType, type CommandMessage, type SlashMessage @@ -81,12 +79,14 @@ export default class DisableCommand extends BushCommand { if (DisableCommand.blacklistedCommands.includes(commandID)) return message.util.send(`${emojis.error} the ${commandID} command cannot be disabled.`); - const disabledCommands = global ? getGlobal('disabledCommands') : await message.guild.getSetting('disabledCommands'); + const disabledCommands = global + ? this.client.utils.getGlobal('disabledCommands') + : await message.guild.getSetting('disabledCommands'); if (action === 'toggle') action = disabledCommands.includes(commandID) ? 'disable' : 'enable'; const newValue = addOrRemoveFromArray(action === 'disable' ? 'add' : 'remove', disabledCommands, commandID); const success = global - ? await setGlobal('disabledCommands', newValue).catch(() => false) + ? await this.client.utils.setGlobal('disabledCommands', newValue).catch(() => false) : await message.guild.setSetting('disabledCommands', newValue, message.member!).catch(() => false); if (!success) return await message.util.reply({ diff --git a/src/commands/config/features.ts b/src/commands/config/features.ts index e88f4b7..affcde3 100644 --- a/src/commands/config/features.ts +++ b/src/commands/config/features.ts @@ -51,7 +51,7 @@ export default class FeaturesCommand extends BushCommand { }); collector.on('collect', async (interaction: SelectMenuInteraction) => { - if (interaction.user.id === message.author.id || client.config.owners.includes(interaction.user.id)) { + if (interaction.user.id === message.author.id || this.client.config.owners.includes(interaction.user.id)) { assert(message.inGuild()); const [selected]: GuildFeatures[] = interaction.values as GuildFeatures[]; diff --git a/src/commands/dev/dm.ts b/src/commands/dev/dm.ts index f1e2bce..c1340b1 100644 --- a/src/commands/dev/dm.ts +++ b/src/commands/dev/dm.ts @@ -41,7 +41,7 @@ export default class DMCommand extends BushCommand { args: { user: ArgType<'user'>; content: ArgType<'string'> } ) { try { - await client.users.send(args.user.id, args.content); + await this.client.users.send(args.user.id, args.content); } catch (e) { return message.util.reply(`${emojis.error} There was an error sending ${format.input(args.user.tag)} a dm.`); } diff --git a/src/commands/dev/eval.ts b/src/commands/dev/eval.ts index 239a06a..2be2963 100644 --- a/src/commands/dev/eval.ts +++ b/src/commands/dev/eval.ts @@ -11,7 +11,6 @@ import { getMethods, Global, Guild, - inspectCleanRedactCodeblock, Level, ModLog, Shared, @@ -243,10 +242,11 @@ export default class EvalCommand extends BushCommand { /* eslint-disable @typescript-eslint/no-unused-vars */ const me = message.member, member = message.member, - bot = client, + bot = this.client, + client = this.client, guild = message.guild, channel = message.channel, - config = client.config, + config = this.client.config, members = message.guild?.members, roles = message.guild?.roles; /* eslint-enable @typescript-eslint/no-unused-vars */ @@ -315,7 +315,7 @@ export default class EvalCommand extends BushCommand { options.depth ??= 1; options.getters ??= true; - return inspectCleanRedactCodeblock(obj, language, options); + return this.client.utils.inspectCleanRedactCodeblock(obj, language, options); } } diff --git a/src/commands/dev/javascript.ts b/src/commands/dev/javascript.ts index 7c47f2f..e472a5a 100644 --- a/src/commands/dev/javascript.ts +++ b/src/commands/dev/javascript.ts @@ -3,7 +3,6 @@ import { clientSendAndPermCheck, colors, emojis, - inspectCleanRedactCodeblock, type ArgType, type CommandMessage, type OptArgType, @@ -60,13 +59,13 @@ export default class JavascriptCommand extends BushCommand { } const code = args.code.replace(/[“”]/g, '"').replace(/```*(?:js)?/g, ''); const embed = new EmbedBuilder(); - const input = await inspectCleanRedactCodeblock(code, 'js'); + const input = await this.client.utils.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 inspectCleanRedactCodeblock(rawOutput, 'js', { + const output = await this.client.utils.inspectCleanRedactCodeblock(rawOutput, 'js', { depth: args.sel_depth ?? 0, getters: true, inspectStrings: true, @@ -82,7 +81,7 @@ export default class JavascriptCommand extends BushCommand { embed.setTitle(`${emojis.errorFull} Unable to Evaluate Expression`).setColor(colors.error); embed.addFields([ { name: '📥 Input', value: input }, - { name: '📤 Error', value: await inspectCleanRedactCodeblock(e, 'js', { colors: false }) } + { name: '📤 Error', value: await this.client.utils.inspectCleanRedactCodeblock(e, 'js', { colors: false }) } ]); } diff --git a/src/commands/dev/reload.ts b/src/commands/dev/reload.ts index 8c2000f..40d53eb 100644 --- a/src/commands/dev/reload.ts +++ b/src/commands/dev/reload.ts @@ -1,13 +1,4 @@ -import { - BushCommand, - clientSendAndPermCheck, - codeblock, - emojis, - formatError, - shell, - type CommandMessage, - type SlashMessage -} from '#lib'; +import { BushCommand, clientSendAndPermCheck, emojis, formatError, shell, type CommandMessage, type SlashMessage } from '#lib'; export default class ReloadCommand extends BushCommand { public constructor() { @@ -44,17 +35,19 @@ export default class ReloadCommand extends BushCommand { const s = new Date(); output = await shell(`yarn build:${/* args.fast ? 'esbuild' : */ 'tsc'}`); await Promise.all([ - client.commandHandler.reloadAll(), - client.listenerHandler.reloadAll(), - client.inhibitorHandler.reloadAll(), - client.contextMenuCommandHandler.reloadAll(), - client.taskHandler.reloadAll() + this.client.commandHandler.reloadAll(), + this.client.listenerHandler.reloadAll(), + this.client.inhibitorHandler.reloadAll(), + this.client.contextMenuCommandHandler.reloadAll(), + this.client.taskHandler.reloadAll() ]); 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 codeblock(formatError(e), 2048 - 34, 'js', true)}`); + if (output!) void this.client.logger.error('reloadCommand', output); + return message.util.send( + `An error occurred while reloading:\n${await this.client.utils.codeblock(formatError(e), 2048 - 34, 'js', true)}` + ); } } } diff --git a/src/commands/dev/say.ts b/src/commands/dev/say.ts index 6ec52a1..2246588 100644 --- a/src/commands/dev/say.ts +++ b/src/commands/dev/say.ts @@ -43,7 +43,7 @@ export default class SayCommand extends BushCommand { } public override async execSlash(message: SlashMessage, args: { content: string }) { - if (!client.config.owners.includes(message.author.id)) { + if (!this.client.config.owners.includes(message.author.id)) { return await message.interaction.reply({ 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 28a4e5d..ab66f1c 100644 --- a/src/commands/dev/servers.ts +++ b/src/commands/dev/servers.ts @@ -26,7 +26,7 @@ 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 guilds = [...this.client.guilds.cache.sort((a, b) => (a.memberCount < b.memberCount ? 1 : -1)).values()]; const chunkedGuilds: Guild[][] = chunk(guilds, 10); const embeds: APIEmbed[] = chunkedGuilds.map((chunk) => { return { @@ -36,7 +36,7 @@ export default class ServersCommand extends BushCommand { 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} + **Owner:** ${this.client.users.cache.has(guild.ownerId) ? this.client.users.cache.get(guild.ownerId)!.tag : guild.ownerId} **Members:** ${guild.memberCount.toLocaleString()}` })) } as APIEmbed; diff --git a/src/commands/dev/sh.ts b/src/commands/dev/sh.ts index f7c17bd..7ffdf27 100644 --- a/src/commands/dev/sh.ts +++ b/src/commands/dev/sh.ts @@ -2,7 +2,6 @@ import { ArgType, BushCommand, clientSendAndPermCheck, - codeblock, colors, emojis, formatError, @@ -51,7 +50,7 @@ export default class ShCommand extends BushCommand { } public override async exec(message: CommandMessage | SlashMessage, args: { command: ArgType<'string'> }) { - if (!client.config.owners.includes(message.author.id)) + if (!this.client.config.owners.includes(message.author.id)) return await message.util.reply(`${emojis.error} Only my developers can run this command.`); const input = clean(args.command); @@ -61,7 +60,7 @@ export default class ShCommand extends BushCommand { .setTimestamp() .setTitle('Shell Command') .addFields([ - { name: '📥 Input', value: await codeblock(input, 1024, 'sh', true) }, + { name: '📥 Input', value: await this.client.utils.codeblock(input, 1024, 'sh', true) }, { name: 'Running', value: emojis.loading } ]); @@ -81,12 +80,14 @@ export default class ShCommand extends BushCommand { embed.setTitle(`${emojis.successFull} Executed command successfully.`).setColor(colors.success).spliceFields(1, 1); - 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) }]); + if (stdout) embed.addFields([{ name: '📤 stdout', value: await this.client.utils.codeblock(stdout, 1024, 'ansi', true) }]); + if (stderr) embed.addFields([{ name: '📤 stderr', value: await this.client.utils.codeblock(stderr, 1024, 'ansi', true) }]); } catch (e) { embed.setTitle(`${emojis.errorFull} An error occurred while executing.`).setColor(colors.error).spliceFields(1, 1); - embed.addFields([{ name: '📤 Output', value: await codeblock(formatError(e, true), 1024, 'ansi', true) }]); + embed.addFields([ + { name: '📤 Output', value: await this.client.utils.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 3de04bf..24e8c9a 100644 --- a/src/commands/dev/superUser.ts +++ b/src/commands/dev/superUser.ts @@ -1,13 +1,4 @@ -import { - BushCommand, - clientSendAndPermCheck, - emojis, - format, - getShared, - insertOrRemoveFromShared, - type ArgType, - type CommandMessage -} from '#lib'; +import { BushCommand, clientSendAndPermCheck, emojis, format, type ArgType, type CommandMessage } from '#lib'; import { type ArgumentGeneratorReturn, type ArgumentTypeCasterReturn } from 'discord-akairo'; export default class SuperUserCommand extends BushCommand { @@ -65,14 +56,14 @@ 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(`${emojis.error} Only my developers can run this command.`); - const superUsers: string[] = getShared('superUsers'); + const superUsers: string[] = this.client.utils.getShared('superUsers'); if (args.action === 'add' ? superUsers.includes(args.user.id) : !superUsers.includes(args.user.id)) return message.util.reply( `${emojis.warn} ${format.input(args.user.tag)} is ${args.action === 'add' ? 'already' : 'not'} a superuser.` ); - const success = await insertOrRemoveFromShared(args.action, 'superUsers', args.user.id).catch(() => false); + const success = await this.client.utils.insertOrRemoveFromShared(args.action, 'superUsers', args.user.id).catch(() => false); if (success) { return await message.util.reply( diff --git a/src/commands/dev/test.ts b/src/commands/dev/test.ts index 9491d19..600aeac 100644 --- a/src/commands/dev/test.ts +++ b/src/commands/dev/test.ts @@ -135,15 +135,15 @@ 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(`${emojis.error} This test can only be run in a guild.`); - await client.guilds.fetch(); + await this.client.guilds.fetch(); const promises: Promise<Collection<string, ApplicationCommand>>[] = []; - client.guilds.cache.each((guild) => { + this.client.guilds.cache.each((guild) => { promises.push(guild.commands.set([])); }); await Promise.all(promises); - await client.application!.commands.fetch(); - await client.application!.commands.set([]); + await this.client.application!.commands.fetch(); + await this.client.application!.commands.set([]); 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())) { @@ -166,7 +166,7 @@ export default class TestCommand extends BushCommand { }); // eslint-disable-next-line @typescript-eslint/no-misused-promises - client.ws.on(GatewayDispatchEvents.InteractionCreate, async (i: any) => { + this.client.ws.on(GatewayDispatchEvents.InteractionCreate, async (i: any) => { if (i?.data?.custom_id !== 'test;modal' || i?.data?.component_type !== 2) return; if (i?.message?.id !== m.id) return; diff --git a/src/commands/info/botInfo.ts b/src/commands/info/botInfo.ts index decbe04..25b860c 100644 --- a/src/commands/info/botInfo.ts +++ b/src/commands/info/botInfo.ts @@ -3,7 +3,6 @@ import { clientSendAndPermCheck, colors, humanizeDuration, - mapIDs, shell, type CommandMessage, type SlashMessage @@ -44,14 +43,14 @@ export default class BotInfoCommand extends BushCommand { haiku = 'Haiku' } - const developers = (await mapIDs(client.config.owners)).map((u) => u?.tag).join('\n'); + const developers = (await this.client.utils.mapIDs(this.client.config.owners)).map((u) => u?.tag).join('\n'); const currentCommit = (await shell('git rev-parse HEAD')).stdout.replace('\n', ''); let repoUrl = (await shell('git remote get-url origin')).stdout.replace('\n', ''); if (repoUrl.includes('.git')) repoUrl = repoUrl.substring(0, repoUrl.length - 4); const embed = new EmbedBuilder() .setTitle('Bot Info:') .addFields([ - { name: '**Uptime**', value: humanizeDuration(client.uptime!, 2), inline: true }, + { name: '**Uptime**', value: humanizeDuration(this.client.uptime!, 2), inline: true }, { name: '**Memory Usage**', value: `System: ${prettyBytes(os.totalmem() - os.freemem(), { binary: true })}/${prettyBytes(os.totalmem(), { @@ -62,18 +61,18 @@ export default class BotInfoCommand extends BushCommand { )}`, inline: true }, - { name: '**CPU Usage**', value: `${client.stats.cpu}%`, inline: true }, + { name: '**CPU Usage**', value: `${this.client.stats.cpu}%`, inline: true }, { name: '**Platform**', value: Platform[process.platform], inline: true }, - { name: '**Commands Used**', value: `${client.stats.commandsUsed.toLocaleString()}`, inline: true }, - { name: '**Slash Commands Used**', value: `${client.stats.slashCommandsUsed.toLocaleString()}`, inline: true }, - { name: '**Servers**', value: client.guilds.cache.size.toLocaleString(), inline: true }, - { name: '**Users**', value: client.users.cache.size.toLocaleString(), inline: true }, + { name: '**Commands Used**', value: `${this.client.stats.commandsUsed.toLocaleString()}`, inline: true }, + { name: '**Slash Commands Used**', value: `${this.client.stats.slashCommandsUsed.toLocaleString()}`, inline: true }, + { name: '**Servers**', value: this.client.guilds.cache.size.toLocaleString(), inline: true }, + { name: '**Users**', value: this.client.users.cache.size.toLocaleString(), inline: true }, { name: '**Discord.js Version**', value: discordJSVersion, inline: true }, { name: '**Node.js Version**', value: process.version.slice(1), inline: true }, - { name: '**Commands**', value: client.commandHandler.modules.size.toLocaleString(), inline: true }, - { name: '**Listeners**', value: client.listenerHandler.modules.size.toLocaleString(), inline: true }, - { name: '**Inhibitors**', value: client.inhibitorHandler.modules.size.toLocaleString(), inline: true }, - { name: '**Tasks**', value: client.taskHandler.modules.size.toLocaleString(), inline: true }, + { name: '**Commands**', value: this.client.commandHandler.modules.size.toLocaleString(), inline: true }, + { name: '**Listeners**', value: this.client.listenerHandler.modules.size.toLocaleString(), inline: true }, + { name: '**Inhibitors**', value: this.client.inhibitorHandler.modules.size.toLocaleString(), inline: true }, + { name: '**Tasks**', value: this.client.taskHandler.modules.size.toLocaleString(), inline: true }, { name: '**Current Commit**', value: `[${currentCommit.substring(0, 7)}](${repoUrl}/commit/${currentCommit})`, diff --git a/src/commands/info/guildInfo.ts b/src/commands/info/guildInfo.ts index 92999a5..060a439 100644 --- a/src/commands/info/guildInfo.ts +++ b/src/commands/info/guildInfo.ts @@ -66,7 +66,7 @@ export default class GuildInfoCommand extends BushCommand { let guild: ArgType<'guild' | 'snowflake'> | GuildPreview = args.guild ?? message.guild!; if (typeof guild === 'string') { - const preview = await client.fetchGuildPreview(`${args.guild}` as Snowflake).catch(() => undefined); + const preview = await this.client.fetchGuildPreview(`${args.guild}` as Snowflake).catch(() => undefined); if (preview) guild = preview; else return await message.util.reply(`${emojis.error} That guild is not discoverable or does not exist.`); } diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts index 051fce5..1a19969 100644 --- a/src/commands/info/help.ts +++ b/src/commands/info/help.ts @@ -4,7 +4,6 @@ import { colors, format, invite, - prefix, type ArgType, |
