diff options
| author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-01-01 08:53:23 -0500 |
|---|---|---|
| committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-01-01 08:53:23 -0500 |
| commit | e0ae0639d0b36c3cfd4065f791b95a32c1d7ea64 (patch) | |
| tree | 46547b51ad50b0a7a73fbc848ad643f8736399ae /src/commands/utilities | |
| parent | cbb68773614e44eb246e4cf2ff0d64d3e90f620f (diff) | |
| download | tanzanite-e0ae0639d0b36c3cfd4065f791b95a32c1d7ea64.tar.gz tanzanite-e0ae0639d0b36c3cfd4065f791b95a32c1d7ea64.tar.bz2 tanzanite-e0ae0639d0b36c3cfd4065f791b95a32c1d7ea64.zip | |
added autocomplete to a few commands and performed some fixes
Diffstat (limited to 'src/commands/utilities')
| -rw-r--r-- | src/commands/utilities/activity.ts | 23 | ||||
| -rw-r--r-- | src/commands/utilities/price.ts | 45 | ||||
| -rw-r--r-- | src/commands/utilities/suicide.ts | 21 | ||||
| -rw-r--r-- | src/commands/utilities/wolframAlpha.ts | 13 |
4 files changed, 43 insertions, 59 deletions
diff --git a/src/commands/utilities/activity.ts b/src/commands/utilities/activity.ts index 6801358..e1c2d88 100644 --- a/src/commands/utilities/activity.ts +++ b/src/commands/utilities/activity.ts @@ -70,24 +70,7 @@ const activityTypeCaster = (_message: Message | BushMessage | BushSlashMessage, export default class YouTubeCommand extends BushCommand { constructor() { super('activity', { - aliases: [ - 'activity', - 'yt', - 'youtube', - 'chess', - 'park', - 'poker', - 'fish', - 'fishing', - 'fishington', - 'betrayal', - 'doodle-crew', - 'doodle', - 'wood-snacks', - 'wood', - 'letter-tile', - 'letter' - ], + aliases: Object.values(activityMap).flatMap((a) => a.aliases), category: 'utilities', description: 'Allows you to play discord activities in voice channels.', usage: [ @@ -139,7 +122,7 @@ export default class YouTubeCommand extends BushCommand { const target_application_id = message.util.isSlash ? args.activity : activityTypeCaster(message, args.activity); let response: string; - const invite = await (client as any).api + const invite = await (<any>client).api .channels(channel.id) .invites.post({ data: { @@ -152,7 +135,7 @@ export default class YouTubeCommand extends BushCommand { } }) .catch((e: Error | DiscordAPIError) => { - if ((e as DiscordAPIError).code === 50013) { + if ((e as DiscordAPIError)?.code === 50013) { response = `${util.emojis.error} I am missing permissions to make an invite in that channel.`; return; } else response = `${util.emojis.error} An error occurred while generating your invite: ${e?.message ?? e}`; diff --git a/src/commands/utilities/price.ts b/src/commands/utilities/price.ts index 16dd327..e2cb837 100644 --- a/src/commands/utilities/price.ts +++ b/src/commands/utilities/price.ts @@ -1,9 +1,11 @@ import { BushCommand, type BushMessage } from '#lib'; -import { MessageEmbed } from 'discord.js'; +import { AutocompleteInteraction, MessageEmbed } from 'discord.js'; import Fuse from 'fuse.js'; import got from 'got'; export default class PriceCommand extends BushCommand { + public static cachedItemList: string[] = []; + public constructor() { super('price', { aliases: ['price'], @@ -19,7 +21,8 @@ export default class PriceCommand extends BushCommand { match: 'content', prompt: 'What item would you like to find the price of?', retry: '{error} Choose a valid item.', - slashType: 'STRING' + slashType: 'STRING', + autocomplete: true }, { id: 'strict', @@ -40,14 +43,14 @@ export default class PriceCommand extends BushCommand { public override async exec(message: BushMessage, { item, strict }: { item: string; strict: boolean }) { if (message.util.isSlashMessage(message)) await message.interaction.deferReply(); - const errors = new Array<string>(); + const errors: string[] = []; //prettier-ignore const [bazaar, currentLowestBIN, averageLowestBIN, auctionAverages] = (await Promise.all([ - got.get('https://api.hypixel.net/skyblock/bazaar').json().catch(() => errors.push('bazaar')), - got.get('https://moulberry.codes/lowestbin.json').json().catch(() => errors.push('current lowest BIN')), - got.get('https://moulberry.codes/auction_averages_lbin/3day.json').json().catch(() => errors.push('average Lowest BIN')), - got.get('https://moulberry.codes/auction_averages/3day.json').json().catch(() => errors.push('auction average')) + got.get('https://api.hypixel.net/skyblock/bazaar').json().catch(() => { errors.push('bazaar') }), + got.get('https://moulberry.codes/lowestbin.json').json().catch(() => { errors.push('current lowest BIN') }), + got.get('https://moulberry.codes/auction_averages_lbin/3day.json').json().catch(() => { errors.push('average Lowest BIN') }), + got.get('https://moulberry.codes/auction_averages/3day.json').json().catch(() => { errors.push('auction average') }) ])) as [Bazaar, LowestBIN, LowestBIN, AuctionAverages]; let parsedItem = item.toString().toUpperCase().replace(/ /g, '_').replace(/'S/g, ''); @@ -61,10 +64,10 @@ export default class PriceCommand extends BushCommand { // create a set from all the item names so that there are no duplicates for the fuzzy search const itemNames = new Set([ - ...Object.keys(averageLowestBIN || {}), - ...Object.keys(currentLowestBIN || {}), - ...Object.keys(auctionAverages || {}), - ...Object.keys(bazaar?.products || {}) + ...Object.keys(averageLowestBIN ?? {}), + ...Object.keys(currentLowestBIN ?? {}), + ...Object.keys(auctionAverages ?? {}), + ...Object.keys(bazaar?.products ?? {}) ]); // fuzzy search @@ -132,15 +135,27 @@ export default class PriceCommand extends BushCommand { priceEmbed.addField(name, price.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })); } } + + public override autocomplete(interaction: AutocompleteInteraction) { + const fuzzy = new Fuse(PriceCommand.cachedItemList, { + threshold: 0.5, + isCaseSensitive: false, + findAllMatches: true + }).search(interaction.options.getFocused().toString()); + + const res = fuzzy.slice(0, fuzzy.length >= 25 ? 25 : undefined).map((v) => ({ name: v.item, value: v.item })); + + void interaction.respond(res); + } } -interface Summary { +export interface Summary { amount: number; pricePerUnit: number; orders: number; } -interface Bazaar { +export interface Bazaar { success: boolean; lastUpdated: number; products: { @@ -163,11 +178,11 @@ interface Bazaar { }; } -interface LowestBIN { +export interface LowestBIN { [key: string]: number; } -interface AuctionAverages { +export interface AuctionAverages { [key: string]: { price?: number; count?: number; diff --git a/src/commands/utilities/suicide.ts b/src/commands/utilities/suicide.ts index f0d75a2..b347f9c 100644 --- a/src/commands/utilities/suicide.ts +++ b/src/commands/utilities/suicide.ts @@ -1,5 +1,5 @@ import { AllowedMentions, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; -import { MessageEmbed, type Message } from 'discord.js'; +import { MessageEmbed } from 'discord.js'; export default class TemplateCommand extends BushCommand { public constructor() { @@ -44,17 +44,14 @@ export default class TemplateCommand extends BushCommand { ].join('\n') ); - return ( + return message.util.send({ + embeds: [suicideEmbed], + allowedMentions: AllowedMentions.users(), // If the original message was a reply -> imitate it - !message.util.isSlashMessage(message) && (message as Message).reference?.messageId && message.guild && message.channel - ? await message.channel.messages.fetch((message as Message).reference!.messageId!).then(async (message1) => { - await message1.reply({ - embeds: [suicideEmbed], - allowedMentions: AllowedMentions.users(), - target: message1 - }); - }) - : await message.util.send({ embeds: [suicideEmbed], allowedMentions: AllowedMentions.users() }) - ); + reply: + !message.util.isSlashMessage(message) && message.reference?.messageId + ? { messageReference: message.reference.messageId } + : undefined + }); } } diff --git a/src/commands/utilities/wolframAlpha.ts b/src/commands/utilities/wolframAlpha.ts index 705e157..faf575c 100644 --- a/src/commands/utilities/wolframAlpha.ts +++ b/src/commands/utilities/wolframAlpha.ts @@ -18,8 +18,7 @@ export default class WolframAlphaCommand extends BushCommand { match: 'rest', prompt: 'What would you like to look up?', retry: '{error} Pick something to look up.', - slashType: 'STRING', - only: 'slash' + slashType: 'STRING' }, { id: 'image', @@ -29,16 +28,6 @@ export default class WolframAlphaCommand extends BushCommand { prompt: 'Would you like to use the Simple API instead of the Short Answers API?', slashType: 'BOOLEAN', optional: true - }, - { - id: 'expression', - description: 'The expression to query the Wolfram|Alpha api for.', - type: 'string', - match: 'rest', - prompt: 'What would you like to look up?', - retry: '{error} Pick something to look up.', - slashType: 'STRING', - only: 'text' } ], slash: true, |
