From 661e4c9935aeb8760dafc7ced4bbec6cc356a033 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Tue, 14 Jun 2022 12:47:57 -0400 Subject: remove the war crimes that I previously committed - Remove custom typings and replace with declaration merging - Fix the typings for args - Replace all discord-api-types imports with discord.js imports - Fix discord.js breaking changes --- src/commands/_fake-command/ironmoon.ts | 6 +- src/commands/admin/channelPermissions.ts | 10 +- src/commands/admin/roleAll.ts | 5 +- src/commands/config/_customAutomodPhrases.ts | 8 +- src/commands/config/blacklist.ts | 12 +- src/commands/config/config.ts | 15 +- src/commands/config/disable.ts | 6 +- src/commands/config/features.ts | 8 +- src/commands/config/log.ts | 4 +- src/commands/dev/__template.ts | 4 +- src/commands/dev/debug.ts | 4 +- src/commands/dev/dm.ts | 4 +- src/commands/dev/eval.ts | 30 ++- src/commands/dev/javascript.ts | 9 +- src/commands/dev/reload.ts | 8 +- src/commands/dev/say.ts | 6 +- src/commands/dev/servers.ts | 7 +- src/commands/dev/sh.ts | 8 +- src/commands/dev/superUser.ts | 23 +- src/commands/dev/syncAutomod.ts | 4 +- src/commands/dev/test.ts | 300 +++++++++++++------------ src/commands/fun/coinFlip.ts | 4 +- src/commands/fun/dice.ts | 4 +- src/commands/fun/eightBall.ts | 4 +- src/commands/fun/minesweeper.ts | 24 +- src/commands/info/avatar.ts | 7 +- src/commands/info/botInfo.ts | 4 +- src/commands/info/color.ts | 33 +-- src/commands/info/guildInfo.ts | 28 ++- src/commands/info/help.ts | 14 +- src/commands/info/icon.ts | 4 +- src/commands/info/links.ts | 4 +- src/commands/info/ping.ts | 12 +- src/commands/info/pronouns.ts | 4 +- src/commands/info/snowflake.ts | 16 +- src/commands/info/userInfo.ts | 41 ++-- src/commands/leveling/leaderboard.ts | 4 +- src/commands/leveling/level.ts | 16 +- src/commands/leveling/levelRoles.ts | 4 +- src/commands/leveling/setLevel.ts | 4 +- src/commands/leveling/setXp.ts | 4 +- src/commands/moderation/_activePunishments.ts | 149 ++++++------ src/commands/moderation/ban.ts | 12 +- src/commands/moderation/block.ts | 11 +- src/commands/moderation/evidence.ts | 47 ++-- src/commands/moderation/hideCase.ts | 4 +- src/commands/moderation/kick.ts | 9 +- src/commands/moderation/lockdown.ts | 18 +- src/commands/moderation/massBan.ts | 8 +- src/commands/moderation/massEvidence.ts | 4 +- src/commands/moderation/modlog.ts | 6 +- src/commands/moderation/mute.ts | 10 +- src/commands/moderation/purge.ts | 16 +- src/commands/moderation/removeReactionEmoji.ts | 6 +- src/commands/moderation/role.ts | 17 +- src/commands/moderation/slowmode.ts | 17 +- src/commands/moderation/timeout.ts | 8 +- src/commands/moderation/unban.ts | 10 +- src/commands/moderation/unblock.ts | 11 +- src/commands/moderation/unlockdown.ts | 13 +- src/commands/moderation/unmute.ts | 13 +- src/commands/moderation/untimeout.ts | 10 +- src/commands/moderation/warn.ts | 10 +- src/commands/moulberry-bush/capePermissions.ts | 4 +- src/commands/moulberry-bush/capes.ts | 15 +- src/commands/moulberry-bush/giveawayPing.ts | 4 +- src/commands/moulberry-bush/moulHammer.ts | 6 +- src/commands/moulberry-bush/report.ts | 4 +- src/commands/moulberry-bush/rule.ts | 4 +- src/commands/moulberry-bush/serverStatus.ts | 4 +- src/commands/utilities/_poll.ts | 149 ++++++------ src/commands/utilities/activity.ts | 11 +- src/commands/utilities/calculator.ts | 4 +- src/commands/utilities/decode.ts | 5 +- src/commands/utilities/hash.ts | 4 +- src/commands/utilities/highlight-!.ts | 12 +- src/commands/utilities/highlight-add.ts | 7 +- src/commands/utilities/highlight-block.ts | 9 +- src/commands/utilities/highlight-clear.ts | 4 +- src/commands/utilities/highlight-matches.ts | 8 +- src/commands/utilities/highlight-remove.ts | 4 +- src/commands/utilities/highlight-show.ts | 4 +- src/commands/utilities/highlight-unblock.ts | 9 +- src/commands/utilities/price.ts | 8 +- src/commands/utilities/remind.ts | 6 +- src/commands/utilities/reminders.ts | 7 +- src/commands/utilities/steal.ts | 20 +- src/commands/utilities/suicide.ts | 4 +- src/commands/utilities/uuid.ts | 18 +- src/commands/utilities/viewRaw.ts | 19 +- src/commands/utilities/whoHasRole.ts | 8 +- src/commands/utilities/wolframAlpha.ts | 7 +- 92 files changed, 741 insertions(+), 752 deletions(-) (limited to 'src/commands') diff --git a/src/commands/_fake-command/ironmoon.ts b/src/commands/_fake-command/ironmoon.ts index 1f63c06..cb50c7e 100644 --- a/src/commands/_fake-command/ironmoon.ts +++ b/src/commands/_fake-command/ironmoon.ts @@ -1,4 +1,4 @@ -import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, type CommandMessage, type SlashMessage } from '#lib'; export default class IronmoonCommand extends BushCommand { public constructor() { @@ -13,13 +13,13 @@ export default class IronmoonCommand extends BushCommand { }); } - public override condition(message: BushMessage): boolean { + public override condition(message: CommandMessage): boolean { return false; if (message.content.toLowerCase().includes('ironmoon')) return true; else return false; } - public override async exec(message: BushMessage | BushSlashMessage) { + public override async exec(message: CommandMessage | SlashMessage) { return await message.util.reply('Your message included the word ironmoon.'); } } diff --git a/src/commands/admin/channelPermissions.ts b/src/commands/admin/channelPermissions.ts index d58a7da..f6240a5 100644 --- a/src/commands/admin/channelPermissions.ts +++ b/src/commands/admin/channelPermissions.ts @@ -1,4 +1,4 @@ -import { BushCommand, ButtonPaginator, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, ButtonPaginator, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, EmbedBuilder, PermissionFlagsBits } from 'discord.js'; @@ -57,12 +57,8 @@ export default class ChannelPermissionsCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, - args: { - target: ArgType<'member'> | ArgType<'role'>; - permission: ArgType<'permission'>; - state: 'true' | 'false' | 'neutral'; - } + message: CommandMessage | SlashMessage, + args: { target: ArgType<'member' | 'role'>; permission: ArgType<'permission'>; state: 'true' | 'false' | 'neutral' } ) { assert(message.inGuild()); if (message.util.isSlashMessage(message)) await message.interaction.deferReply(); diff --git a/src/commands/admin/roleAll.ts b/src/commands/admin/roleAll.ts index 7cb7346..80952cc 100644 --- a/src/commands/admin/roleAll.ts +++ b/src/commands/admin/roleAll.ts @@ -1,4 +1,5 @@ -import { AllowedMentions, BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { AllowedMentions, BushCommand, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; + import assert from 'assert'; import { ApplicationCommandOptionType, PermissionFlagsBits, type GuildMember } from 'discord.js'; @@ -39,7 +40,7 @@ export default class RoleAllCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage, args: { role: ArgType<'role'>; bots: ArgType<'boolean'> }) { + public override async exec(message: CommandMessage | SlashMessage, args: { role: ArgType<'role'>; bots: ArgType<'flag'> }) { assert(message.inGuild()); if (!message.member!.permissions.has(PermissionFlagsBits.Administrator) && !message.member!.user.isOwner()) return await message.util.reply(`${util.emojis.error} You must have admin perms to use this command.`); diff --git a/src/commands/config/_customAutomodPhrases.ts b/src/commands/config/_customAutomodPhrases.ts index bd9bab5..13887ae 100644 --- a/src/commands/config/_customAutomodPhrases.ts +++ b/src/commands/config/_customAutomodPhrases.ts @@ -1,5 +1,5 @@ -// import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; -// import { PermissionFlagsBits } from 'discord.js'; +// import { BushCommand, type ArgType, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; +// import { ApplicationCommandOptionType, PermissionFlagsBits } from 'discord.js'; // export default class CustomAutomodPhrasesCommand extends BushCommand { // public constructor() { @@ -36,7 +36,7 @@ // } // public override async exec( -// message: BushMessage | BushSlashMessage, -// args: { required_argument: string; optional_argument: string } +// message: CommandMessage | SlashMessage, +// args: { required_argument: ArgType<'string'>; optional_argument: OptArgType<'string'> } // ) {} // } diff --git a/src/commands/config/blacklist.ts b/src/commands/config/blacklist.ts index ba2d24a..de457c0 100644 --- a/src/commands/config/blacklist.ts +++ b/src/commands/config/blacklist.ts @@ -1,6 +1,6 @@ -import { AllowedMentions, BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { AllowedMentions, BushCommand, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; -import { ApplicationCommandOptionType, PermissionFlagsBits, User } from 'discord.js'; +import { ApplicationCommandOptionType, GuildMember, PermissionFlagsBits, User } from 'discord.js'; export default class BlacklistCommand extends BushCommand { public constructor() { @@ -47,11 +47,11 @@ export default class BlacklistCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, args: { action?: 'blacklist' | 'unblacklist'; - target: ArgType<'channel'> | ArgType<'user'> | string; // there is no way to combine channel and user in slash commands without making subcommands - global: ArgType<'boolean'>; + target: ArgType<'channel' | 'user'> | string; // there is no way to combine channel and user in slash commands without making subcommands + global: ArgType<'flag'>; } ) { let action: 'blacklist' | 'unblacklist' | 'toggle' = @@ -88,7 +88,7 @@ export default class BlacklistCommand extends BushCommand { const success = await (global ? util.setGlobal(key, newValue) - : message.guild!.setSetting(key, newValue, message.member!) + : message.guild!.setSetting(key, newValue, message.member as GuildMember) ).catch(() => false); if (!success) diff --git a/src/commands/config/config.ts b/src/commands/config/config.ts index e203d12..689a3af 100644 --- a/src/commands/config/config.ts +++ b/src/commands/config/config.ts @@ -4,12 +4,13 @@ import { guildSettingsObj, settingsArr, type ArgType, - type BushMessage, - type BushSlashMessage, + type CommandMessage, type GuildSettings, - type GuildSettingType + type GuildSettingType, + type SlashMessage } from '#lib'; import assert from 'assert'; + import { type ArgumentGeneratorReturn, type SlashOption } from 'discord-akairo'; import { ActionRowBuilder, @@ -149,7 +150,7 @@ export default class ConfigCommand extends BushCommand { }); } - public override *args(message: BushMessage): ArgumentGeneratorReturn { + public override *args(message: CommandMessage): ArgumentGeneratorReturn { const optional = message.util.parsed!.alias === 'settings'; const setting: GuildSettings = yield { id: 'setting', @@ -205,13 +206,13 @@ export default class ConfigCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, args: { setting?: GuildSettings; subcommandGroup?: GuildSettings; action?: Action; subcommand?: Action; - value: ArgType<'channel'> | ArgType<'role'> | string; + value: ArgType<'channel' | 'role'> | string; } ) { assert(message.inGuild()); @@ -305,7 +306,7 @@ export default class ConfigCommand extends BushCommand { } public async generateMessageOptions( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, setting?: undefined | keyof typeof guildSettingsObj ): Promise { assert(message.inGuild()); diff --git a/src/commands/config/disable.ts b/src/commands/config/disable.ts index dea7b0f..373b5f6 100644 --- a/src/commands/config/disable.ts +++ b/src/commands/config/disable.ts @@ -1,4 +1,4 @@ -import { AllowedMentions, BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { AllowedMentions, BushCommand, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, AutocompleteInteraction, PermissionFlagsBits } from 'discord.js'; import Fuse from 'fuse.js'; @@ -54,8 +54,8 @@ export default class DisableCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, - args: { action?: 'enable' | 'disable'; command: ArgType<'commandAlias'> | string; global: boolean } + message: CommandMessage | SlashMessage, + args: { action?: 'enable' | 'disable'; command: ArgType<'commandAlias'> | string; global: ArgType<'flag'> } ) { assert(message.inGuild()); diff --git a/src/commands/config/features.ts b/src/commands/config/features.ts index 2eee0fe..95ae544 100644 --- a/src/commands/config/features.ts +++ b/src/commands/config/features.ts @@ -2,9 +2,9 @@ import { BushCommand, guildFeaturesArr, guildFeaturesObj, - type BushMessage, - type BushSlashMessage, - type GuildFeatures + type CommandMessage, + type GuildFeatures, + type SlashMessage } from '#lib'; import assert from 'assert'; import { @@ -32,7 +32,7 @@ export default class FeaturesCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage) { + public override async exec(message: CommandMessage | SlashMessage) { assert(message.inGuild()); const featureEmbed = new EmbedBuilder().setTitle(`${message.guild.name}'s Features`).setColor(util.colors.default); diff --git a/src/commands/config/log.ts b/src/commands/config/log.ts index f99f007..7c76bdf 100644 --- a/src/commands/config/log.ts +++ b/src/commands/config/log.ts @@ -1,4 +1,4 @@ -import { BushCommand, guildLogsArr, type ArgType, type BushMessage, type BushSlashMessage, type GuildLogType } from '#lib'; +import { BushCommand, guildLogsArr, type ArgType, type CommandMessage, type GuildLogType, type SlashMessage } from '#lib'; import assert from 'assert'; import { ArgumentGeneratorReturn } from 'discord-akairo'; import { ApplicationCommandOptionType, ChannelType, PermissionFlagsBits } from 'discord.js'; @@ -70,7 +70,7 @@ export default class LogCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, args: { log_type: GuildLogType; channel: ArgType<'textChannel'> } ) { assert(message.inGuild()); diff --git a/src/commands/dev/__template.ts b/src/commands/dev/__template.ts index ace8802..7bcce32 100644 --- a/src/commands/dev/__template.ts +++ b/src/commands/dev/__template.ts @@ -1,4 +1,4 @@ -import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage, type OptArgType } from '#lib'; +import { BushCommand, type ArgType, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; import { ApplicationCommandOptionType } from 'discord.js'; export default class TemplateCommand extends BushCommand { @@ -39,7 +39,7 @@ export default class TemplateCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, args: { required_argument: ArgType<'string'>; optional_argument: OptArgType<'string'> } ) { return await message.util.reply(`${util.emojis.error} Do not use the template command.`); diff --git a/src/commands/dev/debug.ts b/src/commands/dev/debug.ts index f8c614d..682a93d 100644 --- a/src/commands/dev/debug.ts +++ b/src/commands/dev/debug.ts @@ -1,4 +1,4 @@ -// import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +// import { BushCommand, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; // import { ApplicationCommandOptionType, AutocompleteInteraction, ChatInputCommandInteraction } from 'discord.js'; // import Fuse from 'fuse.js'; @@ -29,7 +29,7 @@ // }); // } -// public override async exec(message: BushMessage | BushSlashMessage, args: { action: ArgType<'string'> }) { +// public override async exec(message: CommandMessage | SlashMessage, 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') { diff --git a/src/commands/dev/dm.ts b/src/commands/dev/dm.ts index 0646f59..468fb20 100644 --- a/src/commands/dev/dm.ts +++ b/src/commands/dev/dm.ts @@ -1,4 +1,4 @@ -import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; import { ApplicationCommandOptionType } from 'discord.js'; export default class DMCommand extends BushCommand { @@ -37,7 +37,7 @@ export default class DMCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, args: { user: ArgType<'user'>; content: ArgType<'string'> } ) { try { diff --git a/src/commands/dev/eval.ts b/src/commands/dev/eval.ts index 8af280d..b8ee9e4 100644 --- a/src/commands/dev/eval.ts +++ b/src/commands/dev/eval.ts @@ -3,8 +3,6 @@ import { ActivePunishment, BushCommand, BushInspectOptions, - BushMessage, - BushSlashMessage, CodeBlockLang, Global, Guild, @@ -12,7 +10,9 @@ import { ModLog, Shared, StickyRole, - type ArgType + type ArgType, + type CommandMessage, + type SlashMessage } from '#lib'; import { Snowflake as Snowflake_ } from '@sapphire/snowflake'; import assert from 'assert'; @@ -57,7 +57,7 @@ const { transpile } = ts, /* eslint-enable @typescript-eslint/no-unused-vars */ // prettier-ignore -util.assertAll(ActivePunishment, BushCommand, BushMessage, BushSlashMessage, Global, Guild, Level, ModLog, Shared, StickyRole, Snowflake_, Canvas, exec, ActionRow, ButtonComponent, ButtonInteraction, Collection, Collector, CommandInteraction, ContextMenuCommandInteraction, DMChannel, Embed, Emoji, Interaction, InteractionCollector, Message, Attachment, MessageCollector, OAuth2Scopes, PermissionFlagsBits, PermissionsBitField, ReactionCollector, SelectMenuComponent, Util, path, ts, fileURLToPath, promisify, assert, got, transpile, emojis, colors, sh, SnowflakeUtil, __dirname); +util.assertAll(ActivePunishment, BushCommand, Global, Guild, Level, ModLog, Shared, StickyRole, Snowflake_, Canvas, exec, ActionRow, ButtonComponent, ButtonInteraction, Collection, Collector, CommandInteraction, ContextMenuCommandInteraction, DMChannel, Embed, Emoji, Interaction, InteractionCollector, Message, Attachment, MessageCollector, OAuth2Scopes, PermissionFlagsBits, PermissionsBitField, ReactionCollector, SelectMenuComponent, Util, path, ts, fileURLToPath, promisify, assert, got, transpile, emojis, colors, sh, SnowflakeUtil, __dirname); export default class EvalCommand extends BushCommand { public constructor() { @@ -180,7 +180,7 @@ export default class EvalCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, { code: argCode, sel_depth: selDepth, @@ -196,15 +196,15 @@ export default class EvalCommand extends BushCommand { }: { code: ArgType<'string'>; sel_depth: ArgType<'integer'>; - sudo: ArgType<'boolean'>; - silent: ArgType<'boolean'>; - delete_msg: ArgType<'boolean'>; - typescript: ArgType<'boolean'>; - hidden: ArgType<'boolean'>; - show_proto: ArgType<'boolean'>; - show_methods: ArgType<'boolean'>; - async: ArgType<'boolean'>; - no_inspect_strings: ArgType<'boolean'>; + sudo: ArgType<'flag'>; + silent: ArgType<'flag'>; + delete_msg: ArgType<'flag'>; + typescript: ArgType<'flag'>; + hidden: ArgType<'flag'>; + show_proto: ArgType<'flag'>; + show_methods: ArgType<'flag'>; + async: ArgType<'flag'>; + no_inspect_strings: ArgType<'flag'>; } ) { if (!message.author.isOwner()) @@ -322,5 +322,3 @@ interface CodeBlockCustomOptions extends CodeBlockOptions { prototype?: boolean; methods?: boolean; } - -/** @typedef {ActivePunishment|Global|Guild|Level|ModLog|StickyRole|ButtonInteraction|Collection|Collector|CommandInteraction|ContextMenuCommandInteraction|DMChannel|Emoji|Interaction|InteractionCollector|Message|ActionRow|Attachment|ButtonComponent|MessageCollector|SelectMenuComponent|ReactionCollector|Util|Canvas|Shared|PermissionsBitField|got} VSCodePleaseDontRemove */ diff --git a/src/commands/dev/javascript.ts b/src/commands/dev/javascript.ts index be8fdce..fd1894b 100644 --- a/src/commands/dev/javascript.ts +++ b/src/commands/dev/javascript.ts @@ -1,4 +1,4 @@ -import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, type ArgType, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, EmbedBuilder } from 'discord.js'; import { VM } from 'vm2'; @@ -41,11 +41,8 @@ export default class JavascriptCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, - args: { - sel_depth: ArgType<'integer'>; - code: string; - } + message: CommandMessage | SlashMessage, + args: { code: ArgType<'string'>; sel_depth: OptArgType<'integer'> } ) { if (!message.author.isSuperUser()) return await message.util.reply(`${util.emojis.error} Only super users can run this command.`); diff --git a/src/commands/dev/reload.ts b/src/commands/dev/reload.ts index 17802b0..96c395f 100644 --- a/src/commands/dev/reload.ts +++ b/src/commands/dev/reload.ts @@ -1,4 +1,4 @@ -import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, type CommandMessage, type SlashMessage } from '#lib'; export default class ReloadCommand extends BushCommand { public constructor() { @@ -13,7 +13,7 @@ export default class ReloadCommand extends BushCommand { // id: 'fast', // description: 'Whether or not to use esbuild for fast compiling.', // match: 'flag', - // flag: '--fast', + // flag: ['--fast'], // prompt: 'Would you like to use esbuild for fast compiling?', // optional: true, // slashType: ApplicationCommandOptionType.Boolean @@ -27,14 +27,14 @@ export default class ReloadCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage /* { fast }: { fast: boolean } */) { + public override async exec(message: CommandMessage | SlashMessage /* args: { fast: ArgType<'flag'> } */) { if (!message.author.isOwner()) return await message.util.reply(`${util.emojis.error} Only my developers can run this command.`); let output: { stdout: string; stderr: string }; try { const s = new Date(); - output = await util.shell(`yarn build:${/* fast ? 'esbuild' : */ 'tsc'}`); + output = await util.shell(`yarn build:${/* args.fast ? 'esbuild' : */ 'tsc'}`); await Promise.all([ client.commandHandler.reloadAll(), client.listenerHandler.reloadAll(), diff --git a/src/commands/dev/say.ts b/src/commands/dev/say.ts index bbada0c..a452126 100644 --- a/src/commands/dev/say.ts +++ b/src/commands/dev/say.ts @@ -1,4 +1,4 @@ -import { AllowedMentions, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { AllowedMentions, BushCommand, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; import { ApplicationCommandOptionType } from 'discord.js'; export default class SayCommand extends BushCommand { @@ -27,7 +27,7 @@ export default class SayCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage, args: { content: string }) { + public override async exec(message: CommandMessage | SlashMessage, args: { content: ArgType<'string'> }) { if (!message.author.isOwner()) return await message.util.reply(`${util.emojis.error} Only my developers can run this command.`); @@ -35,7 +35,7 @@ export default class SayCommand extends BushCommand { await message.util.send({ content: args.content, allowedMentions: AllowedMentions.none() }).catch(() => null); } - public override async execSlash(message: BushSlashMessage, args: { content: string }) { + public override async execSlash(message: SlashMessage, args: { content: string }) { if (!client.config.owners.includes(message.author.id)) { return await message.interaction.reply({ content: `${util.emojis.error} Only my developers can run this command.`, diff --git a/src/commands/dev/servers.ts b/src/commands/dev/servers.ts index 0701158..e99bcda 100644 --- a/src/commands/dev/servers.ts +++ b/src/commands/dev/servers.ts @@ -1,7 +1,6 @@ -import { BushCommand, ButtonPaginator, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, ButtonPaginator, type CommandMessage, type SlashMessage } from '#lib'; import { stripIndent } from '#tags'; -import type { APIEmbed } from 'discord-api-types/v10'; -import type { Guild } from 'discord.js'; +import { type APIEmbed, type Guild } from 'discord.js'; export default class ServersCommand extends BushCommand { public constructor() { @@ -17,7 +16,7 @@ export default class ServersCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage) { + public override async exec(message: CommandMessage | SlashMessage) { const guilds = [...client.guilds.cache.sort((a, b) => (a.memberCount < b.memberCount ? 1 : -1)).values()]; const chunkedGuilds: Guild[][] = util.chunk(guilds, 10); const embeds: APIEmbed[] = chunkedGuilds.map((chunk) => { diff --git a/src/commands/dev/sh.ts b/src/commands/dev/sh.ts index d47ecd2..8c62f5d 100644 --- a/src/commands/dev/sh.ts +++ b/src/commands/dev/sh.ts @@ -1,4 +1,4 @@ -import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { ArgType, BushCommand, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; import chalk from 'chalk'; import { exec } from 'child_process'; @@ -40,10 +40,10 @@ export default class ShCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage, { command }: { command: string }) { + public override async exec(message: CommandMessage | SlashMessage, args: { command: ArgType<'string'> }) { if (!client.config.owners.includes(message.author.id)) return await message.util.reply(`${util.emojis.error} Only my developers can run this command.`); - const input = clean(command); + const input = clean(args.command); const embed = new EmbedBuilder() .setColor(util.colors.gray) @@ -65,7 +65,7 @@ export default class ShCommand extends BushCommand { return abc.replace(new RegExp(pattern, 'g'), ''); } */ try { - const output = await sh(command, { env: { ...process.env, FORCE_COLOR: 'true' } }); + const output = await sh(args.command, { env: { ...process.env, FORCE_COLOR: 'true' } }); const stdout = /* strip( */ clean(output.stdout); /* ) */ const stderr = /* strip( */ clean(output.stderr); /* ) */ diff --git a/src/commands/dev/superUser.ts b/src/commands/dev/superUser.ts index d62ac8e..6a2b745 100644 --- a/src/commands/dev/superUser.ts +++ b/src/commands/dev/superUser.ts @@ -1,6 +1,5 @@ -import { BushCommand, type ArgType, type BushMessage } from '#lib'; -import { ArgumentGeneratorReturn } from 'discord-akairo'; -import { ArgumentTypeCasterReturn } from 'discord-akairo/dist/src/struct/commands/arguments/Argument.js'; +import { BushCommand, type ArgType, type CommandMessage } from '#lib'; +import { type ArgumentGeneratorReturn, type ArgumentTypeCasterReturn } from 'discord-akairo'; export default class SuperUserCommand extends BushCommand { public constructor() { @@ -54,30 +53,30 @@ export default class SuperUserCommand extends BushCommand { return { action, user }; } - public override async exec(message: BushMessage, { action, user }: { action: 'add' | 'remove'; user: ArgType<'user'> }) { + public override async exec(message: CommandMessage, args: { action: 'add' | 'remove'; user: ArgType<'user'> }) { if (!message.author.isOwner()) return await message.util.reply(`${util.emojis.error} Only my developers can run this command.`); const superUsers: string[] = util.getShared('superUsers'); - if (action === 'add' ? superUsers.includes(user.id) : !superUsers.includes(user.id)) + if (args.action === 'add' ? superUsers.includes(args.user.id) : !superUsers.includes(args.user.id)) return message.util.reply( - `${util.emojis.warn} ${util.format.input(user.tag)} is ${action === 'add' ? 'already' : 'not'} a superuser.` + `${util.emojis.warn} ${util.format.input(args.user.tag)} is ${args.action === 'add' ? 'already' : 'not'} a superuser.` ); - const success = await util.insertOrRemoveFromShared(action, 'superUsers', user.id).catch(() => false); + const success = await util.insertOrRemoveFromShared(args.action, 'superUsers', args.user.id).catch(() => false); if (success) { return await message.util.reply( - `${util.emojis.success} ${action == 'remove' ? '' : 'made'} ${util.format.input(user.tag)} ${ - action == 'remove' ? 'is no longer ' : '' + `${util.emojis.success} ${args.action == 'remove' ? '' : 'made'} ${util.format.input(args.user.tag)} ${ + args.action == 'remove' ? 'is no longer ' : '' }a superuser.` ); } else { return await message.util.reply( - `${util.emojis.error} There was an error ${action == 'remove' ? `removing` : 'making'} ${util.format.input(user.tag)} ${ - action == 'remove' ? `from` : 'to' - } the superuser list.` + `${util.emojis.error} There was an error ${args.action == 'remove' ? `removing` : 'making'} ${util.format.input( + args.user.tag + )} ${args.action == 'remove' ? `from` : 'to'} the superuser list.` ); } } diff --git a/src/commands/dev/syncAutomod.ts b/src/commands/dev/syncAutomod.ts index 4d4a6d7..9954e70 100644 --- a/src/commands/dev/syncAutomod.ts +++ b/src/commands/dev/syncAutomod.ts @@ -1,4 +1,4 @@ -import { BushCommand, Shared, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, Shared, type CommandMessage, type SlashMessage } from '#lib'; import got from 'got'; import typescript from 'typescript'; import { NodeVM } from 'vm2'; @@ -18,7 +18,7 @@ export default class SyncAutomodCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage) { + public override async exec(message: CommandMessage | SlashMessage) { if (!message.author.isOwner() && message.author.id !== '497789163555389441') return await message.util.reply(`${util.emojis.error} Only a very select few may use this command.`); diff --git a/src/commands/dev/test.ts b/src/commands/dev/test.ts index 2d7b1f8..d54d544 100644 --- a/src/commands/dev/test.ts +++ b/src/commands/dev/test.ts @@ -1,11 +1,11 @@ -import { BushCommand, ButtonPaginator, Shared, type BushMessage } from '#lib'; -import { Routes } from 'discord-api-types/rest/v9'; +import { BushCommand, ButtonPaginator, OptArgType, Shared, type CommandMessage } from '#lib'; import { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, GatewayDispatchEvents, + Routes, type ApplicationCommand, type Collection } from 'discord.js'; @@ -38,7 +38,7 @@ export default class TestCommand extends BushCommand { }); } - public override async exec(message: BushMessage, args: { feature: string }) { + public override async exec(message: CommandMessage, args: { feature: OptArgType<'string'> }) { const responses = [ 'Yes master.', 'Test it your self bitch, I am hungry.', @@ -51,166 +51,168 @@ export default class TestCommand extends BushCommand { return await message.util.reply(responses[Math.floor(Math.random() * responses.length)]); } - if (['button', 'buttons'].includes(args.feature?.toLowerCase())) { - const buttonRow = new ActionRowBuilder().addComponents([ - new ButtonBuilder({ style: ButtonStyle.Primary, customId: 'primaryButton', label: 'Primary' }), - new ButtonBuilder({ style: ButtonStyle.Secondary, customId: 'secondaryButton', label: 'Secondary' }), - new ButtonBuilder({ style: ButtonStyle.Success, customId: 'successButton', label: 'Success' }), - new ButtonBuilder({ style: ButtonStyle.Danger, customId: 'dangerButton', label: 'Danger' }), - new ButtonBuilder({ style: ButtonStyle.Link, label: 'Link', url: '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())) { - const embed = new EmbedBuilder() - .addFields([{ name: 'Field Name', value: 'Field Content' }]) - .setAuthor({ name: 'Author', iconURL: 'https://www.w3schools.com/w3css/img_snowtops.jpg', url: 'https://google.com/' }) - .setColor(message.member?.displayColor ?? util.colors.default) - .setDescription('Description') - .setFooter({ text: 'Footer', iconURL: message.author.avatarURL() ?? undefined }) - .setURL('https://duckduckgo.com/') - .setTimestamp() - .setImage('https://media.sproutsocial.com/uploads/2017/02/10x-featured-social-media-image-size.png') - .setThumbnail( - 'https://images.unsplash.com/photo-1501183007986-d0d080b147f9?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2134&q=80' - ) - .setTitle('Title'); + if (args.feature) { + if (['button', 'buttons'].includes(args.feature?.toLowerCase())) { + const buttonRow = new ActionRowBuilder().addComponents([ + new ButtonBuilder({ style: ButtonStyle.Primary, customId: 'primaryButton', label: 'Primary' }), + new ButtonBuilder({ style: ButtonStyle.Secondary, customId: 'secondaryButton', label: 'Secondary' }), + new ButtonBuilder({ style: ButtonStyle.Success, customId: 'successButton', label: 'Success' }), + new ButtonBuilder({ style: ButtonStyle.Danger, customId: 'dangerButton', label: 'Danger' }), + new ButtonBuilder({ style: ButtonStyle.Link, label: 'Link', url: '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())) { + const embed = new EmbedBuilder() + .addFields([{ name: 'Field Name', value: 'Field Content' }]) + .setAuthor({ name: 'Author', iconURL: 'https://www.w3schools.com/w3css/img_snowtops.jpg', url: 'https://google.com/' }) + .setColor(message.member?.displayColor ?? util.colors.default) + .setDescription('Description') + .setFooter({ text: 'Footer', iconURL: message.author.avatarURL() ?? undefined }) + .setURL('https://duckduckgo.com/') + .setTimestamp() + .setImage('https://media.sproutsocial.com/uploads/2017/02/10x-featured-social-media-image-size.png') + .setThumbnail( + 'https://images.unsplash.com/photo-1501183007986-d0d080b147f9?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2134&q=80' + ) + .setTitle('Title'); - const buttonRow = new ActionRowBuilder().addComponents([ - new ButtonBuilder({ style: ButtonStyle.Link, label: 'Link', url: '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: ActionRowBuilder[] = []; - for (let a = 1; a <= 5; a++) { - const row = new ActionRowBuilder(); - for (let b = 1; b <= 5; b++) { - const id = (a + 5 * (b - 1)).toString(); - const button = new ButtonBuilder({ style: ButtonStyle.Primary, customId: id, label: id }); - row.addComponents([button]); + const buttonRow = new ActionRowBuilder().addComponents([ + new ButtonBuilder({ style: ButtonStyle.Link, label: 'Link', url: '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: ActionRowBuilder[] = []; + for (let a = 1; a <= 5; a++) { + const row = new ActionRowBuilder(); + for (let b = 1; b <= 5; b++) { + const id = (a + 5 * (b - 1)).toString(); + const button = new ButtonBuilder({ style: ButtonStyle.Primary, customId: id, label: id }); + row.addComponents([button]); + } + buttonRows.push(row); } - buttonRows.push(row); - } - return await message.util.reply({ content: 'buttons', components: buttonRows }); - } else if (['paginate'].includes(args.feature?.toLowerCase())) { - const embeds = []; - for (let i = 1; i <= 5; i++) { - embeds.push(new EmbedBuilder().setDescription(i.toString())); - } - 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() ?? undefined; - const author = { name: 'This is a author', iconURL: _avatar }; - const footer = { text: 'This is a footer', iconURL: _avatar }; - 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() }; + return await message.util.reply({ content: 'buttons', components: buttonRows }); + } else if (['paginate'].includes(args.feature?.toLowerCase())) { + const embeds = []; + for (let i = 1; i <= 5; i++) { + embeds.push(new EmbedBuilder().setDescription(i.toString())); + } + 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() ?? undefined; + const author = { name: 'This is a author', iconURL: _avatar }; + const footer = { text: 'This is a footer', iconURL: _avatar }; + 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 colors = [c.red, c.orange, c.gold, c.yellow, c.green, c.darkGreen, c.aqua, c.blue, c.purple, 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 embeds = colors.map((c, i) => ({ ...o, title: `Embed Title ${i}`, color: c })); - const ButtonRows: ActionRowBuilder[] = []; - for (let a = 1; a <= 5; a++) { - const row = new ActionRowBuilder(); - for (let b = 1; b <= 5; b++) { - const id = (a + 5 * (b - 1)).toString(); - const button = new ButtonBuilder({ style: ButtonStyle.Secondary, customId: id, label: id }); - row.addComponents([button]); + const ButtonRows: ActionRowBuilder[] = []; + for (let a = 1; a <= 5; a++) { + const row = new ActionRowBuilder(); + for (let b = 1; b <= 5; b++) { + const id = (a + 5 * (b - 1)).toString(); + const button = new ButtonBuilder({ style: ButtonStyle.Secondary, customId: id, label: id }); + row.addComponents([button]); + } + ButtonRows.push(row); } - ButtonRows.push(row); - } - return await message.util.reply({ content: 'this is content', components: ButtonRows, embeds }); - } else if (['delete slash commands'].includes(args.feature?.toLowerCase())) { - if (!message.guild) return await message.util.reply(`${util.emojis.error} This test can only be run in a guild.`); - await client.guilds.fetch(); - const promises: Promise>[] = []; - client.guilds.cache.each((guild) => { - promises.push(guild.commands.set([])); - }); - await Promise.all(promises); + return await message.util.reply({ content: 'this is content', components: ButtonRows, embeds }); + } else if (['delete slash commands'].includes(args.feature?.toLowerCase())) { + if (!message.guild) return await message.util.reply(`${util.emojis.error} This test can only be run in a guild.`); + await client.guilds.fetch(); + const promises: Promise>[] = []; + client.guilds.cache.each((guild) => { + promises.push(guild.commands.set([])); + }); + await Promise.all(promises); - await client.application!.commands.fetch(); - await client.application!.commands.set([]); + await client.application!.commands.fetch(); + await client.application!.commands.set([]); - return await message.util.reply(`${util.emojis.success} Removed guild commands and global commands.`); - } else if (['drop down', 'drop downs', 'select menu', 'select menus'].includes(args.feature?.toLowerCase())) { - return message.util.reply(`${util.emojis.error} no`); - } else if (['sync automod'].includes(args.feature?.toLowerCase())) { - const row = (await Shared.findByPk(0))!; - row.badLinks = badLinksArray; - row.badLinksSecret = badLinksSecretArray; - row.badWords = badWords; - await row.save(); - return await message.util.reply(`${util.emojis.success} Synced automod.`); - } else if (['modal'].includes(args.feature?.toLowerCase())) { - const m = await message.util.reply({ - content: 'Click for modal', - components: [ - new ActionRowBuilder().addComponents([ - new ButtonBuilder({ style: ButtonStyle.Primary, label: 'Modal', customId: 'test;modal' }) - ]) - ] - }); + return await message.util.reply(`${util.emojis.success} Removed guild commands and global commands.`); + } else if (['drop down', 'drop downs', 'select menu', 'select menus'].includes(args.feature?.toLowerCase())) { + return message.util.reply(`${util.emojis.error} no`); + } else if (['sync automod'].includes(args.feature?.toLowerCase())) { + const row = (await Shared.findByPk(0))!; + row.badLinks = badLinksArray; + row.badLinksSecret = badLinksSecretArray; + row.badWords = badWords; + await row.save(); + return await message.util.reply(`${util.emojis.success} Synced automod.`); + } else if (['modal'].includes(args.feature?.toLowerCase())) { + const m = await message.util.reply({ + content: 'Click for modal', + components: [ + new ActionRowBuilder().addComponents([ + new ButtonBuilder({ style: ButtonStyle.Primary, label: 'Modal', customId: 'test;modal' }) + ]) + ] + }); - // eslint-disable-next-line @typescript-eslint/no-misused-promises - client.ws.on(GatewayDispatchEvents.InteractionCreate, async (i: any) => { - if (i?.data?.custom_id !== 'test;modal' || i?.data?.component_type !== 2) return; - if (i?.message?.id !== m.id) return; + // eslint-disable-next-line @typescript-eslint/no-misused-promises + client.ws.on(GatewayDispatchEvents.InteractionCreate, async (i: any) => { + if (i?.data?.custom_id !== 'test;modal' || i?.data?.component_type !== 2) return; + if (i?.message?.id !== m.id) return; - const text = { type: 4, style: 1, min_length: 1, max_length: 4000, required: true }; + const text = { type: 4, style: 1, min_length: 1, max_length: 4000, required: true }; - await this.client.rest.post(Routes.interactionCallback(i.id, i.token), { - body: { - type: 9, - data: { - custom_id: 'test;login', - title: 'Login (real)', - components: [ - { - type: 1, - components: [ - { - ...text, - custom_id: 'test;login;email', - label: 'Email', - placeholder: 'Email' - } - ] - }, - { - type: 1, - components: [ - { - ...text, - custom_id: 'test;login;password', - label: 'Password', - placeholder: 'Password' - } - ] - }, - { - type: 1, - components: [ - { - ...text, - custom_id: 'test;login;2fa', - label: 'Enter Discord Auth Code', - min_length: 6, - max_length: 6, - placeholder: '6-digit authentication code' - } - ] - } - ] + await this.client.rest.post(Routes.interactionCallback(i.id, i.token), { + body: { + type: 9, + data: { + custom_id: 'test;login', + title: 'Login (real)', + components: [ + { + type: 1, + components: [ + { + ...text, + custom_id: 'test;login;email', + label: 'Email', + placeholder: 'Email' + } + ] + }, + { + type: 1, + components: [ + { + ...text, + custom_id: 'test;login;password', + label: 'Password', + placeholder: 'Password' + } + ] + }, + { + type: 1, + components: [ + { + ...text, + custom_id: 'test;login;2fa', + label: 'Enter Discord Auth Code', + min_length: 6, + max_length: 6, + placeholder: '6-digit authentication code' + } + ] + } + ] + } } - } + }); }); - }); - return; + return; + } } return await message.util.reply(responses[Math.floor(Math.random() * responses.length)]); } diff --git a/src/commands/fun/coinFlip.ts b/src/commands/fun/coinFlip.ts index b0805cd..fea5cb5 100644 --- a/src/commands/fun/coinFlip.ts +++ b/src/commands/fun/coinFlip.ts @@ -1,4 +1,4 @@ -import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, type CommandMessage, type SlashMessage } from '#lib'; export default class CoinFlipCommand extends BushCommand { public constructor() { @@ -14,7 +14,7 @@ export default class CoinFlipCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage) { + public override async exec(message: CommandMessage | SlashMessage) { const random = Math.random(); let result: string; const fall = message.author.id === '322862723090219008' ? 0.1 : 0.001; //dw about it diff --git a/src/commands/fun/dice.ts b/src/commands/fun/dice.ts index 53fc9e2..b2bc7e4 100644 --- a/src/commands/fun/dice.ts +++ b/src/commands/fun/dice.ts @@ -1,4 +1,4 @@ -import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, type CommandMessage, type SlashMessage } from '#lib'; export default class DiceCommand extends BushCommand { public constructor() { @@ -14,7 +14,7 @@ export default class DiceCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage) { + public override async exec(message: CommandMessage | SlashMessage) { const responses = ['1', '2', '3', '4', '5', '6']; const answer = responses[Math.floor(Math.random() * responses.length)]; return await message.util.reply(`You rolled a **${answer}**.`); diff --git a/src/commands/fun/eightBall.ts b/src/commands/fun/eightBall.ts index ff06fe5..66fcc45 100644 --- a/src/commands/fun/eightBall.ts +++ b/src/commands/fun/eightBall.ts @@ -1,4 +1,4 @@ -import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, type CommandMessage, type SlashMessage } from '#lib'; import { ApplicationCommandOptionType } from 'discord.js'; export default class EightBallCommand extends BushCommand { @@ -26,7 +26,7 @@ export default class EightBallCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage) { + public override async exec(message: CommandMessage | SlashMessage) { const responses = [ 'It is certain', 'Without a doubt', diff --git a/src/commands/fun/minesweeper.ts b/src/commands/fun/minesweeper.ts index 72551e9..d25cb5d 100644 --- a/src/commands/fun/minesweeper.ts +++ b/src/commands/fun/minesweeper.ts @@ -1,4 +1,4 @@ -import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, OptArgType, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; import { Minesweeper } from '@notenoughupdates/discord.js-minesweeper'; import assert from 'assert'; import { ApplicationCommandOptionType } from 'discord.js'; @@ -53,10 +53,10 @@ export default class MinesweeperCommand extends BushCommand { optional: true }, { - id: 'do_not_reveal_first_cell', + id: 'no_reveal', description: 'Whether to not reveal the first cell automatically.', match: 'flag', - flag: ['--doNotRevealFirstCell', 'do_not_reveal_first_cell'], + flag: ['--noReveal', '--no_reveal', '--doNotRevealFirstCell', 'do_not_reveal_first_cell'], prompt: 'Would you like to not automatically reveal the first cell?', slashType: ApplicationCommandOptionType.Boolean, optional: true @@ -69,20 +69,24 @@ export default class MinesweeperCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, args: { - rows: ArgType<'integer'>; - columns: ArgType<'integer'>; - mines: ArgType<'integer'>; - spaces: boolean; - do_not_reveal_first_cell: boolean; + rows: OptArgType<'integer'>; + columns: OptArgType<'integer'>; + mines: OptArgType<'integer'>; + spaces: ArgType<'flag'>; + no_reveal: ArgType<'flag'>; } ) { + args.rows ??= 9; + args.columns ??= 9; + args.mines ??= 10; + const minesweeper = new Minesweeper({ rows: args.rows, columns: args.columns, mines: args.mines, - revealFirstCell: args.do_not_reveal_first_cell ? false : true, + revealFirstCell: args.no_reveal ? false : true, spaces: args.spaces ?? false, zeroFirstCell: false }); diff --git a/src/commands/info/avatar.ts b/src/commands/info/avatar.ts index 870908d..544c30a 100644 --- a/src/commands/info/avatar.ts +++ b/src/commands/info/avatar.ts @@ -1,4 +1,4 @@ -import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; import { ApplicationCommandOptionType, EmbedBuilder, GuildMember, PermissionFlagsBits } from 'discord.js'; export default class AvatarCommand extends BushCommand { @@ -27,11 +27,12 @@ export default class AvatarCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage, args: { user: ArgType<'member'> | ArgType<'globalUser'> }) { + public override async exec(message: CommandMessage | SlashMessage, args: { user: OptArgType<'member' | 'globalUser'> }) { const params: { size: 2048; extension: 'png'; dynamic: true } = { size: 2048, extension: 'png', dynamic: true }; const defaultAvatar = `https://cdn.discordapp.com/embed/avatars/${Math.ceil(Math.random() * 6) - 1}.png`; - const member = (args.user ?? message.member) instanceof GuildMember ? args.user ?? message.member : undefined; + const member = + (args.user ?? message.member) instanceof GuildMember ? args.user ?? (message.member as GuildMember | null) : null; const user = args.user instanceof GuildMember ? args.user.user : args.user ?? message.author; const guildAvatar = member?.avatarURL(params); diff --git a/src/commands/info/botInfo.ts b/src/commands/info/botInfo.ts index e67ae5a..4a8a36a 100644 --- a/src/commands/info/botInfo.ts +++ b/src/commands/info/botInfo.ts @@ -1,4 +1,4 @@ -import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; import { EmbedBuilder, PermissionFlagsBits, version as discordJSVersion } from 'discord.js'; import * as os from 'os'; @@ -20,7 +20,7 @@ export default class BotInfoCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage) { + public override async exec(message: CommandMessage | SlashMessage) { enum Platform { aix = 'AIX', android = 'Android', diff --git a/src/commands/info/color.ts b/src/commands/info/color.ts index a74c3f3..f60e28a 100644 --- a/src/commands/info/color.ts +++ b/src/commands/info/color.ts @@ -1,25 +1,9 @@ -import { - AllowedMentions, - BushCommand, - type ArgType, - type BushArgumentTypeCaster, - type BushGuildMember, - type BushMessage, - type BushRole, - type BushSlashMessage -} from '#lib'; +import { AllowedMentions, BushCommand, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; -import { ApplicationCommandOptionType, EmbedBuilder, PermissionFlagsBits, Role } from 'discord.js'; +import { ApplicationCommandOptionType, EmbedBuilder, GuildMember, PermissionFlagsBits, Role } from 'discord.js'; import tinycolor from 'tinycolor2'; - assert(tinycolor); -const isValidTinyColor: BushArgumentTypeCaster = (_message, phase) => { - // if the phase is a number it converts it to hex incase it could be representing a color in decimal - const newPhase = isNaN(phase as any) ? phase : `#${Number(phase).toString(16)}`; - return tinycolor(newPhase).isValid() ? newPhase : null; -}; - export default class ColorCommand extends BushCommand { public constructor() { super('color', { @@ -32,7 +16,7 @@ export default class ColorCommand extends BushCommand { { id: 'color', description: 'The color string, role, or member to find the color of.', - type: util.arg.union(isValidTinyColor as any, 'role', 'member'), + type: util.arg.union('tinyColor', 'role', 'member'), readableType: 'color|role|member', match: 'restContent', prompt: 'What color code, role, or user would you like to find the color of?', @@ -50,15 +34,12 @@ export default class ColorCommand extends BushCommand { return color.substring(4, color.length - 5); } - public override async exec( - message: BushMessage | BushSlashMessage, - args: { color: string | ArgType<'role'> | ArgType<'member'> } - ) { + public override async exec(message: CommandMessage | SlashMessage, args: { color: ArgType<'tinyColor' | 'role' | 'member'> }) { const _color = message.util.isSlashMessage(message) - ? ((await util.arg.cast(util.arg.union(isValidTinyColor, 'role', 'member'), message, args.color as string)) as + ? ((await util.arg.cast(util.arg.union('tinyColor', 'role', 'member'), message, args.color as string)) as | string - | BushRole - | BushGuildMember) + | Role + | GuildMember) : args.color; const color = diff --git a/src/commands/info/guildInfo.ts b/src/commands/info/guildInfo.ts index 4872497..572cf06 100644 --- a/src/commands/info/guildInfo.ts +++ b/src/commands/info/guildInfo.ts @@ -1,10 +1,12 @@ -import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage, type OptArgType } from '#lib'; +import { BushCommand, type ArgType, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; import assert from 'assert'; -import { GuildDefaultMessageNotifications, GuildExplicitContentFilter } from 'discord-api-types/v10'; import { ApplicationCommandOptionType, + ChannelType, EmbedBuilder, Guild, + GuildDefaultMessageNotifications, + GuildExplicitContentFilter, GuildMFALevel, GuildPremiumTier, GuildVerificationLevel, @@ -41,17 +43,14 @@ export default class GuildInfoCommand extends BushCommand { }); } - public override async exec( - message: BushMessage | BushSlashMessage, - args: { guild: OptArgType<'guild'> | OptArgType<'snowflake'> } - ) { + public override async exec(message: CommandMessage | SlashMessage, args: { guild: OptArgType<'guild' | 'snowflake'> }) { if (!args.guild && !message.inGuild()) { return await message.util.reply( `${util.emojis.error} You must either provide an server to provide info about or run this command in a server.` ); } - let guild: ArgType<'guild'> | ArgType<'snowflake'> | GuildPreview = args.guild ?? message.guild!; + let guild: ArgType<'guild' | 'snowflake'> | GuildPreview = args.guild ?? message.guild!; if (typeof guild === 'string') { const preview = await client.fetchGuildPreview(`${args.guild}` as Snowflake).catch(() => undefined); if (preview) guild = preview; @@ -163,10 +162,19 @@ export default class GuildInfoCommand extends BushCommand { const guildStats: string[] = []; - const channelTypes = (['Text', 'Voice', 'News', 'Stage', 'Category', 'Thread'] as const).map( + const channelTypes = ( + [ + ['Text', [ChannelType.GuildText]], + ['Voice', [ChannelType.GuildVoice]], + ['News', [ChannelType.GuildNews]], + ['Stage', [ChannelType.GuildStageVoice]], + ['Category', [ChannelType.GuildCategory]], + ['Thread', [ChannelType.GuildNewsThread, ChannelType.GuildPrivateThread, ChannelType.GuildPublicThread]] + ] as const + ).map( (type) => - `${client.consts.mappings.otherEmojis[`Channel${type}`]} ${guild.channels.cache - .filter((channel) => channel[`is${type}`]()) + `${client.consts.mappings.otherEmojis[`Channel${type[0]}`]} ${guild.channels.cache + .filter((channel) => type[1].some((type) => channel.type === type)) .size.toLocaleString()}` ); diff --git a/src/commands/info/help.ts b/src/commands/info/help.ts index ea1e965..af44980 100644 --- a/src/commands/info/help.ts +++ b/src/commands/info/help.ts @@ -1,10 +1,10 @@ -import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; -import { ButtonBuilder } from '@discordjs/builders'; +import { BushCommand, type ArgType, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; import assert from 'assert'; import { ActionRowBuilder, ApplicationCommandOptionType, AutocompleteInteraction, + ButtonBuilder, ButtonStyle, EmbedBuilder, PermissionFlagsBits @@ -53,7 +53,7 @@ export default class HelpCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage, args: HelpArgs) { + public override async exec(message: CommandMessage | SlashMessage, args: HelpArgs) { const row = this.addLinks(message); const command = args.command ? typeof args.command === 'string' @@ -70,7 +70,7 @@ export default class HelpCommand extends BushCommand { } } - private helpAll(message: BushMessage | BushSlashMessage, args: HelpArgs, row: ActionRowBuilder) { + private helpAll(message: CommandMessage | SlashMessage, args: HelpArgs, row: ActionRowBuilder) { const prefix = util.prefix(message); const embed = new EmbedBuilder() .setColor(util.colors.default) @@ -99,7 +99,7 @@ export default class HelpCommand extends BushCommand { return message.util.reply({ embeds: [embed], components: row.components.length ? [row] : undefined }); } - private helpIndividual(message: BushMessage | BushSlashMessage, row: ActionRowBuilder, command: BushCommand) { + private helpIndividual(message: CommandMessage | SlashMessage, row: ActionRowBuilder, command: BushCommand) { const embed = new EmbedBuilder().setColor(util.colors.default).setTitle(`${command.id} Command`); let description = `${command.description ?? '*This command does not have a description.*'}`; @@ -207,7 +207,7 @@ export default class HelpCommand extends BushCommand { } } - private addLinks(message: BushMessage | BushSlashMessage) { + private addLinks(message: CommandMessage | SlashMessage) { const row = new ActionRowBuilder(); if (!client.config.isDevelopment && !client.guilds.cache.some((guild) => guild.ownerId === message.author.id)) { @@ -246,4 +246,4 @@ export default class HelpCommand extends BushCommand { } } -type HelpArgs = { command: ArgType<'commandAlias'> | string; showHidden?: boolean }; +type HelpArgs = { command: OptArgType<'commandAlias'> | string; showHidden: ArgType<'flag'> }; diff --git a/src/commands/info/icon.ts b/src/commands/info/icon.ts index db390a5..9c9556b 100644 --- a/src/commands/info/icon.ts +++ b/src/commands/info/icon.ts @@ -1,4 +1,4 @@ -import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; import { EmbedBuilder, PermissionFlagsBits } from 'discord.js'; @@ -17,7 +17,7 @@ export default class IconCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage) { + public override async exec(message: CommandMessage | SlashMessage) { assert(message.inGuild()); const embed = new EmbedBuilder() diff --git a/src/commands/info/links.ts b/src/commands/info/links.ts index 91b62ca..0d5bd15 100644 --- a/src/commands/info/links.ts +++ b/src/commands/info/links.ts @@ -1,4 +1,4 @@ -import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from 'discord.js'; import packageDotJSON from '../../../package.json' assert { type: 'json' }; @@ -19,7 +19,7 @@ export default class LinksCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage) { + public override async exec(message: CommandMessage | SlashMessage) { const buttonRow = new ActionRowBuilder(); if (!client.config.isDevelopment || message.author.isOwner()) { buttonRow.addComponents([new ButtonBuilder({ style: ButtonStyle.Link, label: 'Invite Me', url: util.invite })]); diff --git a/src/commands/info/ping.ts b/src/commands/info/ping.ts index af0fa98..ad7fdcc 100644 --- a/src/commands/info/ping.ts +++ b/src/commands/info/ping.ts @@ -1,5 +1,5 @@ -import { BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; -import { EmbedBuilder, PermissionFlagsBits } from 'discord.js'; +import { BushCommand, type CommandMessage, type SlashMessage } from '#lib'; +import { EmbedBuilder, PermissionFlagsBits, type Message } from 'discord.js'; export default class PingCommand extends BushCommand { public constructor() { @@ -15,21 +15,21 @@ export default class PingCommand extends BushCommand { }); } - public override async exec(message: BushMessage) { + public override async exec(message: CommandMessage) { const timestamp1 = message.editedTimestamp ?