diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-01-23 18:13:05 -0500 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-01-23 18:13:05 -0500 |
commit | a3f8d3884a1deca5eccfb6d990e2a7b42fbbe08a (patch) | |
tree | 9b0f8ed8a93c22c90512751e3f2f5937e1925760 /src/commands/dev | |
parent | 5557677f1570eb564a30cfcebb6030235dc84d47 (diff) | |
download | tanzanite-a3f8d3884a1deca5eccfb6d990e2a7b42fbbe08a.tar.gz tanzanite-a3f8d3884a1deca5eccfb6d990e2a7b42fbbe08a.tar.bz2 tanzanite-a3f8d3884a1deca5eccfb6d990e2a7b42fbbe08a.zip |
fix discord.js breaking changes, some other stuff
Diffstat (limited to 'src/commands/dev')
-rw-r--r-- | src/commands/dev/__template.ts | 5 | ||||
-rw-r--r-- | src/commands/dev/debug.ts | 79 | ||||
-rw-r--r-- | src/commands/dev/dm.ts | 6 | ||||
-rw-r--r-- | src/commands/dev/eval.ts | 39 | ||||
-rw-r--r-- | src/commands/dev/javascript.ts | 10 | ||||
-rw-r--r-- | src/commands/dev/reload.ts | 2 | ||||
-rw-r--r-- | src/commands/dev/say.ts | 3 | ||||
-rw-r--r-- | src/commands/dev/sh.ts | 7 | ||||
-rw-r--r-- | src/commands/dev/test.ts | 75 |
9 files changed, 147 insertions, 79 deletions
diff --git a/src/commands/dev/__template.ts b/src/commands/dev/__template.ts index 6adba08..7ea1784 100644 --- a/src/commands/dev/__template.ts +++ b/src/commands/dev/__template.ts @@ -1,4 +1,5 @@ import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage, type OptionalArgType } from '#lib'; +import { ApplicationCommandOptionType } from 'discord.js'; export default class TemplateCommand extends BushCommand { public constructor() { @@ -15,7 +16,7 @@ export default class TemplateCommand extends BushCommand { type: 'string', prompt: 'What would you like to set your first argument to be?', retry: '{error} Pick a valid argument.', - slashType: 'STRING' + slashType: ApplicationCommandOptionType.String }, { id: 'optional_argument', @@ -24,7 +25,7 @@ export default class TemplateCommand extends BushCommand { prompt: 'What would you like to set your second argument to be?', retry: '{error} Pick a valid argument.', optional: true, - slashType: 'STRING' + slashType: ApplicationCommandOptionType.String } ], slash: false, //set this to true diff --git a/src/commands/dev/debug.ts b/src/commands/dev/debug.ts new file mode 100644 index 0000000..f8c614d --- /dev/null +++ b/src/commands/dev/debug.ts @@ -0,0 +1,79 @@ +// import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +// import { ApplicationCommandOptionType, AutocompleteInteraction, ChatInputCommandInteraction } from 'discord.js'; +// import Fuse from 'fuse.js'; + +// export default class DebugCommand extends BushCommand { +// public constructor() { +// super('debug', { +// aliases: ['debug'], +// category: 'debug', +// description: 'Command description.', +// usage: ['template <requiredArg> [optionalArg]'], +// examples: ['template 1 2'], +// args: [ +// { +// id: 'action', +// description: 'Debug action.', +// type: 'string', +// prompt: 'Debug action.', +// retry: '{error} Pick valid action.', +// slashType: ApplicationCommandOptionType.String, +// autocomplete: true +// } +// ], +// slash: true, +// slashGuilds: ['516977525906341928'], +// superUserOnly: true, +// clientPermissions: (m) => util.clientSendAndPermCheck(m), +// userPermissions: [] +// }); +// } + +// public override async exec(message: BushMessage | BushSlashMessage, args: { action: ArgType<'string'> }) { +// if (args.action === 'util.reply') { +// return await message.util.reply(`This is a util.reply`); +// } else if (args.action === 'util.reply-object') { +// return await message.util.reply({ +// content: `This is a util.reply with object parameters`, +// embeds: [{ description: 'And an embed' }] +// }); +// } else if (args.action === 'util.send') { +// return await message.util.send(`This is a util.send`); +// } else if (args.action === 'util.send-object') { +// return await message.util.send({ +// content: `This is a util.send with object parameters`, +// embeds: [{ description: 'And an embed' }] +// }); +// } else if (args.action === 'interaction.reply') { +// return await (message.interaction as ChatInputCommandInteraction).reply(`This is a interaction.reply`); +// } else if (args.action === 'interaction.reply-object') { +// return await (message.interaction as ChatInputCommandInteraction).reply({ +// content: `This is a interaction.reply with object parameters`, +// embeds: [{ description: 'And an embed' }] +// }); +// } else { +// return await message.util.reply(`${util.emojis.error} Invalid action.`); +// } +// } + +// public override autocomplete(interaction: AutocompleteInteraction) { +// const actions = [ +// 'util.reply', +// 'util.reply-object', +// 'util.send', +// 'util.send-object', +// 'interaction.reply', +// 'interaction.reply-object' +// ]; + +// const fuzzy = new Fuse(actions, { +// threshold: 0.5, +// isCaseSensitive: false, +// findAllMatches: true +// }).search(interaction.options.getFocused().toString()); + +// const res = fuzzy.slice(0, fuzzy.length >= 25 ? 25 : undefined).map((v) => ({ name: v.item, value: v.item })); + +// void interaction.respond(res.length ? res : actions.map((v) => ({ name: v, value: v }))); +// } +// } diff --git a/src/commands/dev/dm.ts b/src/commands/dev/dm.ts index d702875..0646f59 100644 --- a/src/commands/dev/dm.ts +++ b/src/commands/dev/dm.ts @@ -1,4 +1,5 @@ import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { ApplicationCommandOptionType } from 'discord.js'; export default class DMCommand extends BushCommand { public constructor() { @@ -15,7 +16,7 @@ export default class DMCommand extends BushCommand { description: 'The user to send the dm to.', prompt: 'Who would you like to dm?', retry: '{error} Pick a valid user to send a dm to.', - slashType: 'STRING' + slashType: ApplicationCommandOptionType.String }, { id: 'content', @@ -24,7 +25,7 @@ export default class DMCommand extends BushCommand { description: 'The content to send to the user.', prompt: 'What would you like to send to the user?', retry: '{error} Pick something to send the user.', - slashType: 'STRING' + slashType: ApplicationCommandOptionType.String } ], slash: false, @@ -34,6 +35,7 @@ export default class DMCommand extends BushCommand { userPermissions: [] }); } + public override async exec( message: BushMessage | BushSlashMessage, args: { user: ArgType<'user'>; content: ArgType<'string'> } diff --git a/src/commands/dev/eval.ts b/src/commands/dev/eval.ts index 656eeff..92b1117 100644 --- a/src/commands/dev/eval.ts +++ b/src/commands/dev/eval.ts @@ -12,26 +12,28 @@ import { StickyRole, type ArgType } from '#lib'; +import { Snowflake as Snowflake_ } from '@sapphire/snowflake'; import { Canvas } from 'canvas'; import { exec } from 'child_process'; import { + ActionRow, + ApplicationCommandOptionType, + ButtonComponent, ButtonInteraction, Collection, Collector, CommandInteraction, - ContextMenuInteraction, + ContextMenuCommandInteraction, DMChannel, Emoji, Interaction, InteractionCollector, Message, - MessageActionRow, MessageAttachment, - MessageButton, MessageCollector, MessageEmbed, - MessageSelectMenu, ReactionCollector, + SelectMenuComponent, Util } from 'discord.js'; import ts from 'typescript'; @@ -39,7 +41,8 @@ import { promisify } from 'util'; const { transpile } = ts, emojis = util.emojis, colors = util.colors, - sh = promisify(exec); + sh = promisify(exec), + SnowflakeUtil = new Snowflake_(1420070400000n); /* eslint-enable @typescript-eslint/no-unused-vars */ export default class EvalCommand extends BushCommand { @@ -57,7 +60,7 @@ export default class EvalCommand extends BushCommand { match: 'rest', prompt: 'What would you like to eval?', retry: '{error} Invalid code to eval.', - slashType: 'STRING' + slashType: ApplicationCommandOptionType.String }, { id: 'sel_depth', @@ -67,7 +70,7 @@ export default class EvalCommand extends BushCommand { flag: '--depth', default: 0, prompt: 'How deep would you like to inspect the output?', - slashType: 'INTEGER', + slashType: ApplicationCommandOptionType.Integer, optional: true }, { @@ -76,7 +79,7 @@ export default class EvalCommand extends BushCommand { match: 'flag', flag: '--sudo', prompt: 'Would you like to override checks?', - slashType: 'BOOLEAN', + slashType: ApplicationCommandOptionType.Boolean, optional: true }, { @@ -95,7 +98,7 @@ export default class EvalCommand extends BushCommand { match: 'flag', flag: '--silent', prompt: 'Would you like to make the response silent?', - slashType: 'BOOLEAN', + slashType: ApplicationCommandOptionType.Boolean, optional: true }, { @@ -104,7 +107,7 @@ export default class EvalCommand extends BushCommand { match: 'flag', flag: '--ts', prompt: 'Is this code written in typescript?', - slashType: 'BOOLEAN', + slashType: ApplicationCommandOptionType.Boolean, optional: true }, { @@ -113,7 +116,7 @@ export default class EvalCommand extends BushCommand { match: 'flag', flag: '--hidden', prompt: 'Would you like to show hidden items?', - slashType: 'BOOLEAN', + slashType: ApplicationCommandOptionType.Boolean, optional: true }, { @@ -122,7 +125,7 @@ export default class EvalCommand extends BushCommand { match: 'flag', flag: '--proto', prompt: 'Would you like to show the prototype of the output?', - slashType: 'BOOLEAN', + slashType: ApplicationCommandOptionType.Boolean, optional: true }, { @@ -131,7 +134,7 @@ export default class EvalCommand extends BushCommand { match: 'flag', flag: ['--func', '--function', '--functions', '--meth', '--method', '--methods'], prompt: 'Would you like to inspect the prototype chain to find methods?', - slashType: 'BOOLEAN', + slashType: ApplicationCommandOptionType.Boolean, optional: true }, { @@ -140,7 +143,7 @@ export default class EvalCommand extends BushCommand { match: 'flag', flag: '--async', prompt: 'Would you like to wrap the code in an async function?', - slashType: 'BOOLEAN', + slashType: ApplicationCommandOptionType.Boolean, optional: true }, { @@ -149,7 +152,7 @@ export default class EvalCommand extends BushCommand { match: 'flag', flag: ['--strings', '--string'], prompt: 'Would you like to not inspect strings?', - slashType: 'BOOLEAN', + slashType: ApplicationCommandOptionType.Boolean, optional: true } ], @@ -242,9 +245,7 @@ export default class EvalCommand extends BushCommand { embed.addField('📤 Error', await util.inspectCleanRedactCodeblock(e, 'js')); } - embed - .setTimestamp() - .setFooter({ text: message.author.tag, iconURL: message.author.displayAvatarURL({ dynamic: true }) ?? undefined }); + embed.setTimestamp().setFooter({ text: message.author.tag, iconURL: message.author.displayAvatarURL() ?? undefined }); if (!args.silent || message.util.isSlashMessage(message)) { await message.util.reply({ embeds: [embed] }); @@ -260,4 +261,4 @@ export default class EvalCommand extends BushCommand { } } -/** @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|Shared} VSCodePleaseDontRemove */ +/** @typedef {ActivePunishment|Global|Guild|Level|ModLog|StickyRole|ButtonInteraction|Collection|Collector|CommandInteraction|ContextMenuCommandInteraction|DMChannel|Emoji|Interaction|InteractionCollector|Message|ActionRow|MessageAttachment|ButtonComponent|MessageCollector|SelectMenuComponent|ReactionCollector|Util|Canvas|Shared} VSCodePleaseDontRemove */ diff --git a/src/commands/dev/javascript.ts b/src/commands/dev/javascript.ts index c8113aa..9d6a20b 100644 --- a/src/commands/dev/javascript.ts +++ b/src/commands/dev/javascript.ts @@ -1,6 +1,6 @@ import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; import assert from 'assert'; -import { MessageEmbed } from 'discord.js'; +import { ApplicationCommandOptionType, MessageEmbed } from 'discord.js'; import { VM } from 'vm2'; assert(VM); @@ -19,7 +19,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' + slashType: ApplicationCommandOptionType.String }, { id: 'sel_depth', @@ -29,7 +29,7 @@ export default class JavascriptCommand extends BushCommand { flag: '--depth', default: 0, prompt: 'How deep would you like to inspect the output?', - slashType: 'INTEGER', + slashType: ApplicationCommandOptionType.Integer, optional: true } ], @@ -75,9 +75,7 @@ export default class JavascriptCommand extends BushCommand { embed.addField('📤 Error', await util.inspectCleanRedactCodeblock(e, 'js')); } - embed - .setTimestamp() - .setFooter({ text: message.author.tag, iconURL: message.author.displayAvatarURL({ dynamic: true }) ?? undefined }); + embed.setTimestamp().setFooter({ text: message.author.tag, iconURL: message.author.displayAvatarURL() ?? undefined }); await message.util.reply({ embeds: [embed] }); } diff --git a/src/commands/dev/reload.ts b/src/commands/dev/reload.ts index 6d030b7..d874c83 100644 --- a/src/commands/dev/reload.ts +++ b/src/commands/dev/reload.ts @@ -16,7 +16,7 @@ export default class ReloadCommand extends BushCommand { // flag: '--fast', // prompt: 'Would you like to use esbuild for fast compiling?', // optional: true, - // slashType:'BOOLEAN' + // slashType: ApplicationCommandOptionType.Boolean // } // ], ownerOnly: true, diff --git a/src/commands/dev/say.ts b/src/commands/dev/say.ts index 2c8151f..bbada0c 100644 --- a/src/commands/dev/say.ts +++ b/src/commands/dev/say.ts @@ -1,4 +1,5 @@ import { AllowedMentions, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { ApplicationCommandOptionType } from 'discord.js'; export default class SayCommand extends BushCommand { public constructor() { @@ -16,7 +17,7 @@ export default class SayCommand extends BushCommand { match: 'rest', prompt: 'What would you like the bot to say?', retry: '{error} Choose something for the bot to send.', - slashType: 'STRING' + slashType: ApplicationCommandOptionType.String } ], ownerOnly: true, diff --git a/src/commands/dev/sh.ts b/src/commands/dev/sh.ts index 9956897..f74dedf 100644 --- a/src/commands/dev/sh.ts +++ b/src/commands/dev/sh.ts @@ -2,8 +2,9 @@ import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; import assert from 'assert'; import chalk from 'chalk'; import { exec } from 'child_process'; -import { MessageEmbed, Util } from 'discord.js'; +import { ApplicationCommandOptionType, MessageEmbed, Util } from 'discord.js'; import { promisify } from 'util'; + assert(chalk); const sh = promisify(exec); @@ -30,7 +31,7 @@ export default class ShCommand extends BushCommand { match: 'rest', prompt: 'What would you like run', retry: '{error} Invalid command to run.', - slashType: 'STRING' + slashType: ApplicationCommandOptionType.String } ], ownerOnly: true, @@ -46,7 +47,7 @@ export default class ShCommand extends BushCommand { const embed = new MessageEmbed() .setColor(util.colors.gray) - .setFooter({ text: message.author.tag, iconURL: message.author.avatarURL({ dynamic: true }) ?? undefined }) + .setFooter({ text: message.author.tag, iconURL: message.author.avatarURL() ?? undefined }) .setTimestamp() .setTitle('Shell Command') .addField('📥 Input', await util.codeblock(input, 1024, 'sh', true)) diff --git a/src/commands/dev/test.ts b/src/commands/dev/test.ts index 1ec7f71..63c1112 100644 --- a/src/commands/dev/test.ts +++ b/src/commands/dev/test.ts @@ -1,6 +1,13 @@ import { BushCommand, ButtonPaginator, Shared, type BushMessage } from '#lib'; -import { MessageActionRow, MessageButton, MessageEmbed, type ApplicationCommand, type Collection } from 'discord.js'; -import { MessageButtonStyles } from 'discord.js/typings/enums'; +import { + ActionRow, + ActionRowComponent, + ButtonComponent, + ButtonStyle, + MessageEmbed, + type ApplicationCommand, + type Collection +} from 'discord.js'; import badLinksSecretArray from '../../lib/badlinks-secret.js'; import badLinksArray from '../../lib/badlinks.js'; import badWords from '../../lib/badwords.js'; @@ -44,12 +51,12 @@ export default class TestCommand extends BushCommand { } if (['button', 'buttons'].includes(args?.feature?.toLowerCase())) { - const ButtonRow = new MessageActionRow().addComponents( - new MessageButton({ style: MessageButtonStyles.PRIMARY, customId: 'primaryButton', label: 'Primary' }), - new MessageButton({ style: MessageButtonStyles.SECONDARY, customId: 'secondaryButton', label: 'Secondary' }), - new MessageButton({ style: MessageButtonStyles.SUCCESS, customId: 'success', label: 'Success' }), - new MessageButton({ style: MessageButtonStyles.DANGER, customId: 'danger', label: 'Danger' }), - new MessageButton({ style: MessageButtonStyles.LINK, label: 'Link', url: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' }) + const ButtonRow = new ActionRow().addComponents( + new ButtonComponent().setStyle(ButtonStyle.Primary).setCustomId('primaryButton').setLabel('Primary'), + new ButtonComponent().setStyle(ButtonStyle.Secondary).setCustomId('secondaryButton').setLabel('Secondary'), + new ButtonComponent().setStyle(ButtonStyle.Success).setCustomId('successButton').setLabel('Success'), + new ButtonComponent().setStyle(ButtonStyle.Danger).setCustomId('dangerButton').setLabel('Danger'), + new ButtonComponent().setStyle(ButtonStyle.Link).setLabel('Link').setURL('https://www.youtube.com/watch?v=dQw4w9WgXcQ') ); return await message.util.reply({ content: 'buttons', components: [ButtonRow] }); } else if (['embed', 'button embed'].includes(args?.feature?.toLowerCase())) { @@ -67,25 +74,17 @@ export default class TestCommand extends BushCommand { ) .setTitle('Title'); - const buttonRow = new MessageActionRow().addComponents( - new MessageButton({ - style: MessageButtonStyles.LINK, - label: 'Link', - url: 'https://www.google.com/' - }) + const buttonRow = new ActionRow().addComponents( + new ButtonComponent().setStyle(ButtonStyle.Link).setLabel('Link').setURL('https://google.com/') ); return await message.util.reply({ content: 'Test', embeds: [embed], components: [buttonRow] }); } else if (['lots of buttons'].includes(args?.feature?.toLowerCase())) { - const ButtonRows: MessageActionRow[] = []; + const ButtonRows: ActionRow<ActionRowComponent>[] = []; for (let a = 1; a <= 5; a++) { - const row = new MessageActionRow(); + const row = new ActionRow(); for (let b = 1; b <= 5; b++) { const id = (a + 5 * (b - 1)).toString(); - const button = new MessageButton({ - style: MessageButtonStyles.SECONDARY, - customId: id, - label: id - }); + const button = new ButtonComponent().setStyle(ButtonStyle.Primary).setCustomId(id).setLabel(id); row.addComponents(button); } ButtonRows.push(row); @@ -99,39 +98,25 @@ export default class TestCommand extends BushCommand { return await ButtonPaginator.send(message, embeds); } else if (['lots of embeds'].includes(args?.feature?.toLowerCase())) { const description = 'This is a description.'; - const _avatar = message.author.avatarURL({ dynamic: true }) ?? undefined; + const _avatar = message.author.avatarURL() ?? undefined; const author = { name: 'This is a author', iconURL: _avatar }; const footer = { text: 'This is a footer', iconURL: _avatar }; - const fields = []; - for (let i = 0; i < 25; i++) { - fields.push({ name: `Field ${i}`, value: `Field Value ${i}` }); - } + const fields = Array(25) + .fill(0) + .map((_, i) => ({ name: `Field ${i}`, value: 'Field Value' })); const c = util.colors; const o = { description, author, footer, fields, time: Date.now() }; - const embeds = [ - { ...o, title: 'Embed Title 0', color: c.red }, - { ...o, title: 'Embed Title 1', color: c.orange }, - { ...o, title: 'Embed Title 2', color: c.gold }, - { ...o, title: 'Embed Title 3', color: c.yellow }, - { ...o, title: 'Embed Title 4', color: c.green }, - { ...o, title: 'Embed Title 5', color: c.darkGreen }, - { ...o, title: 'Embed Title 6', color: c.aqua }, - { ...o, title: 'Embed Title 7', color: c.blue }, - { ...o, title: 'Embed Title 8', color: c.purple }, - { ...o, title: 'Embed Title 9', color: c.pink } - ]; + const colors = [c.red, c.orange, c.gold, c.yellow, c.green, c.darkGreen, c.aqua, c.blue, c.purple, c.pink]; + + const embeds = colors.map((c, i) => ({ ...o, title: `Embed Title ${i}`, color: c })); - const ButtonRows: MessageActionRow[] = []; + const ButtonRows: ActionRow<ActionRowComponent>[] = []; for (let a = 1; a <= 5; a++) { - const row = new MessageActionRow(); + const row = new ActionRow(); for (let b = 1; b <= 5; b++) { const id = (a + 5 * (b - 1)).toString(); - const button = new MessageButton({ - style: MessageButtonStyles.SECONDARY, - customId: id, - label: id - }); + const button = new ButtonComponent().setStyle(ButtonStyle.Secondary).setCustomId(id).setLabel(id); row.addComponents(button); } ButtonRows.push(row); |