diff options
Diffstat (limited to 'src/commands/utilities')
-rw-r--r-- | src/commands/utilities/activity.ts | 6 | ||||
-rw-r--r-- | src/commands/utilities/decode.ts | 9 | ||||
-rw-r--r-- | src/commands/utilities/price.ts | 14 | ||||
-rw-r--r-- | src/commands/utilities/viewraw.ts | 17 |
4 files changed, 29 insertions, 17 deletions
diff --git a/src/commands/utilities/activity.ts b/src/commands/utilities/activity.ts index 0962fff..8bdfc21 100644 --- a/src/commands/utilities/activity.ts +++ b/src/commands/utilities/activity.ts @@ -1,4 +1,4 @@ -import { VoiceChannel } from 'discord.js'; +import { Message, VoiceChannel } from 'discord.js'; import { BushCommand, BushMessage, BushSlashMessage } from '../../lib'; const activityMap = { @@ -9,7 +9,7 @@ const activityMap = { 'Chess in the Park': '832012774040141894' }; -function map(phase) { +function map(phase: string) { if (['yt', 'youtube'].includes(phase)) return activityMap['YouTube Together']; else if (['chess', 'park'].includes(phase)) return activityMap['Chess in the Park']; else if (['poker'].includes(phase)) return activityMap['Poker Night']; @@ -19,7 +19,7 @@ function map(phase) { } // eslint-disable-next-line @typescript-eslint/no-unused-vars -const activityTypeCaster = (_message: BushMessage, phrase: string) => { +const activityTypeCaster = (_message: Message, phrase: string) => { if (!phrase) return null; const mappedPhrase = map(phrase); if (mappedPhrase) return mappedPhrase; diff --git a/src/commands/utilities/decode.ts b/src/commands/utilities/decode.ts index 9f56cfc..05e988a 100644 --- a/src/commands/utilities/decode.ts +++ b/src/commands/utilities/decode.ts @@ -95,17 +95,20 @@ export default class DecodeCommand extends BushCommand { message: BushMessage | AkairoMessage, { from, to, data }: { from: BufferEncoding; to: BufferEncoding; data: string } ): Promise<unknown> { + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing const encodeOrDecode = util.capitalizeFirstLetter(message?.util?.parsed?.alias || 'decoded'); const decodedEmbed = new MessageEmbed() .setTitle(`${encodeOrDecode} Information`) - .addField('📥 Input', await util.inspectCleanRedactCodeblock(data, null)); + .addField('📥 Input', await util.inspectCleanRedactCodeblock(data, undefined)); try { const decoded = Buffer.from(data, from).toString(to); - decodedEmbed.setColor(util.colors.success).addField('📤 Output', await util.inspectCleanRedactCodeblock(decoded, null)); + decodedEmbed + .setColor(util.colors.success) + .addField('📤 Output', await util.inspectCleanRedactCodeblock(decoded, undefined)); } catch (error) { decodedEmbed .setColor(util.colors.error) - .addField(`📤 Error ${encodeOrDecode.slice(1)}ing`, await util.inspectCleanRedactCodeblock(error.stack, null)); + .addField(`📤 Error ${encodeOrDecode.slice(1)}ing`, await util.inspectCleanRedactCodeblock(error.stack, undefined)); } return await message.util.reply({ embeds: [decodedEmbed], allowedMentions: AllowedMentions.none() }); } diff --git a/src/commands/utilities/price.ts b/src/commands/utilities/price.ts index a68c01d..921784f 100644 --- a/src/commands/utilities/price.ts +++ b/src/commands/utilities/price.ts @@ -112,6 +112,8 @@ export default class PriceCommand extends BushCommand { let parsedItem = item.toString().toUpperCase().replace(/ /g, '_').replace(/'S/g, ''); const priceEmbed = new MessageEmbed(); + if (bazaar?.success === false) errors.push('bazaar'); + if (errors?.length) { priceEmbed.setFooter(`Could not fetch data from ${util.oxford(errors, 'and', '')}`); } @@ -127,8 +129,8 @@ export default class PriceCommand extends BushCommand { // fuzzy search if (!strict) parsedItem = new Fuse(Array.from(itemNames))?.search(parsedItem)[0]?.item; - // iif bazaar item then it there should not be any ah data - if (bazaar['products'][parsedItem]) { + // if its a bazaar item then it there should not be any ah data + if (bazaar['products']?.[parsedItem]) { const bazaarPriceEmbed = new MessageEmbed() .setColor(errors?.length ? util.colors.warn : util.colors.success) .setTitle(`Bazaar Information for **${parsedItem}**`) @@ -168,8 +170,12 @@ export default class PriceCommand extends BushCommand { return await message.util.reply({ embeds: [priceEmbed] }); // helper functions - function addBazaarInformation(Information: string, digits: number, commas: boolean): string { - const price = bazaar?.products[parsedItem]?.quick_status?.[Information]; + function addBazaarInformation( + Information: keyof Bazaar['products'][string]['quick_status'], + digits: number, + commas: boolean + ): string { + const price = bazaar?.products?.[parsedItem]?.quick_status?.[Information]; const roundedPrice = Number(Number(price).toFixed(digits)); return commas ? roundedPrice?.toLocaleString() : roundedPrice?.toString(); } diff --git a/src/commands/utilities/viewraw.ts b/src/commands/utilities/viewraw.ts index e783dec..f6be382 100644 --- a/src/commands/utilities/viewraw.ts +++ b/src/commands/utilities/viewraw.ts @@ -70,18 +70,21 @@ export default class ViewRawCommand extends BushCommand { return await message.util.reply({ embeds: [messageEmbed] }); } - public static async getRawData(message: BushMessage, options: { json?: boolean; js: boolean }): Promise<unknown> { + public static async getRawData(message: BushMessage, options: { json?: boolean; js: boolean }): Promise<MessageEmbed> { const content = options.json || options.js ? options.json ? inspect(JSON.stringify(message.toJSON())) : inspect(message.toJSON()) || '[No Content]' : message.content || '[No Content]'; - return new MessageEmbed() - .setFooter(message.author.tag, message.author.avatarURL({ dynamic: true })) - .setTimestamp(message.createdTimestamp) - .setColor(message.member?.roles?.color?.color || util.colors.default) - .setTitle('Raw Message Information') - .setDescription(await util.codeblock(content, 2048, 'js')); + return ( + new MessageEmbed() + .setFooter(message.author.tag, message.author.avatarURL({ dynamic: true }) ?? undefined) + .setTimestamp(message.createdTimestamp) + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + .setColor(message.member?.roles?.color?.color || util.colors.default) + .setTitle('Raw Message Information') + .setDescription(await util.codeblock(content, 2048, 'js')) + ); } } |