diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-01-01 08:53:23 -0500 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-01-01 08:53:23 -0500 |
commit | e0ae0639d0b36c3cfd4065f791b95a32c1d7ea64 (patch) | |
tree | 46547b51ad50b0a7a73fbc848ad643f8736399ae /src/commands/dev | |
parent | cbb68773614e44eb246e4cf2ff0d64d3e90f620f (diff) | |
download | tanzanite-e0ae0639d0b36c3cfd4065f791b95a32c1d7ea64.tar.gz tanzanite-e0ae0639d0b36c3cfd4065f791b95a32c1d7ea64.tar.bz2 tanzanite-e0ae0639d0b36c3cfd4065f791b95a32c1d7ea64.zip |
added autocomplete to a few commands and performed some fixes
Diffstat (limited to 'src/commands/dev')
-rw-r--r-- | src/commands/dev/eval.ts | 120 | ||||
-rw-r--r-- | src/commands/dev/javascript.ts | 12 |
2 files changed, 62 insertions, 70 deletions
diff --git a/src/commands/dev/eval.ts b/src/commands/dev/eval.ts index ac114ea..5b2f27a 100644 --- a/src/commands/dev/eval.ts +++ b/src/commands/dev/eval.ts @@ -1,10 +1,45 @@ -import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +/* eslint-disable @typescript-eslint/no-unused-vars */ +import { + ActivePunishment, + BushCommand, + BushMessage, + BushSlashMessage, + Global, + Guild, + Level, + ModLog, + StickyRole, + type ArgType +} from '#lib'; +import { Canvas } from 'canvas'; import { exec } from 'child_process'; -import { MessageEmbed as _MessageEmbed } from 'discord.js'; +import { + ButtonInteraction, + Collection, + Collector, + CommandInteraction, + ContextMenuInteraction, + DMChannel, + Emoji, + Interaction, + InteractionCollector, + Message, + MessageActionRow, + MessageAttachment, + MessageButton, + MessageCollector, + MessageEmbed, + MessageSelectMenu, + ReactionCollector, + Util +} from 'discord.js'; import ts from 'typescript'; import { promisify } from 'util'; - -const { transpile } = ts; +const { transpile } = ts, + emojis = util.emojis, + colors = util.colors, + sh = promisify(exec); +/* eslint-enable @typescript-eslint/no-unused-vars */ export default class EvalCommand extends BushCommand { public constructor() { @@ -21,8 +56,7 @@ export default class EvalCommand extends BushCommand { match: 'rest', prompt: 'What would you like to eval?', retry: '{error} Invalid code to eval.', - slashType: 'STRING', - only: 'slash' + slashType: 'STRING' }, { id: 'sel_depth', @@ -98,15 +132,6 @@ export default class EvalCommand extends BushCommand { prompt: 'Would you like to inspect the prototype chain to find methods?', slashType: 'BOOLEAN', optional: true - }, - { - id: 'code', - description: 'The code you would like to evaluate.', - match: 'rest', - prompt: 'What would you like to eval?', - retry: '{error} Invalid code to eval.', - slashType: 'STRING', - only: 'text' } ], slash: true, @@ -120,14 +145,14 @@ export default class EvalCommand extends BushCommand { message: BushMessage | BushSlashMessage, args: { sel_depth: ArgType<'integer'>; - code: string; - sudo: boolean; - silent: boolean; - deleteMSG: boolean; - typescript: boolean; - hidden: boolean; - show_proto: boolean; - show_methods: boolean; + code: ArgType<'string'>; + sudo: ArgType<'boolean'>; + silent: ArgType<'boolean'>; + deleteMSG: ArgType<'boolean'>; + typescript: ArgType<'boolean'>; + hidden: ArgType<'boolean'>; + show_proto: ArgType<'boolean'>; + show_methods: ArgType<'boolean'>; } ) { if (!message.author.isOwner()) @@ -135,16 +160,16 @@ export default class EvalCommand extends BushCommand { if (message.util.isSlashMessage(message)) { await message.interaction.deferReply({ ephemeral: args.silent }); } - const _isTypescript = args.typescript || args.code.includes('```ts'); - const _code = args.code.replace(/[“”]/g, '"').replace(/```*(?:js|ts)?/g, ''); + const isTypescript = args.typescript || args.code.includes('```ts'); + const rawCode = args.code.replace(/[“”]/g, '"').replace(/```*(?:js|ts)?/g, ''); const code: { ts: string | null; js: string; lang: 'ts' | 'js' } = { - ts: _isTypescript ? _code : null, - js: _isTypescript ? transpile(_code) : _code, - lang: _isTypescript ? 'ts' : 'js' + ts: isTypescript ? rawCode : null, + js: isTypescript ? transpile(rawCode) : rawCode, + lang: isTypescript ? 'ts' : 'js' }; - const embed = new _MessageEmbed(); + const embed = new MessageEmbed(); const badPhrases = ['delete', 'destroy']; if (badPhrases.some((p) => code[code.lang]!.includes(p)) && !args.sudo) { @@ -152,39 +177,14 @@ export default class EvalCommand extends BushCommand { } /* eslint-disable @typescript-eslint/no-unused-vars */ - const sh = promisify(exec), - me = message.member, + const me = message.member, member = message.member, bot = client, guild = message.guild, channel = message.channel, config = client.config, members = message.guild?.members, - roles = message.guild?.roles, - emojis = util.emojis, - colors = util.colors, - { ActivePunishment, Global, Guild, Level, ModLog, StickyRole } = await import('#lib'), - { - ButtonInteraction, - Collection, - Collector, - CommandInteraction, - ContextMenuInteraction, - DMChannel, - Emoji, - Interaction, - InteractionCollector, - Message, - MessageActionRow, - MessageAttachment, - MessageButton, - MessageCollector, - MessageEmbed, - MessageSelectMenu, - ReactionCollector, - Util - } = await import('discord.js'), - { Canvas } = await import('canvas'); + roles = message.guild?.roles; /* eslint-enable @typescript-eslint/no-unused-vars */ const inputJS = await util.inspectCleanRedactCodeblock(code.js, 'js'); @@ -228,11 +228,13 @@ export default class EvalCommand extends BushCommand { } else { try { await message.author.send({ embeds: [embed] }); - if (!args.deleteMSG) await (message as BushMessage).react(emojis.successFull); + if (!args.deleteMSG) await message.react(emojis.successFull); } catch { - if (!args.deleteMSG) await (message as BushMessage).react(emojis.errorFull); + if (!args.deleteMSG) await message.react(emojis.errorFull); } } - if (args.deleteMSG && (message as BushMessage).deletable) await (message as BushMessage).delete(); + if (args.deleteMSG && 'deletable' in message && message.deletable) await message.delete(); } } + +/** @typedef {ActivePunishment|Global|Guild|Level|ModLog|StickyRole|ButtonInteraction|Collection|Collector|CommandInteraction|ContextMenuInteraction|DMChannel|Emoji|Interaction|InteractionCollector|Message|MessageActionRow|MessageAttachment|MessageButton|MessageCollector|MessageSelectMenu|ReactionCollector|Util|Canvas} VSCodePleaseDontRemove */ diff --git a/src/commands/dev/javascript.ts b/src/commands/dev/javascript.ts index a5f90cb..8c5dcb4 100644 --- a/src/commands/dev/javascript.ts +++ b/src/commands/dev/javascript.ts @@ -17,8 +17,7 @@ export default class JavascriptCommand extends BushCommand { match: 'rest', prompt: 'What code would you like to run in a sand boxed environment?', retry: '{error} Invalid code to run in a sand boxed environment.', - slashType: 'STRING', - only: 'slash' + slashType: 'STRING' }, { id: 'sel_depth', @@ -30,15 +29,6 @@ export default class JavascriptCommand extends BushCommand { prompt: 'How deep would you like to inspect the output?', slashType: 'INTEGER', optional: true - }, - { - id: 'code', - description: 'The code you would like to run in a sand boxed environment.', - match: 'rest', - prompt: 'What code would you like to run in a sand boxed environment?', - retry: '{error} Invalid code to run in a sand boxed environment.', - slashType: 'STRING', - only: 'text' } ], slash: true, |