From e0b2b559219d642d6b5353490ab60ae1a754b560 Mon Sep 17 00:00:00 2001 From: TymanWasTaken <32660892+tymanwastaken@users.noreply.github.com> Date: Tue, 11 May 2021 10:51:31 -0600 Subject: change commmand & listener file name formatting --- src/commands/owner/EvalCommand.ts | 139 ----------------------- src/commands/owner/ReloadCommand.ts | 34 ------ src/commands/owner/eval.ts | 139 +++++++++++++++++++++++ src/commands/owner/reload.ts | 34 ++++++ src/listeners/client/ReadyListener.ts | 16 --- src/listeners/client/ready.ts | 16 +++ src/listeners/commands/CommandBlockedListener.ts | 34 ------ src/listeners/commands/CommandErrorListener.ts | 48 -------- src/listeners/commands/commandblocked.ts | 34 ++++++ src/listeners/commands/error.ts | 48 ++++++++ 10 files changed, 271 insertions(+), 271 deletions(-) delete mode 100644 src/commands/owner/EvalCommand.ts delete mode 100644 src/commands/owner/ReloadCommand.ts create mode 100644 src/commands/owner/eval.ts create mode 100644 src/commands/owner/reload.ts delete mode 100644 src/listeners/client/ReadyListener.ts create mode 100644 src/listeners/client/ready.ts delete mode 100644 src/listeners/commands/CommandBlockedListener.ts delete mode 100644 src/listeners/commands/CommandErrorListener.ts create mode 100644 src/listeners/commands/commandblocked.ts create mode 100644 src/listeners/commands/error.ts (limited to 'src') diff --git a/src/commands/owner/EvalCommand.ts b/src/commands/owner/EvalCommand.ts deleted file mode 100644 index f1ada89..0000000 --- a/src/commands/owner/EvalCommand.ts +++ /dev/null @@ -1,139 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { BotCommand } from '../../lib/extensions/BotCommand'; -import { MessageEmbed, Message } from 'discord.js'; -import { inspect, promisify } from 'util'; -import { exec } from 'child_process'; -import { BotMessage } from '../../lib/extensions/BotMessage'; - -const clean = (text) => { - if (typeof text === 'string') - return text - .replace(/`/g, '`' + String.fromCharCode(8203)) - .replace(/@/g, '@' + String.fromCharCode(8203)); - else return text; -}; - -export default class EvalCommand extends BotCommand { - public constructor() { - super('eval', { - aliases: ['eval', 'ev'], - category: 'dev', - description: { - content: 'Use the command to eval stuff in the bot.', - usage: 'eval [--depth #] [--sudo] [--silent] [--delete]', - examples: ['eval message.guild.name', 'eval this.client.ownerID'] - }, - args: [ - { - id: 'depth', - match: 'option', - type: 'number', - flag: '--depth', - default: 0 - }, - { - id: 'silent', - match: 'flag', - flag: '--silent' - }, - { - id: 'code', - match: 'rest', - type: 'string', - prompt: { - start: 'What would you like to eval?', - retry: 'Invalid code to eval. What would you like to eval?' - } - } - ], - ownerOnly: true, - clientPermissions: ['EMBED_LINKS'] - }); - } - - public async exec( - message: BotMessage, - { depth, code, silent }: { depth: number; code: string; silent: boolean } - ): Promise { - const embed: MessageEmbed = new MessageEmbed(); - - try { - let output; - const me = message.member, - member = message.member, - bot = this.client, - guild = message.guild, - channel = message.channel, - config = this.client.config, - sh = promisify(exec), - models = this.client.db.models, - got = await import('got'); - output = eval(code); - output = await output; - if (typeof output !== 'string') output = inspect(output, { depth }); - output = output.replace( - new RegExp(this.client.token, 'g'), - '[token omitted]' - ); - output = clean(output); - embed - .setTitle('✅ Evaled code successfully') - .addField( - '📥 Input', - code.length > 1012 - ? 'Too large to display. Hastebin: ' + - (await this.client.util.haste(code)) - : '```js\n' + code + '```' - ) - .addField( - '📤 Output', - output.length > 1012 - ? 'Too large to display. Hastebin: ' + - (await this.client.util.haste(output)) - : '```js\n' + output + '```' - ) - .setColor('#66FF00') - .setFooter( - message.author.username, - message.author.displayAvatarURL({ dynamic: true }) - ) - .setTimestamp(); - } catch (e) { - embed - .setTitle('❌ Code was not able to be evaled') - .addField( - '📥 Input', - code.length > 1012 - ? 'Too large to display. Hastebin: ' + - (await this.client.util.haste(code)) - : '```js\n' + code + '```' - ) - .addField( - '📤 Output', - e.length > 1012 - ? 'Too large to display. Hastebin: ' + - (await this.client.util.haste(e)) - : '```js\n' + - e + - '```Full stack:' + - (await this.client.util.haste(e.stack)) - ) - .setColor('#FF0000') - .setFooter( - message.author.username, - message.author.displayAvatarURL({ dynamic: true }) - ) - .setTimestamp(); - } - if (!silent) { - await message.util.send(embed); - } else { - try { - await message.author.send(embed); - await message.react(''); - } catch (e) { - await message.react('❌'); - } - } - } -} diff --git a/src/commands/owner/ReloadCommand.ts b/src/commands/owner/ReloadCommand.ts deleted file mode 100644 index 2311424..0000000 --- a/src/commands/owner/ReloadCommand.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { BotCommand } from '../../lib/extensions/BotCommand'; -import { stripIndent } from 'common-tags'; -import { BotMessage } from '../../lib/extensions/BotMessage'; - -export default class ReloadCommand extends BotCommand { - constructor() { - super('reload', { - aliases: ['reload'], - description: { - content: 'Reloads the bot', - usage: 'reload', - examples: ['reload'] - }, - ownerOnly: true, - typing: true - }); - } - - public async exec(message: BotMessage): Promise { - try { - await this.client.util.shell('yarn rimraf dist/'); - await this.client.util.shell('yarn tsc'); - this.client.commandHandler.reloadAll(); - this.client.listenerHandler.reloadAll(); - this.client.inhibitorHandler.reloadAll(); - await message.util.send('🔁 Successfully reloaded!'); - } catch (e) { - await message.util.send(stripIndent` - An error occured while reloading: - ${await this.client.util.haste(e.stack)} - `); - } - } -} diff --git a/src/commands/owner/eval.ts b/src/commands/owner/eval.ts new file mode 100644 index 0000000..f1ada89 --- /dev/null +++ b/src/commands/owner/eval.ts @@ -0,0 +1,139 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +import { BotCommand } from '../../lib/extensions/BotCommand'; +import { MessageEmbed, Message } from 'discord.js'; +import { inspect, promisify } from 'util'; +import { exec } from 'child_process'; +import { BotMessage } from '../../lib/extensions/BotMessage'; + +const clean = (text) => { + if (typeof text === 'string') + return text + .replace(/`/g, '`' + String.fromCharCode(8203)) + .replace(/@/g, '@' + String.fromCharCode(8203)); + else return text; +}; + +export default class EvalCommand extends BotCommand { + public constructor() { + super('eval', { + aliases: ['eval', 'ev'], + category: 'dev', + description: { + content: 'Use the command to eval stuff in the bot.', + usage: 'eval [--depth #] [--sudo] [--silent] [--delete]', + examples: ['eval message.guild.name', 'eval this.client.ownerID'] + }, + args: [ + { + id: 'depth', + match: 'option', + type: 'number', + flag: '--depth', + default: 0 + }, + { + id: 'silent', + match: 'flag', + flag: '--silent' + }, + { + id: 'code', + match: 'rest', + type: 'string', + prompt: { + start: 'What would you like to eval?', + retry: 'Invalid code to eval. What would you like to eval?' + } + } + ], + ownerOnly: true, + clientPermissions: ['EMBED_LINKS'] + }); + } + + public async exec( + message: BotMessage, + { depth, code, silent }: { depth: number; code: string; silent: boolean } + ): Promise { + const embed: MessageEmbed = new MessageEmbed(); + + try { + let output; + const me = message.member, + member = message.member, + bot = this.client, + guild = message.guild, + channel = message.channel, + config = this.client.config, + sh = promisify(exec), + models = this.client.db.models, + got = await import('got'); + output = eval(code); + output = await output; + if (typeof output !== 'string') output = inspect(output, { depth }); + output = output.replace( + new RegExp(this.client.token, 'g'), + '[token omitted]' + ); + output = clean(output); + embed + .setTitle('✅ Evaled code successfully') + .addField( + '📥 Input', + code.length > 1012 + ? 'Too large to display. Hastebin: ' + + (await this.client.util.haste(code)) + : '```js\n' + code + '```' + ) + .addField( + '📤 Output', + output.length > 1012 + ? 'Too large to display. Hastebin: ' + + (await this.client.util.haste(output)) + : '```js\n' + output + '```' + ) + .setColor('#66FF00') + .setFooter( + message.author.username, + message.author.displayAvatarURL({ dynamic: true }) + ) + .setTimestamp(); + } catch (e) { + embed + .setTitle('❌ Code was not able to be evaled') + .addField( + '📥 Input', + code.length > 1012 + ? 'Too large to display. Hastebin: ' + + (await this.client.util.haste(code)) + : '```js\n' + code + '```' + ) + .addField( + '📤 Output', + e.length > 1012 + ? 'Too large to display. Hastebin: ' + + (await this.client.util.haste(e)) + : '```js\n' + + e + + '```Full stack:' + + (await this.client.util.haste(e.stack)) + ) + .setColor('#FF0000') + .setFooter( + message.author.username, + message.author.displayAvatarURL({ dynamic: true }) + ) + .setTimestamp(); + } + if (!silent) { + await message.util.send(embed); + } else { + try { + await message.author.send(embed); + await message.react(''); + } catch (e) { + await message.react('❌'); + } + } + } +} diff --git a/src/commands/owner/reload.ts b/src/commands/owner/reload.ts new file mode 100644 index 0000000..2311424 --- /dev/null +++ b/src/commands/owner/reload.ts @@ -0,0 +1,34 @@ +import { BotCommand } from '../../lib/extensions/BotCommand'; +import { stripIndent } from 'common-tags'; +import { BotMessage } from '../../lib/extensions/BotMessage'; + +export default class ReloadCommand extends BotCommand { + constructor() { + super('reload', { + aliases: ['reload'], + description: { + content: 'Reloads the bot', + usage: 'reload', + examples: ['reload'] + }, + ownerOnly: true, + typing: true + }); + } + + public async exec(message: BotMessage): Promise { + try { + await this.client.util.shell('yarn rimraf dist/'); + await this.client.util.shell('yarn tsc'); + this.client.commandHandler.reloadAll(); + this.client.listenerHandler.reloadAll(); + this.client.inhibitorHandler.reloadAll(); + await message.util.send('🔁 Successfully reloaded!'); + } catch (e) { + await message.util.send(stripIndent` + An error occured while reloading: + ${await this.client.util.haste(e.stack)} + `); + } + } +} diff --git a/src/listeners/client/ReadyListener.ts b/src/listeners/client/ReadyListener.ts deleted file mode 100644 index ae510f6..0000000 --- a/src/listeners/client/ReadyListener.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { BotListener } from '../../lib/extensions/BotListener'; - -export default class CommandBlockedListener extends BotListener { - public constructor() { - super('ready', { - emitter: 'client', - event: 'ready' - }); - } - - public async exec(): Promise { - await this.client.util.info( - `Sucessfully logged in as ${this.client.user.tag}` - ); - } -} diff --git a/src/listeners/client/ready.ts b/src/listeners/client/ready.ts new file mode 100644 index 0000000..ae510f6 --- /dev/null +++ b/src/listeners/client/ready.ts @@ -0,0 +1,16 @@ +import { BotListener } from '../../lib/extensions/BotListener'; + +export default class CommandBlockedListener extends BotListener { + public constructor() { + super('ready', { + emitter: 'client', + event: 'ready' + }); + } + + public async exec(): Promise { + await this.client.util.info( + `Sucessfully logged in as ${this.client.user.tag}` + ); + } +} diff --git a/src/listeners/commands/CommandBlockedListener.ts b/src/listeners/commands/CommandBlockedListener.ts deleted file mode 100644 index 82e53a9..0000000 --- a/src/listeners/commands/CommandBlockedListener.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { BotListener } from '../../lib/extensions/BotListener'; -import { Command } from 'discord-akairo'; -import { Message } from 'discord.js'; - -export default class CommandBlockedListener extends BotListener { - public constructor() { - super('commandBlocked', { - emitter: 'commandHandler', - event: 'commandBlocked' - }); - } - - public async exec( - message: Message, - command: Command, - reason: string - ): Promise { - switch (reason) { - case 'owner': { - await message.util.send( - `You must be an owner to run command \`${message.util.parsed.command}\`` - ); - break; - } - case 'blacklist': { - // pass - break; - } - default: { - await message.util.send(`Command blocked with reason \`${reason}\``); - } - } - } -} diff --git a/src/listeners/commands/CommandErrorListener.ts b/src/listeners/commands/CommandErrorListener.ts deleted file mode 100644 index 37179e7..0000000 --- a/src/listeners/commands/CommandErrorListener.ts +++ /dev/null @@ -1,48 +0,0 @@ -import { BotCommand } from '../../lib/extensions/BotCommand'; -import { BotListener } from '../../lib/extensions/BotListener'; -import { stripIndents } from 'common-tags'; -import { Message } from 'discord.js'; -import { MessageEmbed } from 'discord.js'; -import { TextChannel } from 'discord.js'; - -export default class CommandErrorListener extends BotListener { - constructor() { - super('error', { - emitter: 'commandHandler', - event: 'error' - }); - } - async exec( - error: Error, - message: Message, - command?: BotCommand - ): Promise { - 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`) - .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}\`. - ` - ); - } - const channel = (await this.client.channels.fetch( - this.client.config.channels.log - )) as TextChannel; - await channel.send(errorDevEmbed); - if (errorUserEmbed) await message.reply(errorUserEmbed); - } -} diff --git a/src/listeners/commands/commandblocked.ts b/src/listeners/commands/commandblocked.ts new file mode 100644 index 0000000..82e53a9 --- /dev/null +++ b/src/listeners/commands/commandblocked.ts @@ -0,0 +1,34 @@ +import { BotListener } from '../../lib/extensions/BotListener'; +import { Command } from 'discord-akairo'; +import { Message } from 'discord.js'; + +export default class CommandBlockedListener extends BotListener { + public constructor() { + super('commandBlocked', { + emitter: 'commandHandler', + event: 'commandBlocked' + }); + } + + public async exec( + message: Message, + command: Command, + reason: string + ): Promise { + switch (reason) { + case 'owner': { + await message.util.send( + `You must be an owner to run command \`${message.util.parsed.command}\`` + ); + break; + } + case 'blacklist': { + // pass + break; + } + default: { + await message.util.send(`Command blocked with reason \`${reason}\``); + } + } + } +} diff --git a/src/listeners/commands/error.ts b/src/listeners/commands/error.ts new file mode 100644 index 0000000..37179e7 --- /dev/null +++ b/src/listeners/commands/error.ts @@ -0,0 +1,48 @@ +import { BotCommand } from '../../lib/extensions/BotCommand'; +import { BotListener } from '../../lib/extensions/BotListener'; +import { stripIndents } from 'common-tags'; +import { Message } from 'discord.js'; +import { MessageEmbed } from 'discord.js'; +import { TextChannel } from 'discord.js'; + +export default class CommandErrorListener extends BotListener { + constructor() { + super('error', { + emitter: 'commandHandler', + event: 'error' + }); + } + async exec( + error: Error, + message: Message, + command?: BotCommand + ): Promise { + 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`) + .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}\`. + ` + ); + } + const channel = (await this.client.channels.fetch( + this.client.config.channels.log + )) as TextChannel; + await channel.send(errorDevEmbed); + if (errorUserEmbed) await message.reply(errorUserEmbed); + } +} -- cgit