diff options
Diffstat (limited to 'src/listeners')
-rw-r--r-- | src/listeners/client/ready.ts | 14 | ||||
-rw-r--r-- | src/listeners/commands/commandBlocked.ts | 2 | ||||
-rw-r--r-- | src/listeners/commands/commandError.ts | 6 | ||||
-rw-r--r-- | src/listeners/commands/commandMissingPermissions.ts | 55 | ||||
-rw-r--r-- | src/listeners/commands/commandStarted.ts | 2 | ||||
-rw-r--r-- | src/listeners/commands/slashBlocked.ts | 2 | ||||
-rw-r--r-- | src/listeners/commands/slashCommandError.ts | 15 | ||||
-rw-r--r-- | src/listeners/commands/slashMissingPermissions.ts | 58 | ||||
-rw-r--r-- | src/listeners/commands/slashStarted.ts | 8 | ||||
-rw-r--r-- | src/listeners/message/level.ts | 3 | ||||
-rw-r--r-- | src/listeners/other/consoleListener.ts | 17 | ||||
-rw-r--r-- | src/listeners/other/promiseRejection.ts | 2 |
12 files changed, 140 insertions, 44 deletions
diff --git a/src/listeners/client/ready.ts b/src/listeners/client/ready.ts index a87d216..1a51527 100644 --- a/src/listeners/client/ready.ts +++ b/src/listeners/client/ready.ts @@ -10,15 +10,15 @@ export default class ReadyListener extends BushListener { } public async exec(): Promise<void> { - //@ts-expect-error: ik its private, this is the only time I need to access it outside of its class - const timeStamp = chalk.bgGreen(this.client.logger.getTimeStamp()), - tag = chalk.magenta(this.client.user.tag), - guildCount = chalk.magenta(this.client.guilds.cache.size.toLocaleString()), - userCount = chalk.magenta(this.client.users.cache.size.toLocaleString()); + const tag = `<<${this.client.user.tag}>>`, + guildCount = `<<${this.client.guilds.cache.size.toLocaleString()}>>`, + userCount = `<<${this.client.users.cache.size.toLocaleString()}>>`; - console.log(`${timeStamp} Logged in to ${tag} serving ${guildCount} guilds and ${userCount} users.`); + this.client.logger.success('Ready', `Logged in to ${tag} serving ${guildCount} guilds and ${userCount} users.`); console.log( - chalk.blue(`----------------------------------------------------------------------${this.client.config.dev ? '---' : ''}`) + chalk.blue( + `------------------------------------------------------------------------------${this.client.config.dev ? '---' : ''}` + ) ); this.client.user.setPresence({ diff --git a/src/listeners/commands/commandBlocked.ts b/src/listeners/commands/commandBlocked.ts index febfc93..816005d 100644 --- a/src/listeners/commands/commandBlocked.ts +++ b/src/listeners/commands/commandBlocked.ts @@ -14,7 +14,7 @@ export default class CommandBlockedListener extends BushListener { this.client.console.info( 'CommandBlocked', `<<${message.author.tag}>> tried to run <<${message.util.parsed.command}>> but was blocked because <<${reason}>>.`, - false + true ); const reasons = this.client.consts.BlockedReasons; diff --git a/src/listeners/commands/commandError.ts b/src/listeners/commands/commandError.ts index 7f765ae..85ff11f 100644 --- a/src/listeners/commands/commandError.ts +++ b/src/listeners/commands/commandError.ts @@ -26,13 +26,13 @@ export default class CommandErrorListener extends BushListener { .setColor(this.client.util.colors.error) .setTimestamp(); + await this.client.logger.channelError({ embeds: [errorEmbed] }); if (message) { if (!this.client.config.owners.includes(message.author.id)) { const errorUserEmbed: MessageEmbed = new MessageEmbed() - .setTitle('An error occurred') + .setTitle('A Command Error Occurred') .setColor(this.client.util.colors.error) .setTimestamp(); - await this.client.logger.channelError({ embeds: [errorEmbed] }); if (!command) errorUserEmbed.setDescription(`Oh no! An error occurred. Please give the developers code \`${errorNo}\`.`); else @@ -45,7 +45,7 @@ export default class CommandErrorListener extends BushListener { }); } else { const errorDevEmbed = new MessageEmbed() - .setTitle('An error occurred') + .setTitle('A Command Error Occurred') .setColor(this.client.util.colors.error) .setTimestamp() .setDescription(await this.client.util.codeblock(`${error?.stack}`, 2048, 'js')); diff --git a/src/listeners/commands/commandMissingPermissions.ts b/src/listeners/commands/commandMissingPermissions.ts new file mode 100644 index 0000000..d695d25 --- /dev/null +++ b/src/listeners/commands/commandMissingPermissions.ts @@ -0,0 +1,55 @@ +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushListener } from '../../lib/extensions/BushListener'; +import { BushMessage } from '../../lib/extensions/BushMessage'; + +export default class CommandMissingPermissionsListener extends BushListener { + public constructor() { + super('commandMissingPermissions', { + emitter: 'commandHandler', + event: 'missingPermissions', + category: 'commands' + }); + } + + public async exec( + message: BushMessage, + command: BushCommand | null | undefined, + type: 'client' | 'user', + missing: Array<string> + ): Promise<void> { + const niceMissing = []; + missing.forEach((missing) => { + if (this.client.consts.mappings.permissions[missing]) { + niceMissing.push(this.client.consts.mappings.permissions[missing].name); + } else { + niceMissing.push(missing); + } + }); + + const discordFormat = this.client.util.oxford(this.client.util.surroundArray(niceMissing, '`'), 'and', ''); + const consoleFormat = this.client.util.oxford(this.client.util.surroundArray(niceMissing, '<<', '>>'), 'and', ''); + this.client.console.info( + 'CommandMissingPermissions', + `<<${message.author.tag}>> tried to run <<${ + command?.id + }>> but could not because <<${type}>> is missing the ${consoleFormat} permissions${missing.length ? 's' : ''}.` + ); + if (type == 'client') { + await message.util + .reply( + `${this.client.util.emojis.error} I am missing the ${discordFormat} permission${ + missing.length ? 's' : '' + } required for the \`${command?.id}\` command.` + ) + .catch(() => {}); + } else if (type == 'user') { + await message.util + .reply( + `${this.client.util.emojis.error} You are missing the ${discordFormat} permission${ + missing.length ? 's' : '' + } required for the \`${command?.id}\` command.` + ) + .catch(() => {}); + } + } +} diff --git a/src/listeners/commands/commandStarted.ts b/src/listeners/commands/commandStarted.ts index 8c860f8..9266fc7 100644 --- a/src/listeners/commands/commandStarted.ts +++ b/src/listeners/commands/commandStarted.ts @@ -15,7 +15,7 @@ export default class CommandStartedListener extends BushListener { `The <<${command.id}>> command was used by <<${message.author.tag}>> in ${ message.channel.type === 'dm' ? `their <<DMs>>` : `<<#${message.channel.name}>> in <<${message.guild?.name}>>` }.`, - false // I don't want to spam the log channel when people use commands + true //// I don't want to spam the log channel when people use commands ); } } diff --git a/src/listeners/commands/slashBlocked.ts b/src/listeners/commands/slashBlocked.ts index e87ba70..e64253a 100644 --- a/src/listeners/commands/slashBlocked.ts +++ b/src/listeners/commands/slashBlocked.ts @@ -14,7 +14,7 @@ export default class SlashBlockedListener extends BushListener { this.client.console.info( 'SlashBlocked', `<<${message.author.tag}>> tried to run <<${message.util.parsed.command}>> but was blocked because <<${reason}>>.`, - false + true ); const reasons = this.client.consts.BlockedReasons; diff --git a/src/listeners/commands/slashCommandError.ts b/src/listeners/commands/slashCommandError.ts index b9123e8..1a5f293 100644 --- a/src/listeners/commands/slashCommandError.ts +++ b/src/listeners/commands/slashCommandError.ts @@ -18,20 +18,21 @@ export default class SlashCommandErrorListener extends BushListener { .setDescription( stripIndents`**User:** ${message.author} (${message.author.tag}) **Slash Command:** ${command} - **Channel:** ${message.channel} (${message.channel.id}) - **Message:** [link](https://discord.com/${message.guild.id}/${message.guild.id}/${message.id})` + **Channel:** ${message.channel || message.interaction.user?.tag} ${message.channel ? `(${message.channel?.id})` : ''} + **Message:** [link](https://discord.com/${message.guild?.id}/${message.channel?.id}/${message.id})` ) .addField('Error', await this.client.util.codeblock(`${error?.stack}`, 1024, 'js')) .setColor(this.client.util.colors.error) .setTimestamp(); + await this.client.logger.channelError({ embeds: [errorEmbed] }); if (message) { + const channel = message.channel?.name || message.interaction.user.tag; if (!this.client.config.owners.includes(message.author.id)) { const errorUserEmbed: MessageEmbed = new MessageEmbed() - .setTitle('An error occurred') + .setTitle('A Slash Command Error Occurred') .setColor(this.client.util.colors.error) .setTimestamp(); - await this.client.logger.channelError({ embeds: [errorEmbed] }); if (!command) errorUserEmbed.setDescription(`Oh no! An error occurred. Please give the developers code \`${errorNo}\`.`); else @@ -39,22 +40,20 @@ export default class SlashCommandErrorListener extends BushListener { `Oh no! While running the command \`${command.id}\`, an error occurred. Please give the developers code \`${errorNo}\`.` ); await message.util.send({ embeds: [errorUserEmbed] }).catch((e) => { - const channel = message.channel.type === 'dm' ? message.channel.recipient.tag : message.channel.name; this.client.console.warn('SlashError', `Failed to send user error embed in <<${channel}>>:\n` + e?.stack); }); } else { const errorDevEmbed = new MessageEmbed() - .setTitle('An error occurred') + .setTitle('A Slash Command Error Occurred') .setColor(this.client.util.colors.error) .setTimestamp() .setDescription(await this.client.util.codeblock(`${error?.stack}`, 2048, 'js')); await message.util.send({ embeds: [errorDevEmbed] }).catch((e) => { - const channel = message.channel.type === 'dm' ? message.channel.recipient.tag : message.channel.name; this.client.console.warn('SlashError', `Failed to send owner error stack in <<${channel}>>.` + e?.stack); }); } } - const channel = message.channel.type === 'dm' ? message.channel.recipient.tag : message.channel.name; + const channel = message.channel?.name || message.interaction.user.tag; this.client.console.error( 'SlashError', `an error occurred with the <<${command}>> command in <<${channel}>> triggered by <<${message?.author?.tag}>>:\n` + diff --git a/src/listeners/commands/slashMissingPermissions.ts b/src/listeners/commands/slashMissingPermissions.ts new file mode 100644 index 0000000..1f3599f --- /dev/null +++ b/src/listeners/commands/slashMissingPermissions.ts @@ -0,0 +1,58 @@ +import { Command } from 'discord-akairo'; +import { CommandInteraction } from 'discord.js'; +import { BushListener } from '../../lib/extensions/BushListener'; + +export default class SlashMissingPermissionsListener extends BushListener { + public constructor() { + super('slashMissingPermissions', { + emitter: 'commandHandler', + event: 'slashMissingPermissions', + category: 'slashCommands' + }); + } + + public async exec( + interaction: CommandInteraction, + command: Command, + type: 'user' | 'client', + missing?: string[] + ): Promise<void> { + const niceMissing = []; + missing.forEach((missing) => { + if (this.client.consts.mappings.permissions[missing]) { + niceMissing.push(this.client.consts.mappings.permissions[missing].name); + } else { + niceMissing.push(missing); + } + }); + + const discordFormat = this.client.util.oxford(this.client.util.surroundArray(niceMissing, '`'), 'and', ''); + const consoleFormat = this.client.util.oxford(this.client.util.surroundArray(niceMissing, '<<', '>>'), 'and', ''); + this.client.console.info( + 'CommandMissingPermissions', + `<<${interaction.user.tag}>> tried to run <<${ + command?.id + }>> but could not because <<${type}>> is missing the ${consoleFormat} permissions${missing.length ? 's' : ''}.`, + true + ); + if (type == 'client') { + await this.client.util + .slashRespond( + interaction, + `${this.client.util.emojis.error} I am missing the ${discordFormat} permission${ + missing.length ? 's' : '' + } required for the \`${command?.id}\` command.` + ) + .catch(() => {}); + } else if (type == 'user') { + await this.client.util + .slashRespond( + interaction, + `${this.client.util.emojis.error} You are missing the ${discordFormat} permission${ + missing.length ? 's' : '' + } required for the \`${command?.id}\` command.` + ) + .catch(() => {}); + } + } +} diff --git a/src/listeners/commands/slashStarted.ts b/src/listeners/commands/slashStarted.ts index 6a45546..c6b966a 100644 --- a/src/listeners/commands/slashStarted.ts +++ b/src/listeners/commands/slashStarted.ts @@ -1,5 +1,5 @@ -import { Message } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; +import { BushSlashMessage } from '../../lib/extensions/BushInteractionMessage'; import { BushListener } from '../../lib/extensions/BushListener'; export default class SlashStartedListener extends BushListener { @@ -9,13 +9,13 @@ export default class SlashStartedListener extends BushListener { event: 'slashStarted' }); } - exec(message: Message, command: BushCommand): void { + exec(message: BushSlashMessage, command: BushCommand): void { this.client.logger.info( 'SlashCommand', `The <<${command.id}>> command was used by <<${message.author.tag}>> in ${ - message.channel.type === 'dm' ? `their <<DMs>>` : `<<#${message.channel.name}>> in <<${message.guild?.name}>>` + !message.channel ? `their <<DMs>>` : `<<#${message.channel.name}>> in <<${message.guild?.name}>>` }.`, - false // I don't want to spam the log channel when people use commands + true //// I don't want to spam the log channel when people use commands ); } } diff --git a/src/listeners/message/level.ts b/src/listeners/message/level.ts index 74c4db8..9f413e5 100644 --- a/src/listeners/message/level.ts +++ b/src/listeners/message/level.ts @@ -32,8 +32,7 @@ export default class LevelListener extends BushListener { this.client.logger.error('LevelMessageListener', e); return false; }); - if (success) - await this.client.logger.verbose(`LevelMessageListener`, `Gave <<${xpToGive}>> XP to <<${message.author.tag}>>.`); + if (success) this.client.logger.verbose(`LevelMessageListener`, `Gave <<${xpToGive}>> XP to <<${message.author.tag}>>.`); this.levelCooldowns.add(message.author.id); setTimeout(() => this.levelCooldowns.delete(message.author.id), 60_000); } diff --git a/src/listeners/other/consoleListener.ts b/src/listeners/other/consoleListener.ts index 50c0cf3..d1e318f 100644 --- a/src/listeners/other/consoleListener.ts +++ b/src/listeners/other/consoleListener.ts @@ -30,21 +30,6 @@ export default class ConsoleListener extends BushListener { } catch (e) { console.error(e); } - } /* else if (line.startsWith('reload')) { - exec('npx tsc', (error) => { - if (error) { - return this.client.console.error('Reload', `Error recompiling, \`${error.message}\``); - } - try { - this.client.commandHandler.reloadAll(); - this.client.listenerHandler.reloadAll(); - } catch (e) { - return this.client.console.error('Reload', e); - } - this.client.console.success('Reload', 'Reloaded successfully.'); - }); - } else if (line.startsWith('stop') || line.startsWith('exit')) { - process.exit(); - } */ + } } } diff --git a/src/listeners/other/promiseRejection.ts b/src/listeners/other/promiseRejection.ts index 2d7e316..143659a 100644 --- a/src/listeners/other/promiseRejection.ts +++ b/src/listeners/other/promiseRejection.ts @@ -10,7 +10,7 @@ export default class PromiseRejectionListener extends BushListener { public async exec(error: Error): Promise<void> { this.client.console.error('PromiseRejection', 'An unhanded promise rejection occurred:\n' + error.stack, false); - await this.client.console.channelError({ + this.client.console.channelError({ embeds: [ { title: 'Unhandled promise rejection', |