From 1546da359646b89f13d17784eb7653a52ca61efd Mon Sep 17 00:00:00 2001 From: TymanWasTaken <tyman@tyman.tech> Date: Thu, 27 May 2021 14:58:21 -0600 Subject: Fix file naming --- src/commands/dev/eval.ts | 138 ++++++++++++++++++++++++++++++++++++ src/commands/dev/evalCommand.ts | 138 ------------------------------------ src/commands/dev/reload.ts | 44 ++++++++++++ src/commands/dev/reloadCommand.ts | 44 ------------ src/commands/dev/setLevel.ts | 91 ++++++++++++++++++++++++ src/commands/dev/setLevelCommand.ts | 91 ------------------------ 6 files changed, 273 insertions(+), 273 deletions(-) create mode 100644 src/commands/dev/eval.ts delete mode 100644 src/commands/dev/evalCommand.ts create mode 100644 src/commands/dev/reload.ts delete mode 100644 src/commands/dev/reloadCommand.ts create mode 100644 src/commands/dev/setLevel.ts delete mode 100644 src/commands/dev/setLevelCommand.ts (limited to 'src/commands/dev') diff --git a/src/commands/dev/eval.ts b/src/commands/dev/eval.ts new file mode 100644 index 0000000..83e63f6 --- /dev/null +++ b/src/commands/dev/eval.ts @@ -0,0 +1,138 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { MessageEmbed, Message } from 'discord.js'; +import { inspect, promisify } from 'util'; +import { exec } from 'child_process'; + +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 BushCommand { + public constructor() { + super('eval', { + aliases: ['eval', 'ev'], + category: 'dev', + description: { + content: 'Use the command to eval stuff in the bot.', + usage: 'eval <code> [--silent] [--depth #]', + 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: Message, + { depth, code, silent }: { depth: number; code: string; silent: boolean } + ): Promise<void> { + 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 = require('got'); // eslint-disable-line @typescript-eslint/no-var-requires + 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('<a:Check_Mark:790373952760971294>'); + } catch (e) { + await message.react('❌'); + } + } + } +} diff --git a/src/commands/dev/evalCommand.ts b/src/commands/dev/evalCommand.ts deleted file mode 100644 index 83e63f6..0000000 --- a/src/commands/dev/evalCommand.ts +++ /dev/null @@ -1,138 +0,0 @@ -/* eslint-disable @typescript-eslint/no-unused-vars */ -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { MessageEmbed, Message } from 'discord.js'; -import { inspect, promisify } from 'util'; -import { exec } from 'child_process'; - -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 BushCommand { - public constructor() { - super('eval', { - aliases: ['eval', 'ev'], - category: 'dev', - description: { - content: 'Use the command to eval stuff in the bot.', - usage: 'eval <code> [--silent] [--depth #]', - 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: Message, - { depth, code, silent }: { depth: number; code: string; silent: boolean } - ): Promise<void> { - 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 = require('got'); // eslint-disable-line @typescript-eslint/no-var-requires - 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('<a:Check_Mark:790373952760971294>'); - } catch (e) { - await message.react('❌'); - } - } - } -} diff --git a/src/commands/dev/reload.ts b/src/commands/dev/reload.ts new file mode 100644 index 0000000..64e5745 --- /dev/null +++ b/src/commands/dev/reload.ts @@ -0,0 +1,44 @@ +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { stripIndent } from 'common-tags'; +import { Message } from 'discord.js'; +import { CommandInteraction } from 'discord.js'; + +export default class ReloadCommand extends BushCommand { + constructor() { + super('reload', { + aliases: ['reload'], + category: 'dev', + description: { + content: 'Reloads the bot', + usage: 'reload', + examples: ['reload'] + }, + ownerOnly: true, + typing: true + }); + } + + private async getResponse(): Promise<string> { + 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(); + return '🔁 Successfully reloaded!'; + } catch (e) { + return stripIndent` + An error occured while reloading: + ${await this.client.util.haste(e.stack)} + `; + } + } + + public async exec(message: Message): Promise<void> { + await message.util.send(await this.getResponse()); + } + + public async execSlash(message: CommandInteraction): Promise<void> { + await message.reply(await this.getResponse()); + } +} diff --git a/src/commands/dev/reloadCommand.ts b/src/commands/dev/reloadCommand.ts deleted file mode 100644 index 64e5745..0000000 --- a/src/commands/dev/reloadCommand.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { stripIndent } from 'common-tags'; -import { Message } from 'discord.js'; -import { CommandInteraction } from 'discord.js'; - -export default class ReloadCommand extends BushCommand { - constructor() { - super('reload', { - aliases: ['reload'], - category: 'dev', - description: { - content: 'Reloads the bot', - usage: 'reload', - examples: ['reload'] - }, - ownerOnly: true, - typing: true - }); - } - - private async getResponse(): Promise<string> { - 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(); - return '🔁 Successfully reloaded!'; - } catch (e) { - return stripIndent` - An error occured while reloading: - ${await this.client.util.haste(e.stack)} - `; - } - } - - public async exec(message: Message): Promise<void> { - await message.util.send(await this.getResponse()); - } - - public async execSlash(message: CommandInteraction): Promise<void> { - await message.reply(await this.getResponse()); - } -} diff --git a/src/commands/dev/setLevel.ts b/src/commands/dev/setLevel.ts new file mode 100644 index 0000000..d1701c5 --- /dev/null +++ b/src/commands/dev/setLevel.ts @@ -0,0 +1,91 @@ +import { ApplicationCommandOptionType } from 'discord-api-types'; +import { CommandInteraction } from 'discord.js'; +import { User } from 'discord.js'; +import { Message } from 'discord.js'; +import { BushCommand } from '../../lib/extensions/BushCommand'; +import { SlashCommandOption } from '../../lib/extensions/Util'; +import { Level } from '../../lib/models'; +import AllowedMentions from '../../lib/utils/AllowedMentions'; + +export default class SetLevelCommand extends BushCommand { + constructor() { + super('setlevel', { + aliases: ['setlevel'], + category: 'dev', + description: { + content: 'Sets the level of a user', + usage: 'setlevel <user> <level>', + examples: ['setlevel @Moulberry 69'] //nice + }, + args: [ + { + id: 'user', + type: 'user', + prompt: { + start: 'What user would you like to change the level of?', + retry: + 'Invalid user. What user would you like to change the level of?' + } + }, + { + id: 'level', + type: 'number', + prompt: { + start: 'What level would you like to set?', + retry: 'Invalid user. What level would you like to set?' + } + } + ], + ownerOnly: true, + slashCommandOptions: [ + { + type: ApplicationCommandOptionType.USER, + name: 'user', + description: 'The user to change the level of', + required: true + }, + { + type: ApplicationCommandOptionType.INTEGER, + name: 'level', + description: 'The level to set the user to', + required: true + } + ] + }); + } + + private async setLevel(user: User, level: number): Promise<string> { + const [levelEntry] = await Level.findOrBuild({ + where: { + id: user.id + }, + defaults: { + id: user.id + } + }); + levelEntry.xp = Level.convertLevelToXp(level); + await levelEntry.save(); + return `Successfully set level of <@${user.id}> to \`${level}\` (\`${levelEntry.xp}\` XP)`; + } + + async exec( + message: Message, + { user, level }: { user: User; level: number } + ): Promise<void> { + await message.util.send(await this.setLevel(user, level), { + allowedMentions: AllowedMentions.none() + }); + } + + async execSlash( + message: CommandInteraction, + { + user, + level + }: { user: SlashCommandOption<void>; level: SlashCommandOption<number> } + ): Promise<void> { + await message.reply(await this.setLevel(user.user, level.value), { + allowedMentions: AllowedMentions.none() + }); + } +} diff --git a/src/commands/dev/setLevelCommand.ts b/src/commands/dev/setLevelCommand.ts deleted file mode 100644 index d1701c5..0000000 --- a/src/commands/dev/setLevelCommand.ts +++ /dev/null @@ -1,91 +0,0 @@ -import { ApplicationCommandOptionType } from 'discord-api-types'; -import { CommandInteraction } from 'discord.js'; -import { User } from 'discord.js'; -import { Message } from 'discord.js'; -import { BushCommand } from '../../lib/extensions/BushCommand'; -import { SlashCommandOption } from '../../lib/extensions/Util'; -import { Level } from '../../lib/models'; -import AllowedMentions from '../../lib/utils/AllowedMentions'; - -export default class SetLevelCommand extends BushCommand { - constructor() { - super('setlevel', { - aliases: ['setlevel'], - category: 'dev', - description: { - content: 'Sets the level of a user', - usage: 'setlevel <user> <level>', - examples: ['setlevel @Moulberry 69'] //nice - }, - args: [ - { - id: 'user', - type: 'user', - prompt: { - start: 'What user would you like to change the level of?', - retry: - 'Invalid user. What user would you like to change the level of?' - } - }, - { - id: 'level', - type: 'number', - prompt: { - start: 'What level would you like to set?', - retry: 'Invalid user. What level would you like to set?' - } - } - ], - ownerOnly: true, - slashCommandOptions: [ - { - type: ApplicationCommandOptionType.USER, - name: 'user', - description: 'The user to change the level of', - required: true - }, - { - type: ApplicationCommandOptionType.INTEGER, - name: 'level', - description: 'The level to set the user to', - required: true - } - ] - }); - } - - private async setLevel(user: User, level: number): Promise<string> { - const [levelEntry] = await Level.findOrBuild({ - where: { - id: user.id - }, - defaults: { - id: user.id - } - }); - levelEntry.xp = Level.convertLevelToXp(level); - await levelEntry.save(); - return `Successfully set level of <@${user.id}> to \`${level}\` (\`${levelEntry.xp}\` XP)`; - } - - async exec( - message: Message, - { user, level }: { user: User; level: number } - ): Promise<void> { - await message.util.send(await this.setLevel(user, level), { - allowedMentions: AllowedMentions.none() - }); - } - - async execSlash( - message: CommandInteraction, - { - user, - level - }: { user: SlashCommandOption<void>; level: SlashCommandOption<number> } - ): Promise<void> { - await message.reply(await this.setLevel(user.user, level.value), { - allowedMentions: AllowedMentions.none() - }); - } -} -- cgit