diff options
Diffstat (limited to 'src/commands/utilities')
22 files changed, 164 insertions, 163 deletions
diff --git a/src/commands/utilities/_poll.ts b/src/commands/utilities/_poll.ts index 81bb5fc..a843561 100644 --- a/src/commands/utilities/_poll.ts +++ b/src/commands/utilities/_poll.ts @@ -1,81 +1,80 @@ -/* import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; -import { ApplicationCommandOptionType, ComponentType } from 'discord.js'; +// import { BushCommand, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; +// import { ApplicationCommandOptionType, ComponentType } from 'discord.js'; -export default class PollCommand extends BushCommand { - public constructor() { - super('poll', { - aliases: ['poll', 'quick-poll'], - category: 'utilities', - description: 'Allows you to create a poll that other users can vote on. Separate options with "," or "|".', - usage: ['poll options'], - examples: ['poll 1 2'], - args: [ - { - id: 'question', - description: 'The question to be answered by a poll.', - type: 'string', - prompt: 'What question would you like to ask?', - retry: '{error} Choose a question.', - slashType: ApplicationCommandOptionType.String, - only: 'slash' - }, - { - id: 'options', - description: 'The options to include in the poll. Separate options with "," or "|".', - type: 'string', - prompt: 'What options you want to include in the poll? Separate options with "," or "|".', - retry: '{error} Choose options for the poll. Separate options with "," or "|".', - slashType: ApplicationCommandOptionType.String - } - ], - slash: true, - clientPermissions: (m) => util.clientSendAndPermCheck(m), - userPermissions: [] - }); - } +// export default class PollCommand extends BushCommand { +// public constructor() { +// super('poll', { +// aliases: ['poll', 'quick-poll'], +// category: 'utilities', +// description: 'Allows you to create a poll that other users can vote on. Separate options with "," or "|".', +// usage: ['poll options'], +// examples: ['poll 1 2'], +// args: [ +// { +// id: 'question', +// description: 'The question to be answered by a poll.', +// type: 'string', +// prompt: 'What question would you like to ask?', +// retry: '{error} Choose a question.', +// slashType: ApplicationCommandOptionType.String, +// only: 'slash' +// }, +// { +// id: 'options', +// description: 'The options to include in the poll. Separate options with "," or "|".', +// type: 'string', +// prompt: 'What options you want to include in the poll? Separate options with "," or "|".', +// retry: '{error} Choose options for the poll. Separate options with "," or "|".', +// slashType: ApplicationCommandOptionType.String +// } +// ], +// slash: true, +// clientPermissions: (m) => util.clientSendAndPermCheck(m), +// userPermissions: [] +// }); +// } - public override async exec(message: BushMessage | BushSlashMessage, args: { question?: string; options: ArgType<'string'> }) { - const { question, options } = this.parseArgs(message, args); - if (!question || !options.length) return; +// public override async exec(message: CommandMessage | SlashMessage, args: { question?: string; options: ArgType<'string'> }) { +// const { question, options } = this.parseArgs(message, args); +// if (!question || !options.length) return; - if (question.length > 256) return await message.util.reply(`${util.emojis.error} Question must be 256 characters or less.`); - if (options.length > 10) return await message.util.reply(`${util.emojis.error} You can only have upto 10 options.`); +// if (question.length > 256) return await message.util.reply(`${util.emojis.error} Question must be 256 characters or less.`); +// if (options.length > 10) return await message.util.reply(`${util.emojis.error} You can only have upto 10 options.`); - return message.util.send({ - embeds: [ - { - author: { name: `asked by: ${message.author.tag}`, icon_url: message.author.displayAvatarURL() || undefined }, - title: question - } - ], - components: [ - { - type: ComponentType.ActionRow, - components: [] - } - ] - }); - } +// return message.util.send({ +// embeds: [ +// { +// author: { name: `asked by: ${message.author.tag}`, icon_url: message.author.displayAvatarURL() || undefined }, +// title: question +// } +// ], +// components: [ +// { +// type: ComponentType.ActionRow, +// components: [] +// } +// ] +// }); +// } - private parseArgs( - message: BushMessage | BushSlashMessage, - args: { question?: string; options: ArgType<'string'> } - ): { question: string; options: string[] } { - const split = args.options.split(/[,|]/).filter((s) => s.trim().length > 0); - if (message.util.isSlash) { - if (split.length < 2) { - void message.util.reply(`${util.emojis.error} You must provide at least two options.`); - return { question: '', options: [] }; - } - return { question: args.question!, options: split }; - } else { - if (split.length < 3) { - void message.util.reply(`${util.emojis.error} You must provide a question and at least two options.`); - return { question: '', options: [] }; - } +// private parseArgs( +// message: CommandMessage | SlashMessage, +// args: { question?: string; options: ArgType<'string'> } +// ): { question: string; options: string[] } { +// const split = args.options.split(/[,|]/).filter((s) => s.trim().length > 0); +// if (message.util.isSlash) { +// if (split.length < 2) { +// void message.util.reply(`${util.emojis.error} You must provide at least two options.`); +// return { question: '', options: [] }; +// } +// return { question: args.question!, options: split }; +// } else { +// if (split.length < 3) { +// void message.util.reply(`${util.emojis.error} You must provide a question and at least two options.`); +// return { question: '', options: [] }; +// } - return { question: split[0], options: split.slice(1) }; - } - } -} - */ +// return { question: split[0], options: split.slice(1) }; +// } +// } +// } diff --git a/src/commands/utilities/activity.ts b/src/commands/utilities/activity.ts index 230cc81..14cc5a0 100644 --- a/src/commands/utilities/activity.ts +++ b/src/commands/utilities/activity.ts @@ -1,4 +1,4 @@ -import { BushCommand, type ArgType, type BushArgumentTypeCaster, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, type ArgType, type BushArgumentTypeCaster, type CommandMessage, type SlashMessage } from '#lib'; import { type ArgumentGeneratorReturn, type ArgumentTypeCaster } from 'discord-akairo'; import { ApplicationCommandOptionType, ChannelType, type DiscordAPIError, type Snowflake } from 'discord.js'; @@ -66,7 +66,7 @@ function map(phase: string): Activity | null { return null; } -const activityTypeCaster: BushArgumentTypeCaster<Snowflake | null> = (message: BushMessage, phrase: string) => { +const activityTypeCaster: BushArgumentTypeCaster<Snowflake | null> = (message: CommandMessage, phrase: string) => { const parsedPhrase = phrase ?? message.util.parsed?.alias !== 'activity' ? message.util.parsed?.alias : undefined; if (!parsedPhrase) return null; const mappedPhrase = map(parsedPhrase)?.id; @@ -120,7 +120,7 @@ export default class ActivityCommand extends BushCommand { }); } - public override *args(message: BushMessage): ArgumentGeneratorReturn { + public override *args(message: CommandMessage): ArgumentGeneratorReturn { const channel: ArgType<'voiceChannel'> = yield { id: 'channel', description: 'The channel to create the activity in.', @@ -151,11 +151,12 @@ export default class ActivityCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, args: { channel: ArgType<'voiceChannel'>; activity: string } ) { const channel = typeof args.channel === 'string' ? message.guild?.channels.cache.get(args.channel) : args.channel; - if (!channel || !channel.isVoice()) return await message.util.reply(`${util.emojis.error} Choose a valid voice channel`); + if (channel?.type !== ChannelType.GuildVoice) + return await message.util.reply(`${util.emojis.error} Choose a valid voice channel`); const target_application_id = message.util.isSlashMessage(message) ? args.activity diff --git a/src/commands/utilities/calculator.ts b/src/commands/utilities/calculator.ts index e17ef76..a318a79 100644 --- a/src/commands/utilities/calculator.ts +++ b/src/commands/utilities/calculator.ts @@ -1,4 +1,4 @@ -import { AllowedMentions, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { AllowedMentions, BushCommand, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, EmbedBuilder } from 'discord.js'; import { evaluate } from 'mathjs'; @@ -30,7 +30,7 @@ export default class CalculatorCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage, args: { expression: string }) { + public override async exec(message: CommandMessage | SlashMessage, args: { expression: string }) { const decodedEmbed = new EmbedBuilder().addFields([ { name: '📥 Input', diff --git a/src/commands/utilities/decode.ts b/src/commands/utilities/decode.ts index 7cb0e83..8c82fcc 100644 --- a/src/commands/utilities/decode.ts +++ b/src/commands/utilities/decode.ts @@ -1,5 +1,4 @@ -import { AllowedMentions, BushCommand, type BushMessage } from '#lib'; -import { type AkairoMessage } from 'discord-akairo'; +import { AllowedMentions, BushCommand, type CommandMessage, type SlashMessage } from '#lib'; import { ApplicationCommandOptionType, EmbedBuilder } from 'discord.js'; const encodingTypesArray = ['ascii', 'utf8', 'utf-8', 'utf16le', 'ucs2', 'ucs-2', 'base64', 'latin1', 'binary', 'hex']; @@ -49,7 +48,7 @@ export default class DecodeCommand extends BushCommand { } public override async exec( - message: BushMessage | AkairoMessage, + message: CommandMessage | SlashMessage, { from, to, data }: { from: BufferEncoding; to: BufferEncoding; data: string } ) { const encodeOrDecode = util.capitalizeFirstLetter(message?.util?.parsed?.alias ?? 'decoded'); diff --git a/src/commands/utilities/hash.ts b/src/commands/utilities/hash.ts index 7cc59f3..f47c388 100644 --- a/src/commands/utilities/hash.ts +++ b/src/commands/utilities/hash.ts @@ -1,4 +1,4 @@ -import { BushCommand, type BushMessage } from '#lib'; +import { BushCommand, type CommandMessage } from '#lib'; import assert from 'assert'; import crypto from 'crypto'; import { ApplicationCommandOptionType } from 'discord.js'; @@ -30,7 +30,7 @@ export default class HashCommand extends BushCommand { }); } - public override async exec(message: BushMessage, { url }: { url: string }) { + public override async exec(message: CommandMessage, { url }: { url: string }) { try { const req = await got.get(url); const rawHash = crypto.createHash('md5'); diff --git a/src/commands/utilities/highlight-!.ts b/src/commands/utilities/highlight-!.ts index 9aeb9ec..6dca545 100644 --- a/src/commands/utilities/highlight-!.ts +++ b/src/commands/utilities/highlight-!.ts @@ -1,7 +1,11 @@ -import { BushCommand, Highlight, HighlightWord, type BushSlashMessage } from '#lib'; +import { BushCommand, Highlight, HighlightWord, type SlashMessage } from '#lib'; import { Flag, type ArgumentGeneratorReturn, type SlashOption } from 'discord-akairo'; -import { ApplicationCommandOptionType } from 'discord-api-types/v10'; -import { ApplicationCommandSubCommandData, AutocompleteInteraction, CacheType } from 'discord.js'; +import { + ApplicationCommandOptionType, + ApplicationCommandSubCommandData, + type AutocompleteInteraction, + type CacheType +} from 'discord.js'; type Unpacked<T> = T extends (infer U)[] ? U : T; @@ -139,7 +143,7 @@ export default class HighlightCommand extends BushCommand { return Flag.continue(`highlight-${subcommand}`); } - public override async execSlash(message: BushSlashMessage, args: { subcommand: keyof typeof highlightSubcommands }) { + public override async execSlash(message: SlashMessage, args: { subcommand: keyof typeof highlightSubcommands }) { // manual `Flag.continue` const subcommand = this.handler.modules.get(`highlight-${args.subcommand}`)!; return subcommand.exec(message, args); diff --git a/src/commands/utilities/highlight-add.ts b/src/commands/utilities/highlight-add.ts index 73c61d2..726b887 100644 --- a/src/commands/utilities/highlight-add.ts +++ b/src/commands/utilities/highlight-add.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 { highlightCommandArgs, highlightSubcommands } from './highlight-!.js'; @@ -37,10 +37,7 @@ export default class HighlightAddCommand extends BushCommand { }); } - public override async exec( - message: BushMessage | BushSlashMessage, - args: { word: ArgType<'string'>; regex: ArgType<'boolean'> } - ) { + public override async exec(message: CommandMessage | SlashMessage, args: { word: ArgType<'string'>; regex: ArgType<'flag'> }) { assert(message.inGuild()); args.regex = false; diff --git a/src/commands/utilities/highlight-block.ts b/src/commands/utilities/highlight-block.ts index 4ad1a86..61e1254 100644 --- a/src/commands/utilities/highlight-block.ts +++ b/src/commands/utilities/highlight-block.ts @@ -1,4 +1,4 @@ -import { AllowedMentions, BushCommand, Highlight, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { AllowedMentions, BushCommand, Highlight, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; import { Argument, ArgumentGeneratorReturn } from 'discord-akairo'; import { Channel, GuildMember } from 'discord.js'; @@ -18,7 +18,7 @@ export default class HighlightBlockCommand extends BushCommand { } public override *args(): ArgumentGeneratorReturn { - const target: ArgType<'member'> | ArgType<'channel'> = yield { + const target: ArgType<'member' | 'channel'> = yield { type: Argument.union('member', 'channel'), match: 'rest', prompt: { @@ -31,10 +31,7 @@ export default class HighlightBlockCommand extends BushCommand { return { target }; } - public override async exec( - message: BushMessage | BushSlashMessage, - args: { target: string | ArgType<'member'> | ArgType<'channel'> } - ) { + public override async exec(message: CommandMessage | SlashMessage, args: { target: string | ArgType<'member' | 'channel'> }) { assert(message.inGuild()); args.target = diff --git a/src/commands/utilities/highlight-clear.ts b/src/commands/utilities/highlight-clear.ts index 274c6fb..b905f3b 100644 --- a/src/commands/utilities/highlight-clear.ts +++ b/src/commands/utilities/highlight-clear.ts @@ -1,4 +1,4 @@ -import { BushCommand, ConfirmationPrompt, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, ConfirmationPrompt, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; import { highlightSubcommands } from './highlight-!.js'; @@ -15,7 +15,7 @@ export default class HighlightClearCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage) { + public override async exec(message: CommandMessage | SlashMessage) { assert(message.inGuild()); if (message.util.isSlashMessage(message)) await message.interaction.deferReply(); diff --git a/src/commands/utilities/highlight-matches.ts b/src/commands/utilities/highlight-matches.ts index 0e98c8d..40020cd 100644 --- a/src/commands/utilities/highlight-matches.ts +++ b/src/commands/utilities/highlight-matches.ts @@ -1,7 +1,7 @@ -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 { ArgumentGeneratorReturn } from 'discord-akairo'; -import { APIEmbed } from 'discord-api-types/v10'; +import { type ArgumentGeneratorReturn } from 'discord-akairo'; +import { type APIEmbed } from 'discord.js'; import { highlightCommandArgs, highlightSubcommands } from './highlight-!.js'; export default class HighlightMatchesCommand extends BushCommand { @@ -31,7 +31,7 @@ export default class HighlightMatchesCommand extends BushCommand { return { phrase }; } - public override async exec(message: BushMessage | BushSlashMessage, args: { phrase: ArgType<'string'> }) { + public override async exec(message: CommandMessage | SlashMessage, args: { phrase: ArgType<'string'> }) { assert(message.inGuild()); const res = await client.highlightManager.checkPhrase(message.guild.id, message.author.id, args.phrase); diff --git a/src/commands/utilities/highlight-remove.ts b/src/commands/utilities/highlight-remove.ts index 7e8c416..a2f2367 100644 --- a/src/commands/utilities/highlight-remove.ts +++ b/src/commands/utilities/highlight-remove.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 { highlightCommandArgs, highlightSubcommands } from './highlight-!.js'; @@ -28,7 +28,7 @@ export default class HighlightRemoveCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage, args: { word: ArgType<'string'> }) { + public override async exec(message: CommandMessage | SlashMessage, args: { word: ArgType<'string'> }) { assert(message.inGuild()); const res = await client.highlightManager.removeHighlight(message.guild.id, message.author.id, args.word); diff --git a/src/commands/utilities/highlight-show.ts b/src/commands/utilities/highlight-show.ts index d0a91e6..80ba4ca 100644 --- a/src/commands/utilities/highlight-show.ts +++ b/src/commands/utilities/highlight-show.ts @@ -1,4 +1,4 @@ -import { AllowedMentions, BushCommand, Highlight, type BushMessage, type BushSlashMessage } from '#lib'; +import { AllowedMentions, BushCommand, Highlight, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; import { EmbedBuilder } from 'discord.js'; import { highlightSubcommands } from './highlight-!.js'; @@ -16,7 +16,7 @@ export default class HighlightShowCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage) { + public override async exec(message: CommandMessage | SlashMessage) { assert(message.inGuild()); const [highlight] = await Highlight.findOrCreate({ diff --git a/src/commands/utilities/highlight-unblock.ts b/src/commands/utilities/highlight-unblock.ts index c437e6f..b738ee9 100644 --- a/src/commands/utilities/highlight-unblock.ts +++ b/src/commands/utilities/highlight-unblock.ts @@ -1,4 +1,4 @@ -import { AllowedMentions, BushCommand, Highlight, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { AllowedMentions, BushCommand, Highlight, type ArgType, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; import { Argument, ArgumentGeneratorReturn } from 'discord-akairo'; import { Channel, GuildMember } from 'discord.js'; @@ -18,7 +18,7 @@ export default class HighlightUnblockCommand extends BushCommand { } public override *args(): ArgumentGeneratorReturn { - const target: ArgType<'member'> | ArgType<'channel'> = yield { + const target: ArgType<'member' | 'channel'> = yield { type: Argument.union('member', 'channel'), match: 'rest', prompt: { @@ -31,10 +31,7 @@ export default class HighlightUnblockCommand extends BushCommand { return { target }; } - public override async exec( - message: BushMessage | BushSlashMessage, - args: { target: ArgType<'user'> | ArgType<'role'> | ArgType<'member'> } - ) { + public override async exec(message: CommandMessage | SlashMessage, args: { target: ArgType<'user' | 'role' | 'member'> }) { assert(message.inGuild()); if (!(args.target instanceof GuildMember || args.target instanceof Channel)) diff --git a/src/commands/utilities/price.ts b/src/commands/utilities/price.ts index e4e4f50..a4f4c03 100644 --- a/src/commands/utilities/price.ts +++ b/src/commands/utilities/price.ts @@ -1,4 +1,4 @@ -import { BushCommand, type BushMessage } from '#lib'; +import { ArgType, BushCommand, type CommandMessage } from '#lib'; import assert from 'assert'; import { ApplicationCommandOptionType, AutocompleteInteraction, EmbedBuilder, PermissionFlagsBits } from 'discord.js'; import Fuse from 'fuse.js'; @@ -45,7 +45,7 @@ export default class PriceCommand extends BushCommand { }); } - public override async exec(message: BushMessage, { item, strict }: { item: string; strict: boolean }) { + public override async exec(message: CommandMessage, args: { item: ArgType<'string'>; strict: ArgType<'flag'> }) { if (message.util.isSlashMessage(message)) await message.interaction.deferReply(); const errors: string[] = []; @@ -57,7 +57,7 @@ export default class PriceCommand extends BushCommand { got.get('https://moulberry.codes/auction_averages/3day.json').json().catch(() => { errors.push('auction average') }) ])) as [Bazaar | undefined, LowestBIN | undefined, LowestBIN | undefined, AuctionAverages | undefined]; - let parsedItem = item.toString().toUpperCase().replace(/ /g, '_').replace(/'S/g, ''); + let parsedItem = args.item.toString().toUpperCase().replace(/ /g, '_').replace(/'S/g, ''); const priceEmbed = new EmbedBuilder().setColor(errors?.length ? util.colors.warn : util.colors.success).setTimestamp(); if (bazaar?.success === false) errors.push('bazaar'); @@ -75,7 +75,7 @@ export default class PriceCommand extends BushCommand { ]); // fuzzy search - if (!strict) { + if (!args.strict) { parsedItem = new Fuse([...itemNames], { isCaseSensitive: false, findAllMatches: true, diff --git a/src/commands/utilities/remind.ts b/src/commands/utilities/remind.ts index 044d4fc..8727879 100644 --- a/src/commands/utilities/remind.ts +++ b/src/commands/utilities/remind.ts @@ -1,4 +1,4 @@ -import { BushCommand, Reminder, Time, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, Reminder, Time, type CommandMessage, type OptArgType, type SlashMessage } from '#lib'; import { ApplicationCommandOptionType } from 'discord.js'; export default class RemindCommand extends BushCommand { @@ -28,8 +28,8 @@ export default class RemindCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, - args: { reminder: ArgType<'contentWithDuration'> | string } + message: CommandMessage | SlashMessage, + args: { reminder: OptArgType<'contentWithDuration'> | string } ) { const { duration, content } = await util.castDurationContent(args.reminder, message); diff --git a/src/commands/utilities/reminders.ts b/src/commands/utilities/reminders.ts index 653274a..79284ac 100644 --- a/src/commands/utilities/reminders.ts +++ b/src/commands/utilities/reminders.ts @@ -1,7 +1,6 @@ -import { BushCommand, ButtonPaginator, Reminder, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, ButtonPaginator, Reminder, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; -import { APIEmbed } from 'discord-api-types/v10'; -import { PermissionFlagsBits } from 'discord.js'; +import { PermissionFlagsBits, type APIEmbed } from 'discord.js'; import { Op } from 'sequelize'; assert(Op); @@ -20,7 +19,7 @@ export default class RemindersCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage) { + public override async exec(message: CommandMessage | SlashMessage) { const reminders = await Reminder.findAll({ where: { user: message.author.id, expires: { [Op.gt]: new Date() } } }); if (!reminders.length) return message.util.send(`${util.emojis.error} You don't have any reminders set.`); diff --git a/src/commands/utilities/steal.ts b/src/commands/utilities/steal.ts index e4f08f1..69d3054 100644 --- a/src/commands/utilities/steal.ts +++ b/src/commands/utilities/steal.ts @@ -1,7 +1,7 @@ -import { BushCommand, OptArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, OptArgType, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; import { type ArgumentGeneratorReturn, type ArgumentType, type ArgumentTypeCaster } from 'discord-akairo'; -import { ApplicationCommandOptionType, PermissionFlagsBits, type Attachment } from 'discord.js'; +import { ApplicationCommandOptionType, Attachment, PermissionFlagsBits } from 'discord.js'; import _ from 'lodash'; import { Stream } from 'stream'; import { URL } from 'url'; @@ -41,7 +41,7 @@ export default class StealCommand extends BushCommand { }); } - public override *args(message: BushMessage): ArgumentGeneratorReturn { + public override *args(message: CommandMessage): ArgumentGeneratorReturn { const hasImage = message.attachments.size && message.attachments.first()?.contentType?.includes('image/'); const emoji = hasImage @@ -60,8 +60,8 @@ export default class StealCommand extends BushCommand { } public override async exec( - message: BushMessage, - args: { emoji: OptArgType<'discordEmoji'> | OptArgType<'snowflake'> | OptArgType<'url'> | string; name: string } + message: CommandMessage, + args: { emoji: OptArgType<'discordEmoji' | 'snowflake' | 'url'>; name: OptArgType<'string'> } ) { assert(message.inGuild()); @@ -88,7 +88,9 @@ export default class StealCommand extends BushCommand { : 'stolen_emoji'; const creationSuccess = await message.guild.emojis - .create(image, emojiName, { + .create({ + attachment: image, + name: emojiName, reason: `Stolen by ${message.author.tag} (${message.author.id})` }) .catch((e: Error) => e); @@ -102,7 +104,7 @@ export default class StealCommand extends BushCommand { } } - public override async execSlash(message: BushSlashMessage, args: { emoji: Attachment; name?: string }) { + public override async execSlash(message: SlashMessage, args: { emoji: Attachment; name: string | null }) { assert(message.inGuild()); const name = args.name ?? args.emoji.name ?? 'stolen_emoji'; @@ -119,7 +121,9 @@ export default class StealCommand extends BushCommand { : args.emoji.attachment; const creationSuccess = await message.guild.emojis - .create(data, name, { + .create({ + attachment: data, + name: name, reason: `Stolen by ${message.author.tag} (${message.author.id})` }) .catch((e: Error) => e); diff --git a/src/commands/utilities/suicide.ts b/src/commands/utilities/suicide.ts index e4609f2..c4151e8 100644 --- a/src/commands/utilities/suicide.ts +++ b/src/commands/utilities/suicide.ts @@ -1,4 +1,4 @@ -import { AllowedMentions, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { AllowedMentions, BushCommand, type CommandMessage, type SlashMessage } from '#lib'; import { stripIndent } from '#tags'; import { EmbedBuilder } from 'discord.js'; @@ -17,7 +17,7 @@ export default class SuicideCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage) { + public override async exec(message: CommandMessage | SlashMessage) { // stolen from https://github.com/dexbiobot/Zeppelin const suicideEmbed = new EmbedBuilder() .setTitle('Mental Health Resources') diff --git a/src/commands/utilities/uuid.ts b/src/commands/utilities/uuid.ts index 448baf3..1e70e91 100644 --- a/src/commands/utilities/uuid.ts +++ b/src/commands/utilities/uuid.ts @@ -1,4 +1,4 @@ -import { AllowedMentions, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import { AllowedMentions, ArgType, BushCommand, type CommandMessage, type SlashMessage } from '#lib'; import { ApplicationCommandOptionType } from 'discord.js'; export default class UuidCommand extends BushCommand { @@ -14,7 +14,7 @@ export default class UuidCommand extends BushCommand { id: 'ign', description: 'The ign to find the ign of.', customType: /\w{1,16}/im, - readableType: 'ign', + readableType: 'string[1,16]', prompt: 'What ign would you like to find the uuid of?', retry: '{error} Choose a valid ign.', slashType: ApplicationCommandOptionType.String @@ -23,7 +23,7 @@ export default class UuidCommand extends BushCommand { id: 'dashed', description: 'Include dashes in the uuid.', match: 'flag', - flag: '--dashed', + flag: ['--dashed', '-d'], prompt: 'Would you like to include dashes in the uuid?', slashType: ApplicationCommandOptionType.Boolean, optional: true @@ -36,15 +36,15 @@ export default class UuidCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, - { ign, dashed }: { ign: { match: RegExpMatchArray; matches?: any[] } | string; dashed: boolean } + message: CommandMessage | SlashMessage, + args: { ign: ArgType<'regex'> | string; dashed: ArgType<'flag'> } ) { - if (typeof ign === 'string') ign = { match: /\w{1,16}/im.exec(ign)! }; + if (typeof args.ign === 'string') args.ign = { match: /\w{1,16}/im.exec(args.ign)!, matches: [] }; - if (!ign || !ign.match) return await message.util.reply(`${util.emojis.error} Please enter a valid ign.`); - const readableIGN = ign.match[0]; + if (!args.ign.match) return await message.util.reply(`${util.emojis.error} Please enter a valid ign.`); + const readableIGN = args.ign.match[0]; try { - const uuid = await util.mcUUID(readableIGN, dashed); + const uuid = await util.mcUUID(readableIGN, args.dashed); return await message.util.reply({ content: `The uuid for ${util.format.input(readableIGN)} is ${util.format.input(uuid)}`, allowedMentions: AllowedMentions.none() diff --git a/src/commands/utilities/viewRaw.ts b/src/commands/utilities/viewRaw.ts index cb106dd..5c2c146 100644 --- a/src/commands/utilities/viewRaw.ts +++ b/src/commands/utilities/viewRaw.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 assert from 'assert'; import { ApplicationCommandOptionType, ChannelType, EmbedBuilder, Message, PermissionFlagsBits } from 'discord.js'; @@ -23,7 +23,7 @@ export default class ViewRawCommand extends BushCommand { { id: 'channel', description: 'The channel that the message is in.', - type: util.arg.union('textChannel', 'newsChannel', 'threadChannel'), + type: util.arg.union('textChannel', 'newsChannel', 'threadChannel', 'voiceChannel'), prompt: 'What channel is the message in?', retry: '{error} Choose a valid channel.', optional: true, @@ -34,7 +34,8 @@ export default class ViewRawCommand extends BushCommand { ChannelType.GuildNews, ChannelType.GuildNewsThread, ChannelType.GuildPublicThread, - ChannelType.GuildPrivateThread + ChannelType.GuildPrivateThread, + ChannelType.GuildVoice ] }, { @@ -64,12 +65,12 @@ export default class ViewRawCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, args: { - message: ArgType<'message'> | ArgType<'messageLink'>; - channel: OptArgType<'textChannel'> | OptArgType<'newsChannel'> | OptArgType<'threadChannel'>; - json: boolean; - js: boolean; + message: ArgType<'message' | 'messageLink'>; + channel: OptArgType<'textChannel' | 'newsChannel' | 'threadChannel' | 'voiceChannel'>; + json: ArgType<'flag'>; + js: ArgType<'flag'>; } ) { assert(message.inGuild()); @@ -88,7 +89,7 @@ export default class ViewRawCommand extends BushCommand { return await message.util.reply({ embeds: [Embed] }); } - public static async getRawData(message: BushMessage, options: { json?: boolean; js: boolean }): Promise<EmbedBuilder> { + public static async getRawData(message: Message, options: { json?: boolean; js: boolean }): Promise<EmbedBuilder> { const content = options.json || options.js ? options.json diff --git a/src/commands/utilities/whoHasRole.ts b/src/commands/utilities/whoHasRole.ts index 5f13c02..ae96a65 100644 --- a/src/commands/utilities/whoHasRole.ts +++ b/src/commands/utilities/whoHasRole.ts @@ -1,6 +1,6 @@ -import { BushCommand, BushRole, ButtonPaginator, OptArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { BushCommand, ButtonPaginator, OptArgType, type CommandMessage, type SlashMessage } from '#lib'; import assert from 'assert'; -import { ApplicationCommandOptionType, Util, type CommandInteraction } from 'discord.js'; +import { ApplicationCommandOptionType, Util, type CommandInteraction, type Role } from 'discord.js'; export default class WhoHasRoleCommand extends BushCommand { public constructor() { @@ -31,7 +31,7 @@ export default class WhoHasRoleCommand extends BushCommand { } public override async exec( - message: BushMessage | BushSlashMessage, + message: CommandMessage | SlashMessage, args: { [K in `role${NumberRange}`]: OptArgType<'role'>; } @@ -39,7 +39,7 @@ export default class WhoHasRoleCommand extends BushCommand { assert(message.inGuild()); if (message.util.isSlash) await (message.interaction as CommandInteraction).deferReply(); - const rawRoles = Object.values(args).filter((v) => v !== null) as BushRole[]; + const rawRoles = Object.values(args).filter((v) => v !== null) as Role[]; const roles = rawRoles.map((v) => v.id); const members = message.guild.members.cache.filter((m) => roles.every((r) => m.roles.cache.has(r))); diff --git a/src/commands/utilities/wolframAlpha.ts b/src/commands/utilities/wolframAlpha.ts index 0e1cb14..98cac69 100644 --- a/src/commands/utilities/wolframAlpha.ts +++ b/src/commands/utilities/wolframAlpha.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 { initializeClass as WolframAlphaAPI } from '@notenoughupdates/wolfram-alpha-api'; import assert from 'assert'; import { ApplicationCommandOptionType, EmbedBuilder, type MessageOptions } from 'discord.js'; @@ -39,7 +39,10 @@ export default class WolframAlphaCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage, args: { expression: string; image: boolean }) { + public override async exec( + message: CommandMessage | SlashMessage, + args: { expression: ArgType<'string'>; image: ArgType<'flag'> } + ) { if (message.util.isSlashMessage(message)) await message.interaction.deferReply(); args.image && void message.util.reply({ content: `${util.emojis.loading} Loading...`, embeds: [] }); |