diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/utilities/price.ts | 46 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushClient.ts | 26 | ||||
-rw-r--r-- | src/listeners/other/uncaughtException.ts | 23 |
3 files changed, 53 insertions, 42 deletions
diff --git a/src/commands/utilities/price.ts b/src/commands/utilities/price.ts index 231930c..a8cf127 100644 --- a/src/commands/utilities/price.ts +++ b/src/commands/utilities/price.ts @@ -1,7 +1,6 @@ import { Constants } from 'discord-akairo'; import { ColorResolvable, MessageEmbed } from 'discord.js'; import Fuse from 'fuse.js'; -import got from 'got'; import { BushCommand, BushMessage } from '../../lib'; interface Summary { @@ -98,22 +97,28 @@ export default class PriceCommand extends BushCommand { public async exec(message: BushMessage, { item, strict }: { item: string; strict: boolean }): Promise<unknown> { const errors = new Array<string>(); - const bazaar: Bazaar = await get('https://api.hypixel.net/skyblock/bazaar').catch(() => errors.push('bazaar')); - const currentLowestBIN: LowestBIN = await get('https://moulberry.codes/lowestbin.json').catch(() => - errors.push('current lowest BIN') - ); - const averageLowestBIN: LowestBIN = await get('https://moulberry.codes/auction_averages_lbin/3day.json').catch(() => - errors.push('average Lowest BIN') - ); - const auctionAverages: AuctionAverages = await get('https://moulberry.codes/auction_averages/3day.json').catch(() => - errors.push('auction average') - ); - // adds _ to item name + + const [bazaar, currentLowestBIN, averageLowestBIN, auctionAverages]: [Bazaar, LowestBIN, LowestBIN, AuctionAverages] = + await Promise.all([ + fetch('https://api.hypixel.net/skyblock/bazaar') + .then((resp) => resp.json()) + .catch(() => errors.push('bazaar')), + fetch('https://moulberry.codes/lowestbin.json') + .then((resp) => resp.json()) + .catch(() => errors.push('current lowest BIN')), + fetch('https://moulberry.codes/auction_averages_lbin/3day.json') + .then((resp) => resp.json()) + .catch(() => errors.push('average Lowest BIN')), + fetch('https://moulberry.codes/auction_averages/3day.json') + .then((resp) => resp.json()) + .catch(() => errors.push('auction average')) + ]); + let parsedItem = item.toString().toUpperCase().replace(/ /g, '_').replace(/'S/g, ''); const priceEmbed = new MessageEmbed(); if (errors?.length) { - priceEmbed.setFooter; + priceEmbed.setFooter(`Could not fetch data from ${this.client.util.oxford(errors, 'and', '')}`); } //combines all the item names from each @@ -201,20 +206,5 @@ export default class PriceCommand extends BushCommand { const a = Number(Number(price).toFixed(digits)); return commas ? a?.toLocaleString() : a?.toString(); } - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - async function get(url: string): Promise<any> { - const data = await got.get(url).catch((error) => { - this.client.console.warn('PriceCommand', `There was an problem fetching data from <<${url}>> with error:\n${error}`); - throw 'Error Fetching price data'; - }); - try { - const json = JSON.parse(data.body); - return json; - } catch (error) { - this.client.console.warn('PriceCommand', `There was an problem parsing data from <<${url}>> with error:\n${error}`); - throw 'json error'; - } - } } } diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts index 17d3e11..66204ac 100644 --- a/src/lib/extensions/discord-akairo/BushClient.ts +++ b/src/lib/extensions/discord-akairo/BushClient.ts @@ -165,7 +165,7 @@ export class BushClient extends AkairoClient { prefix: async ({ guild }: { guild: Guild }) => { if (this.config.isDevelopment) return 'dev '; const row = await GuildModel.findByPk(guild.id); - return (row?.prefix || this.config.isBeta ? 'bush ' : this.config.prefix) as string; + return (row?.prefix ?? this.config.prefix) as string; }, allowMention: true, handleEdits: true, @@ -173,8 +173,8 @@ export class BushClient extends AkairoClient { commandUtilLifetime: 300_000, argumentDefaults: { prompt: { - start: 'Placeholder argument prompt. If you see this please tell the devs.', - retry: 'Placeholder failed argument prompt. If you see this please tell the devs.', + start: 'Placeholder argument prompt. If you see this please tell my developers.', + retry: 'Placeholder failed argument prompt. If you see this please tell my developers.', modifyStart: (_: Message, str: string): string => `${str}\n\n Type \`cancel\` to cancel the command`, modifyRetry: (_: Message, str: string): string => `${str.replace('{error}', this.util.emojis.error)}\n\n Type \`cancel\` to cancel the command`, @@ -192,17 +192,15 @@ export class BushClient extends AkairoClient { }); this.util = new BushClientUtil(this); - this.db = new Sequelize( - this.config.isDevelopment ? 'bushbot-dev' : 'bushbot', - this.config.db.username, - this.config.db.password, - { - dialect: 'postgres', - host: this.config.db.host, - port: this.config.db.port, - logging: this.config.logging.db ? (sql) => this.logger.debug(sql) : false - } - ); + this.db = new Sequelize({ + database: this.config.isDevelopment ? 'bushbot-dev' : 'bushbot', + username: this.config.db.username, + password: this.config.db.password, + dialect: 'postgres', + host: this.config.db.host, + port: this.config.db.port, + logging: this.config.logging.db ? (sql) => this.logger.debug(sql) : false + }); this.logger = new BushLogger(this); } diff --git a/src/listeners/other/uncaughtException.ts b/src/listeners/other/uncaughtException.ts new file mode 100644 index 0000000..91d0a56 --- /dev/null +++ b/src/listeners/other/uncaughtException.ts @@ -0,0 +1,23 @@ +import { BushListener } from '@lib'; + +export default class UncaughtExceptionListener extends BushListener { + public constructor() { + super('uncaughtException', { + emitter: 'process', + event: 'uncaughtException' + }); + } + + public async exec(error: Error): Promise<void> { + this.client.console.error('uncaughtException', `An uncaught exception occurred:\n${error?.stack || error}`, false); + this.client.console.channelError({ + embeds: [ + { + title: 'An uncaught exception occurred', + fields: [{ name: 'error', value: await this.client.util.codeblock(`${error?.stack || error}`, 1024, 'js') }], + color: this.client.util.colors.error + } + ] + }); + } +} |