aboutsummaryrefslogtreecommitdiff
path: root/src/listeners/commands
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-06-16 14:32:18 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-06-16 14:32:18 -0400
commit0e87bbd3940d89defcb04926587b35c8f4d1947f (patch)
treee50860d4dc25a11d4c3977b583284c4bcad1b077 /src/listeners/commands
parent661e4c9935aeb8760dafc7ced4bbec6cc356a033 (diff)
downloadtanzanite-0e87bbd3940d89defcb04926587b35c8f4d1947f.tar.gz
tanzanite-0e87bbd3940d89defcb04926587b35c8f4d1947f.tar.bz2
tanzanite-0e87bbd3940d89defcb04926587b35c8f4d1947f.zip
remove util classes, move config out of src
Diffstat (limited to 'src/listeners/commands')
-rw-r--r--src/listeners/commands/commandBlocked.ts73
-rw-r--r--src/listeners/commands/commandCooldown.ts2
-rw-r--r--src/listeners/commands/commandError.ts38
-rw-r--r--src/listeners/commands/commandLocked.ts6
-rw-r--r--src/listeners/commands/commandMissingPermissions.ts16
-rw-r--r--src/listeners/commands/commandStarted.ts2
-rw-r--r--src/listeners/commands/messageBlocked.ts2
-rw-r--r--src/listeners/commands/slashBlocked.ts2
-rw-r--r--src/listeners/commands/slashCommandError.ts2
-rw-r--r--src/listeners/commands/slashMissingPermissions.ts2
-rw-r--r--src/listeners/commands/slashNotFound.ts2
-rw-r--r--src/listeners/commands/slashStarted.ts2
12 files changed, 84 insertions, 65 deletions
diff --git a/src/listeners/commands/commandBlocked.ts b/src/listeners/commands/commandBlocked.ts
index feb85d1..8a05d39 100644
--- a/src/listeners/commands/commandBlocked.ts
+++ b/src/listeners/commands/commandBlocked.ts
@@ -1,4 +1,14 @@
-import { BushListener, type BushCommand, type BushCommandHandlerEvents, type CommandMessage, type SlashMessage } from '#lib';
+import {
+ BlockedReasons,
+ BushListener,
+ emojis,
+ format,
+ oxford,
+ type BushCommand,
+ type BushCommandHandlerEvents,
+ type CommandMessage,
+ type SlashMessage
+} from '#lib';
import { type InteractionReplyOptions, type MessagePayload, type ReplyMessageOptions } from 'discord.js';
export default class CommandBlockedListener extends BushListener {
@@ -10,7 +20,7 @@ export default class CommandBlockedListener extends BushListener {
});
}
- public override async exec(...[message, command, reason]: BushCommandHandlerEvents['commandBlocked']) {
+ public async exec(...[message, command, reason]: BushCommandHandlerEvents['commandBlocked']) {
return await CommandBlockedListener.handleBlocked(message, command, reason);
}
@@ -24,85 +34,84 @@ export default class CommandBlockedListener extends BushListener {
} was blocked because <<${reason}>>.`,
true
);
- const reasons = client.consts.BlockedReasons;
switch (reason) {
- case reasons.OWNER: {
+ case BlockedReasons.OWNER: {
return await respond({
- content: `${util.emojis.error} Only my developers can run the ${util.format.input(command!.id)} command.`,
+ content: `${emojis.error} Only my developers can run the ${format.input(command!.id)} command.`,
ephemeral: true
});
}
- case reasons.SUPER_USER: {
+ case BlockedReasons.SUPER_USER: {
return await respond({
- content: `${util.emojis.error} You must be a superuser to run the ${util.format.input(command!.id)} command.`,
+ content: `${emojis.error} You must be a superuser to run the ${format.input(command!.id)} command.`,
ephemeral: true
});
}
- case reasons.DISABLED_GLOBAL: {
+ case BlockedReasons.DISABLED_GLOBAL: {
return await respond({
- content: `${util.emojis.error} My developers disabled the ${util.format.input(command!.id)} command.`,
+ content: `${emojis.error} My developers disabled the ${format.input(command!.id)} command.`,
ephemeral: true
});
}
- case reasons.DISABLED_GUILD: {
+ case BlockedReasons.DISABLED_GUILD: {
return await respond({
- content: `${util.emojis.error} The ${util.format.input(
- command!.id
- )} command is currently disabled in ${util.format.input(message.guild!.name)}.`,
+ content: `${emojis.error} The ${format.input(command!.id)} command is currently disabled in ${format.input(
+ message.guild!.name
+ )}.`,
ephemeral: true
});
}
- case reasons.CHANNEL_GLOBAL_BLACKLIST:
- case reasons.CHANNEL_GUILD_BLACKLIST:
+ case BlockedReasons.CHANNEL_GLOBAL_BLACKLIST:
+ case BlockedReasons.CHANNEL_GUILD_BLACKLIST:
return isSlash
? await respond({
- content: `${util.emojis.error} You cannot use this bot in this channel.`,
+ content: `${emojis.error} You cannot use this bot in this channel.`,
ephemeral: true
})
- : await (message as CommandMessage).react(util.emojis.cross);
- case reasons.USER_GLOBAL_BLACKLIST:
- case reasons.USER_GUILD_BLACKLIST:
+ : await (message as CommandMessage).react(emojis.cross);
+ case BlockedReasons.USER_GLOBAL_BLACKLIST:
+ case BlockedReasons.USER_GUILD_BLACKLIST:
return isSlash
? await respond({
- content: `${util.emojis.error} You are blacklisted from using this bot.`,
+ content: `${emojis.error} You are blacklisted from using this bot.`,
ephemeral: true
})
- : await (message as CommandMessage).react(util.emojis.cross);
- case reasons.ROLE_BLACKLIST: {
+ : await (message as CommandMessage).react(emojis.cross);
+ case BlockedReasons.ROLE_BLACKLIST: {
return isSlash
? await respond({
- content: `${util.emojis.error} One of your roles blacklists you from using this bot.`,
+ content: `${emojis.error} One of your roles blacklists you from using this bot.`,
ephemeral: true
})
- : await (message as CommandMessage).react(util.emojis.cross);
+ : await (message as CommandMessage).react(emojis.cross);
}
- case reasons.RESTRICTED_CHANNEL: {
+ case BlockedReasons.RESTRICTED_CHANNEL: {
if (!command) break;
const channels = command.restrictedChannels;
const names: string[] = [];
channels!.forEach((c) => {
names.push(`<#${c}>`);
});
- const pretty = util.oxford(names, 'and');
+ const pretty = oxford(names, 'and');
return await respond({
- content: `${util.emojis.error} ${util.format.input(command!.id)} can only be run in ${pretty}.`,
+ content: `${emojis.error} ${format.input(command!.id)} can only be run in ${pretty}.`,
ephemeral: true
});
}
- case reasons.RESTRICTED_GUILD: {
+ case BlockedReasons.RESTRICTED_GUILD: {
if (!command) break;
const guilds = command.restrictedGuilds;
- const names = guilds!.map((g) => util.format.input(client.guilds.cache.get(g)?.name ?? g));
- const pretty = util.oxford(names, 'and');
+ const names = guilds!.map((g) => format.input(client.guilds.cache.get(g)?.name ?? g));
+ const pretty = oxford(names, 'and');
return await respond({
- content: `${util.emojis.error} ${util.format.input(command!.id)} can only be run in ${pretty}.`,
+ content: `${emojis.error} ${format.input(command!.id)} can only be run in ${pretty}.`,
ephemeral: true
});
}
default: {
return await respond({
- content: `${util.emojis.error} Command blocked with reason ${util.format.input(reason ?? 'unknown')}.`,
+ content: `${emojis.error} Command blocked with reason ${format.input(reason ?? 'unknown')}.`,
ephemeral: true
});
}
diff --git a/src/listeners/commands/commandCooldown.ts b/src/listeners/commands/commandCooldown.ts
index 92b0abe..74dd4eb 100644
--- a/src/listeners/commands/commandCooldown.ts
+++ b/src/listeners/commands/commandCooldown.ts
@@ -9,7 +9,7 @@ export default class CommandCooldownListener extends BushListener {
});
}
- public override async exec(...[message, command, remaining]: BushCommandHandlerEvents['cooldown']) {
+ public async exec(...[message, command, remaining]: BushCommandHandlerEvents['cooldown']) {
void client.console.info(
'commandCooldown',
`<<${message.author.tag}>> tried to run <<${
diff --git a/src/listeners/commands/commandError.ts b/src/listeners/commands/commandError.ts
index 878e459..ca6565e 100644
--- a/src/listeners/commands/commandError.ts
+++ b/src/listeners/commands/commandError.ts
@@ -1,6 +1,16 @@
-import { SlashMessage, type BushCommandHandlerEvents } from '#lib';
+import {
+ capitalize,
+ colors,
+ format,
+ formatError,
+ inspectAndRedact,
+ inspectCleanRedactCodeblock,
+ inspectCleanRedactHaste,
+ SlashMessage,
+ type BushCommandHandlerEvents
+} from '#lib';
import { type AkairoMessage, type Command } from 'discord-akairo';
-import { ChannelType, EmbedBuilder, Formatters, GuildTextBasedChannel, type Message } from 'discord.js';
+import { ChannelType, EmbedBuilder, escapeInlineCode, Formatters, GuildTextBasedChannel, type Message } from 'discord.js';
import { BushListener } from '../../lib/extensions/discord-akairo/BushListener.js';
export default class CommandErrorListener extends BushListener {
@@ -12,7 +22,7 @@ export default class CommandErrorListener extends BushListener {
});
}
- public override exec(...[error, message, command]: BushCommandHandlerEvents['error']) {
+ public exec(...[error, message, command]: BushCommandHandlerEvents['error']) {
return CommandErrorListener.handleError(error, message, command);
}
@@ -49,7 +59,7 @@ export default class CommandErrorListener extends BushListener {
`${isSlash ? 'slashC' : 'c'}ommandError`,
`an error occurred with the <<${command}>> ${isSlash ? 'slash ' : ''}command in <<${channel}>> triggered by <<${
message?.author?.tag
- }>>:\n${util.formatError(error, true)})}`,
+ }>>:\n${formatError(error, true)})}`,
false
);
@@ -127,16 +137,16 @@ export default class CommandErrorListener extends BushListener {
stack: string;
}
): EmbedBuilder[] {
- const embeds = [new EmbedBuilder().setColor(util.colors.error)];
+ const embeds = [new EmbedBuilder().setColor(colors.error)];
if (options.type === 'command-user') {
embeds[0]
.setTitle('An Error Occurred')
.setDescription(
`Oh no! ${
options.command
- ? `While running the ${options.isSlash ? 'slash ' : ''}command ${util.format.input(options.command.id)}, a`
+ ? `While running the ${options.isSlash ? 'slash ' : ''}command ${format.input(options.command.id)}, a`
: 'A'
- }n error occurred. Please give the developers code ${util.format.input(`${options.errorNum}`)}.`
+ }n error occurred. Please give the developers code ${format.input(`${options.errorNum}`)}.`
)
.setTimestamp();
return embeds;
@@ -155,11 +165,11 @@ export default class CommandErrorListener extends BushListener {
description.push(...options.haste);
- embeds.push(new EmbedBuilder().setColor(util.colors.error).setTimestamp().setDescription(options.stack.substring(0, 4000)));
+ embeds.push(new EmbedBuilder().setColor(colors.error).setTimestamp().setDescription(options.stack.substring(0, 4000)));
if (description.length) embeds[0].setDescription(description.join('\n').substring(0, 4000));
if (options.type === 'command-dev' || options.type === 'command-log')
- embeds[0].setTitle(`${options.isSlash ? 'Slash ' : ''}CommandError #${util.format.input(`${options.errorNum}`)}`);
+ embeds[0].setTitle(`${options.isSlash ? 'Slash ' : ''}CommandError #${format.input(`${options.errorNum}`)}`);
else if (options.type === 'uncaughtException')
embeds[0].setTitle(`${options.context ? `[${Formatters.bold(options.context)}] An Error Occurred` : 'Uncaught Exception'}`);
else if (options.type === 'unhandledRejection')
@@ -199,7 +209,7 @@ export default class CommandErrorListener extends BushListener {
for (const element in error) {
if (['stack', 'name', 'message'].includes(element)) continue;
else if (typeof (error as any)[element] === 'object') {
- promises.push(util.inspectCleanRedactHaste((error as any)[element], inspectOptions));
+ promises.push(inspectCleanRedactHaste((error as any)[element], inspectOptions));
}
}
@@ -218,14 +228,14 @@ export default class CommandErrorListener extends BushListener {
if (['stack', 'name', 'message'].includes(element)) continue;
else {
ret.push(
- `**Error ${util.capitalizeFirstLetter(element)}:** ${
- typeof (error as any)[element] === 'object'
+ `**Error ${capitalize(element)}:** ${
+ typeof error[element] === 'object'
? `${
pair[element].url
? `[haste](${pair[element].url})${pair[element].error ? ` - ${pair[element].error}` : ''}`
: pair[element].error
}`
- : `\`${util.discord.escapeInlineCode(util.inspectAndRedact((error as any)[element], inspectOptions))}\``
+ : `\`${escapeInlineCode(inspectAndRedact((error as any)[element], inspectOptions))}\``
}`
);
}
@@ -234,7 +244,7 @@ export default class CommandErrorListener extends BushListener {
}
public static async getErrorStack(error: Error | any): Promise<string> {
- return await util.inspectCleanRedactCodeblock(error, 'js', { colors: false }, 4000);
+ return await inspectCleanRedactCodeblock(error, 'js', { colors: false }, 4000);
}
}
diff --git a/src/listeners/commands/commandLocked.ts b/src/listeners/commands/commandLocked.ts
index 285eb50..22ed8e1 100644
--- a/src/listeners/commands/commandLocked.ts
+++ b/src/listeners/commands/commandLocked.ts
@@ -1,4 +1,4 @@
-import { BushListener, type BushCommandHandlerEvents } from '#lib';
+import { BushListener, emojis, format, type BushCommandHandlerEvents } from '#lib';
export default class CommandLockedListener extends BushListener {
public constructor() {
@@ -9,9 +9,9 @@ export default class CommandLockedListener extends BushListener {
});
}
- public override async exec(...[message, command]: BushCommandHandlerEvents['commandLocked']) {
+ public async exec(...[message, command]: BushCommandHandlerEvents['commandLocked']) {
return message.util.reply(
- `${util.emojis.error} You cannot use the ${util.format.input(command.id)} command because it is already in use.`
+ `${emojis.error} You cannot use the ${format.input(command.id)} command because it is already in use.`
);
}
}
diff --git a/src/listeners/commands/commandMissingPermissions.ts b/src/listeners/commands/commandMissingPermissions.ts
index 2cbf17c..352899d 100644
--- a/src/listeners/commands/commandMissingPermissions.ts
+++ b/src/listeners/commands/commandMissingPermissions.ts
@@ -1,4 +1,4 @@
-import { BushListener, type BushCommandHandlerEvents } from '#lib';
+import { BushListener, emojis, format, mappings, oxford, surroundArray, type BushCommandHandlerEvents } from '#lib';
import { type PermissionsString } from 'discord.js';
export default class CommandMissingPermissionsListener extends BushListener {
@@ -10,7 +10,7 @@ export default class CommandMissingPermissionsListener extends BushListener {
});
}
- public override async exec(...[message, command, type, missing]: BushCommandHandlerEvents['missingPermissions']) {
+ public async exec(...[message, command, type, missing]: BushCommandHandlerEvents['missingPermissions']) {
return await CommandMissingPermissionsListener.handleMissing(message, command, type, missing);
}
@@ -20,11 +20,11 @@ export default class CommandMissingPermissionsListener extends BushListener {
| BushCommandHandlerEvents['slashMissingPermissions']
) {
const niceMissing = (missing.includes('Administrator') ? (['Administrator'] as PermissionsString[]) : missing).map(
- (perm) => client.consts.mappings.permissions[perm]?.name ?? missing
+ (perm) => mappings.permissions[perm]?.name ?? missing
);
- const discordFormat = util.oxford(util.surroundArray(niceMissing, '**'), 'and', '');
- const consoleFormat = util.oxford(util.surroundArray(niceMissing, '<<', '>>'), 'and', '');
+ const discordFormat = oxford(surroundArray(niceMissing, '**'), 'and', '');
+ const consoleFormat = oxford(surroundArray(niceMissing, '<<', '>>'), 'and', '');
void client.console.info(
'commandMissingPermissions',
`<<${message.author.tag}>> tried to run <<${
@@ -34,15 +34,15 @@ export default class CommandMissingPermissionsListener extends BushListener {
if (type == 'client') {
return await message.util
.reply(
- `${util.emojis.error} I am missing the ${discordFormat} permission${
+ `${emojis.error} I am missing the ${discordFormat} permission${
missing.length ? 's' : ''
- } required for the ${util.format.input(command?.id)} command.`
+ } required for the ${format.input(command?.id)} command.`
)
.catch(() => {});
} else if (type == 'user') {
return await message.util
.reply(
- `${util.emojis.error} You are missing the ${discordFormat} permission${missing.length ? 's' : ''} required for the **${
+ `${emojis.error} You are missing the ${discordFormat} permission${missing.length ? 's' : ''} required for the **${
command?.id
}** command.`
)
diff --git a/src/listeners/commands/commandStarted.ts b/src/listeners/commands/commandStarted.ts
index 02a0b75..89fea28 100644
--- a/src/listeners/commands/commandStarted.ts
+++ b/src/listeners/commands/commandStarted.ts
@@ -10,7 +10,7 @@ export default class CommandStartedListener extends BushListener {
});
}
- public override exec(...[message, command]: BushCommandHandlerEvents['commandStarted']): void {
+ public exec(...[message, command]: BushCommandHandlerEvents['commandStarted']): void {
client.sentry.addBreadcrumb({
message: `[commandStarted] The ${command.id} was started by ${message.author.tag}.`,
level: 'info',
diff --git a/src/listeners/commands/messageBlocked.ts b/src/listeners/commands/messageBlocked.ts
index 5a2b10d..997579c 100644
--- a/src/listeners/commands/messageBlocked.ts
+++ b/src/listeners/commands/messageBlocked.ts
@@ -9,7 +9,7 @@ export default class MessageBlockedListener extends BushListener {
});
}
- public override async exec(...[message, reason]: BushCommandHandlerEvents['messageBlocked']) {
+ public async exec(...[message, reason]: BushCommandHandlerEvents['messageBlocked']) {
if (['client', 'bot'].includes(reason)) return;
// return await CommandBlockedListener.handleBlocked(message as Message, null, reason);
return void client.console.verbose(`messageBlocked`, `<<${message.author.tag}>>'s message was blocked because ${reason}`);
diff --git a/src/listeners/commands/slashBlocked.ts b/src/listeners/commands/slashBlocked.ts
index 6c0ed14..915b953 100644
--- a/src/listeners/commands/slashBlocked.ts
+++ b/src/listeners/commands/slashBlocked.ts
@@ -10,7 +10,7 @@ export default class SlashBlockedListener extends BushListener {
});
}
- public override async exec(...[message, command, reason]: BushCommandHandlerEvents['slashBlocked']) {
+ public async exec(...[message, command, reason]: BushCommandHandlerEvents['slashBlocked']) {
return await CommandBlockedListener.handleBlocked(message, command, reason);
}
}
diff --git a/src/listeners/commands/slashCommandError.ts b/src/listeners/commands/slashCommandError.ts
index 25c0f3e..f851f4f 100644
--- a/src/listeners/commands/slashCommandError.ts
+++ b/src/listeners/commands/slashCommandError.ts
@@ -10,7 +10,7 @@ export default class SlashCommandErrorListener extends BushListener {
});
}
- public override async exec(...[error, message, command]: BushCommandHandlerEvents['slashError']) {
+ public async exec(...[error, message, command]: BushCommandHandlerEvents['slashError']) {
return await CommandErrorListener.handleError(error, message, command);
}
}
diff --git a/src/listeners/commands/slashMissingPermissions.ts b/src/listeners/commands/slashMissingPermissions.ts
index 296f44b..3ae03e3 100644
--- a/src/listeners/commands/slashMissingPermissions.ts
+++ b/src/listeners/commands/slashMissingPermissions.ts
@@ -10,7 +10,7 @@ export default class SlashMissingPermissionsListener extends BushListener {
});
}
- public override async exec(...[message, command, type, missing]: BushCommandHandlerEvents['slashMissingPermissions']) {
+ public async exec(...[message, command, type, missing]: BushCommandHandlerEvents['slashMissingPermissions']) {
return await CommandMissingPermissionsListener.handleMissing(message, command, type, missing);
}
}
diff --git a/src/listeners/commands/slashNotFound.ts b/src/listeners/commands/slashNotFound.ts
index a8e4267..8c6d2d4 100644
--- a/src/listeners/commands/slashNotFound.ts
+++ b/src/listeners/commands/slashNotFound.ts
@@ -9,7 +9,7 @@ export default class SlashNotFoundListener extends BushListener {
});
}
- public override async exec(...[interaction]: BushCommandHandlerEvents['slashNotFound']) {
+ public async exec(...[interaction]: BushCommandHandlerEvents['slashNotFound']) {
void client.console.info('slashNotFound', `<<${interaction?.commandName}>> could not be found.`);
}
}
diff --git a/src/listeners/commands/slashStarted.ts b/src/listeners/commands/slashStarted.ts
index 3d8334d..e2c8a47 100644
--- a/src/listeners/commands/slashStarted.ts
+++ b/src/listeners/commands/slashStarted.ts
@@ -10,7 +10,7 @@ export default class SlashStartedListener extends BushListener {
});
}
- public override async exec(...[message, command]: BushCommandHandlerEvents['slashStarted']) {
+ public async exec(...[message, command]: BushCommandHandlerEvents['slashStarted']) {
client.sentry.addBreadcrumb({
message: `[slashStarted] The ${command.id} was started by ${message.author.tag}.`,
level: 'info',