diff options
Diffstat (limited to 'src/commands/utilities')
-rw-r--r-- | src/commands/utilities/activity.ts | 73 | ||||
-rw-r--r-- | src/commands/utilities/calculator.ts | 2 | ||||
-rw-r--r-- | src/commands/utilities/hash.ts | 3 | ||||
-rw-r--r-- | src/commands/utilities/price.ts | 3 | ||||
-rw-r--r-- | src/commands/utilities/reminders.ts | 2 | ||||
-rw-r--r-- | src/commands/utilities/steal.ts | 2 | ||||
-rw-r--r-- | src/commands/utilities/suicide.ts | 2 | ||||
-rw-r--r-- | src/commands/utilities/wolframAlpha.ts | 2 |
8 files changed, 72 insertions, 17 deletions
diff --git a/src/commands/utilities/activity.ts b/src/commands/utilities/activity.ts index e1c2d88..28d466b 100644 --- a/src/commands/utilities/activity.ts +++ b/src/commands/utilities/activity.ts @@ -1,5 +1,6 @@ -import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; -import { type DiscordAPIError, type Message } from 'discord.js'; +import { BushCommand, type ArgType, type BushArgumentTypeCaster, type BushMessage, type BushSlashMessage } from '#lib'; +import { type ArgumentOptions, type ArgumentTypeCaster, type Flag } from 'discord-akairo'; +import { type DiscordAPIError, type Snowflake } from 'discord.js'; const activityMap = { 'Poker Night': { @@ -48,29 +49,34 @@ const activityMap = { } }; -function map(phase: string) { - if (client.consts.regex.snowflake.test(phase)) return phase; +interface Activity { + id: Snowflake; + aliases: string[]; +} + +function map(phase: string): Activity | null { + if (client.consts.regex.snowflake.test(phase)) return { id: phase, aliases: [] }; else if (phase in activityMap) return activityMap[phase as keyof typeof activityMap]; for (const activity in activityMap) { if (activityMap[activity as keyof typeof activityMap].aliases.includes(phase.toLowerCase())) - return activityMap[activity as keyof typeof activityMap].id; + return activityMap[activity as keyof typeof activityMap]; } return null; } -const activityTypeCaster = (_message: Message | BushMessage | BushSlashMessage, phrase: string) => { - if (!phrase) return null; - const mappedPhrase = map(phrase); - if (mappedPhrase) return mappedPhrase; - return null; +const activityTypeCaster: BushArgumentTypeCaster<Snowflake | null> = (message: BushMessage, phrase: string) => { + const parsedPhrase = phrase ?? message.util.parsed?.alias !== 'activity' ? message.util.parsed?.alias : undefined; + if (!parsedPhrase) return null; + const mappedPhrase = map(parsedPhrase)?.id; + return mappedPhrase ?? null; }; -export default class YouTubeCommand extends BushCommand { +export default class ActivityCommand extends BushCommand { constructor() { super('activity', { - aliases: Object.values(activityMap).flatMap((a) => a.aliases), + aliases: ['activity', ...Object.values(activityMap).flatMap((a) => a.aliases)], category: 'utilities', description: 'Allows you to play discord activities in voice channels.', usage: [ @@ -87,9 +93,9 @@ export default class YouTubeCommand extends BushCommand { description: 'The channel to create the activity in.', type: 'voiceChannel', prompt: 'What channel would you like to use?', - retry: '{error} Choose a valid voice channel', slashType: 'CHANNEL', - channelTypes: ['GUILD_VOICE'] + channelTypes: ['GUILD_VOICE'], + only: 'slash' }, { id: 'activity', @@ -114,12 +120,47 @@ export default class YouTubeCommand extends BushCommand { }); } - public override async exec(message: BushMessage | BushSlashMessage, args: { channel: ArgType<'channel'>; activity: string }) { + public override *args(message: BushMessage): Generator<ArgumentOptions | Flag, any, any> { + const channel: ArgType<'voiceChannel'> = yield { + id: 'channel', + description: 'The channel to create the activity in.', + type: 'voiceChannel', + prompt: { + start: 'What channel would you like to use?', + retry: '{error} Choose a valid voice channel' + } + }; + + const activity: string = yield { + id: 'activity', + description: 'The activity to create an invite for.', + match: 'rest', + type: <ArgumentTypeCaster>activityTypeCaster, + prompt: { + start: 'What activity would you like to play?', + retry: `{error} You must choose one of the following options: ${Object.values(activityMap) + .flatMap((a) => a.aliases) + .map((a) => `\`${a}\``) + .join(', ')}.`, + optional: !!(message.util.parsed && message.util.parsed?.alias !== 'activity') + }, + default: message.util.parsed?.alias !== 'activity' ? message.util.parsed?.alias : undefined + }; + + return { channel, activity }; + } + + public override async exec( + message: BushMessage | BushSlashMessage, + args: { channel: ArgType<'voiceChannel'>; activity: string } + ) { const channel = typeof args.channel === 'string' ? message.guild?.channels.cache.get(args.channel) : args.channel; if (!channel || channel.type !== 'GUILD_VOICE') return await message.util.reply(`${util.emojis.error} Choose a valid voice channel`); - const target_application_id = message.util.isSlash ? args.activity : activityTypeCaster(message, args.activity); + const target_application_id = message.util.isSlashMessage(message) + ? args.activity + : activityTypeCaster(message, args.activity); let response: string; const invite = await (<any>client).api diff --git a/src/commands/utilities/calculator.ts b/src/commands/utilities/calculator.ts index 2c70dcc..2eeb3a6 100644 --- a/src/commands/utilities/calculator.ts +++ b/src/commands/utilities/calculator.ts @@ -1,6 +1,8 @@ import { AllowedMentions, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; +import assert from 'assert'; import { MessageEmbed } from 'discord.js'; import { evaluate } from 'mathjs'; +assert(evaluate); export default class CalculatorCommand extends BushCommand { public constructor() { diff --git a/src/commands/utilities/hash.ts b/src/commands/utilities/hash.ts index 7a1bfa7..7e892f5 100644 --- a/src/commands/utilities/hash.ts +++ b/src/commands/utilities/hash.ts @@ -1,6 +1,9 @@ import { BushCommand, type BushMessage } from '#lib'; +import assert from 'assert'; import crypto from 'crypto'; import got from 'got'; +assert(crypto); +assert(got); export default class HashCommand extends BushCommand { public constructor() { diff --git a/src/commands/utilities/price.ts b/src/commands/utilities/price.ts index e2cb837..409f544 100644 --- a/src/commands/utilities/price.ts +++ b/src/commands/utilities/price.ts @@ -1,7 +1,10 @@ import { BushCommand, type BushMessage } from '#lib'; +import assert from 'assert'; import { AutocompleteInteraction, MessageEmbed } from 'discord.js'; import Fuse from 'fuse.js'; import got from 'got'; +assert(Fuse); +assert(got); export default class PriceCommand extends BushCommand { public static cachedItemList: string[] = []; diff --git a/src/commands/utilities/reminders.ts b/src/commands/utilities/reminders.ts index 34034d8..8b4124d 100644 --- a/src/commands/utilities/reminders.ts +++ b/src/commands/utilities/reminders.ts @@ -1,6 +1,8 @@ import { BushCommand, ButtonPaginator, Reminder, type BushMessage, type BushSlashMessage } from '#lib'; +import assert from 'assert'; import { type MessageEmbedOptions } from 'discord.js'; import { Op } from 'sequelize'; +assert(Op); export default class RemindersCommand extends BushCommand { public constructor() { diff --git a/src/commands/utilities/steal.ts b/src/commands/utilities/steal.ts index 67b8382..834fc10 100644 --- a/src/commands/utilities/steal.ts +++ b/src/commands/utilities/steal.ts @@ -1,7 +1,9 @@ import { BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import assert from 'assert'; import { type ArgumentOptions, type ArgumentType, type ArgumentTypeCaster, type Flag } from 'discord-akairo'; import _ from 'lodash'; import { URL } from 'url'; +assert(_); export default class StealCommand extends BushCommand { public constructor() { diff --git a/src/commands/utilities/suicide.ts b/src/commands/utilities/suicide.ts index b347f9c..d880215 100644 --- a/src/commands/utilities/suicide.ts +++ b/src/commands/utilities/suicide.ts @@ -1,7 +1,7 @@ import { AllowedMentions, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; import { MessageEmbed } from 'discord.js'; -export default class TemplateCommand extends BushCommand { +export default class SuicideCommand extends BushCommand { public constructor() { super('suicide', { aliases: ['suicide'], diff --git a/src/commands/utilities/wolframAlpha.ts b/src/commands/utilities/wolframAlpha.ts index faf575c..6d8342c 100644 --- a/src/commands/utilities/wolframAlpha.ts +++ b/src/commands/utilities/wolframAlpha.ts @@ -1,6 +1,8 @@ import { AllowedMentions, BushCommand, type BushMessage, type BushSlashMessage } from '#lib'; import { initializeClass as WolframAlphaAPI } from '@notenoughupdates/wolfram-alpha-api'; +import assert from 'assert'; import { MessageEmbed, type MessageOptions } from 'discord.js'; +assert(WolframAlphaAPI); export default class WolframAlphaCommand extends BushCommand { public constructor() { |