diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-06-19 16:43:37 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-06-19 16:43:37 -0400 |
commit | ea64ebfff9aae32deb036643422d3427959dcd24 (patch) | |
tree | 5ab83558642bad282515837424637070f547a05e /src/listeners/commands | |
parent | d055e0dbb86ef7fd4ee96a1531b51181e825fb4b (diff) | |
download | tanzanite-ea64ebfff9aae32deb036643422d3427959dcd24.tar.gz tanzanite-ea64ebfff9aae32deb036643422d3427959dcd24.tar.bz2 tanzanite-ea64ebfff9aae32deb036643422d3427959dcd24.zip |
feat(*): A bunch of stuff
- Remade logging
- updated dependencies
- started adding custom crap to the command handler
- added emojis to stuff
- can't remeber other stuff
Note: this is currently broken
BREAKING CHANGE:
Diffstat (limited to 'src/listeners/commands')
-rw-r--r-- | src/listeners/commands/commandBlocked.ts | 8 | ||||
-rw-r--r-- | src/listeners/commands/commandError.ts | 71 | ||||
-rw-r--r-- | src/listeners/commands/commandStarted.ts | 13 |
3 files changed, 62 insertions, 30 deletions
diff --git a/src/listeners/commands/commandBlocked.ts b/src/listeners/commands/commandBlocked.ts index 916f7cd..61433a6 100644 --- a/src/listeners/commands/commandBlocked.ts +++ b/src/listeners/commands/commandBlocked.ts @@ -1,6 +1,6 @@ -import { BushListener } from '../../lib/extensions/BushListener'; import { Command } from 'discord-akairo'; import { Message } from 'discord.js'; +import { BushListener } from '../../lib/extensions/BushListener'; export default class CommandBlockedListener extends BushListener { public constructor() { @@ -11,6 +11,12 @@ export default class CommandBlockedListener extends BushListener { } public async exec(message: Message, command: Command, reason: string): Promise<void> { + this.client.console.info( + 'CommandBlocked', + `<<${message.author.tag}>> tried to run <<${message.util.parsed.command}>> but was blocked because <<${reason}>>.`, + false + ); + switch (reason) { case 'owner': { await message.util.send(`You must be an owner to run command \`${message.util.parsed.command}\``); diff --git a/src/listeners/commands/commandError.ts b/src/listeners/commands/commandError.ts index 06aa55f..cb8c5d2 100644 --- a/src/listeners/commands/commandError.ts +++ b/src/listeners/commands/commandError.ts @@ -1,40 +1,65 @@ import { stripIndents } from 'common-tags'; -import { Message, MessageEmbed, TextChannel } from 'discord.js'; -import { BushCommand } from '../../lib/extensions/BushCommand'; +import { Command } from 'discord-akairo'; +import { MessageEmbed } from 'discord.js'; import { BushListener } from '../../lib/extensions/BushListener'; +import { BushMessage } from '../../lib/extensions/BushMessage'; export default class CommandErrorListener extends BushListener { - constructor() { - super('error', { + public constructor() { + super('commandError', { emitter: 'commandHandler', event: 'error' }); } - async exec(error: Error, message: Message, command?: BushCommand): Promise<void> { - const errorNumber = Math.floor(Math.random() * 6969696969) + 69; // hehe funy numbers - const errorDevEmbed = this.client.util - .createEmbed(this.client.util.colors.error) - .setTitle(`Error # \`${errorNumber}\`: An error occurred`) + + public async exec(error: Error, message: BushMessage, command: Command | null | undefined): Promise<void> { + const errorNo = Math.floor(Math.random() * 6969696969) + 69; // hehe funny number + const errorEmbed: MessageEmbed = new MessageEmbed() + .setTitle(`Error # \`${errorNo}\`: An error occurred`) .setDescription( stripIndents`**User:** ${message.author} (${message.author.tag}) **Command:** ${command} **Channel:** ${message.channel} (${message.channel.id}) **Message:** [link](${message.url})` ) - .addField('Error', `${await this.client.util.haste(error.stack)}`); - let errorUserEmbed: MessageEmbed; - if (command) { - errorUserEmbed = this.client.util - .createEmbed(this.client.util.colors.error) - .setTitle('An error occurred') - .setDescription( - stripIndents`Whoops! It appears like something broke. - The developers have been notified of this. If you contact them, give them code \`${errorNumber}\`. - ` - ); + .addField('Error', await this.client.util.codeblock(`${error?.stack}`, 1024, 'js')) + .setColor(this.client.util.colors.error) + .setTimestamp(); + + if (message) { + if (!this.client.config.owners.includes(message.author.id)) { + const errorUserEmbed: MessageEmbed = new MessageEmbed() + .setTitle('An 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 + errorUserEmbed.setDescription( + `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('CommandError', `Failed to send user error embed in <<${channel}>>:\n` + e?.stack); + }); + } else { + const errorDevEmbed = new MessageEmbed() + .setTitle('An 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('CommandError', `Failed to send owner error stack in <<${channel}>>.` + e?.stack); + }); + } } - const channel = (await this.client.channels.fetch(this.client.config.channels.log)) as TextChannel; - await channel.send({ embeds: [errorDevEmbed] }); - if (errorUserEmbed) await message.reply({ embeds: [errorUserEmbed] }); + const channel = message.channel.type === 'dm' ? message.channel.recipient.tag : message.channel.name; + this.client.console.error( + 'CommandError', + `an error occurred with the <<${command}>> command in <<${channel}>> triggered by <<${message?.author?.tag}>>:\n` + + error?.stack + ); } } diff --git a/src/listeners/commands/commandStarted.ts b/src/listeners/commands/commandStarted.ts index 1c5b0c7..28ed0f8 100644 --- a/src/listeners/commands/commandStarted.ts +++ b/src/listeners/commands/commandStarted.ts @@ -1,5 +1,4 @@ -import chalk from 'chalk'; -import { Message, DMChannel } from 'discord.js'; +import { Message } from 'discord.js'; import { BushCommand } from '../../lib/extensions/BushCommand'; import { BushListener } from '../../lib/extensions/BushListener'; @@ -11,10 +10,12 @@ export default class CommandStartedListener extends BushListener { }); } exec(message: Message, command: BushCommand): void { - this.client.logger.verbose( - chalk`{cyan {green ${message.author.tag}} is running {green ${command.aliases[0]}} in {green ${ - message.channel instanceof DMChannel ? 'DMs' : `#${message.channel.name} (Server: ${message.guild.name})` - }}.}` + this.client.logger.info( + 'Command', + `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 ); } } |