From 04dc104726fa1519480ba1889c1307ec3ad9be19 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Sat, 18 Sep 2021 21:16:18 -0400 Subject: fix some shit --- package.json | 1 - src/commands/config/config.ts | 2 +- src/commands/config/log.ts | 2 +- src/commands/dev/superUser.ts | 2 +- src/commands/moderation/evidence.ts | 2 +- src/commands/moderation/role.ts | 2 +- src/commands/utilities/price.ts | 35 ++++++++--------- .../extensions/discord-akairo/BushClientUtil.ts | 8 ++-- .../extensions/discord-akairo/BushSlashMessage.ts | 5 +-- src/lib/models/Guild.ts | 4 +- src/lib/models/ModLog.ts | 8 ++-- src/lib/models/__helpers.ts | 12 +++--- yarn.lock | 44 +++------------------- 13 files changed, 43 insertions(+), 84 deletions(-) diff --git a/package.json b/package.json index 627c375..df538e6 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,6 @@ "module-alias": "^2.2.2", "moment": "^2.29.1", "nanoid": "^3.1.25", - "node-fetch": "^3.0.0", "node-os-utils": "^1.3.5", "numeral": "^2.0.6", "pg": "^8.7.1", diff --git a/src/commands/config/config.ts b/src/commands/config/config.ts index 3f1fc8c..4cab741 100644 --- a/src/commands/config/config.ts +++ b/src/commands/config/config.ts @@ -111,7 +111,7 @@ export default class SettingsCommand extends BushCommand { } // I make very readable code :) - *args(message: BushMessage): IterableIterator { + override *args(message: BushMessage): IterableIterator { const optional = message.util.parsed!.alias === 'settings'; const setting = yield { id: 'setting', diff --git a/src/commands/config/log.ts b/src/commands/config/log.ts index 49db6f8..03e3582 100644 --- a/src/commands/config/log.ts +++ b/src/commands/config/log.ts @@ -34,7 +34,7 @@ export default class LogCommand extends BushCommand { }); } - *args(): IterableIterator { + override *args(): IterableIterator { const log_type = yield { id: 'log', type: guildLogsArr, diff --git a/src/commands/dev/superUser.ts b/src/commands/dev/superUser.ts index a36972b..4dc4584 100644 --- a/src/commands/dev/superUser.ts +++ b/src/commands/dev/superUser.ts @@ -17,7 +17,7 @@ export default class SuperUserCommand extends BushCommand { }); } - *args(): IterableIterator { + override *args(): IterableIterator { const action = yield { id: 'action', type: ['add', 'remove'], diff --git a/src/commands/moderation/evidence.ts b/src/commands/moderation/evidence.ts index 71a52b2..250df24 100644 --- a/src/commands/moderation/evidence.ts +++ b/src/commands/moderation/evidence.ts @@ -32,7 +32,7 @@ export default class EvidenceCommand extends BushCommand { }); } - *args(message: BushMessage): IterableIterator { + override *args(message: BushMessage): IterableIterator { const case_id = yield { id: 'case_id', type: 'string', diff --git a/src/commands/moderation/role.ts b/src/commands/moderation/role.ts index d0abb54..69432ab 100644 --- a/src/commands/moderation/role.ts +++ b/src/commands/moderation/role.ts @@ -55,7 +55,7 @@ export default class RoleCommand extends BushCommand { }); } - *args(message: BushMessage): IterableIterator { + override *args(message: BushMessage): IterableIterator { const action = ['rr'].includes(message.util.parsed?.alias ?? '') ? 'remove' : ['ar', 'ra'].includes(message.util.parsed?.alias ?? '') diff --git a/src/commands/utilities/price.ts b/src/commands/utilities/price.ts index 9ef997a..497935a 100644 --- a/src/commands/utilities/price.ts +++ b/src/commands/utilities/price.ts @@ -1,6 +1,6 @@ import { CommandInteraction, MessageEmbed } from 'discord.js'; import Fuse from 'fuse.js'; -import fetch from 'node-fetch'; +import got from 'got'; import { BushCommand, BushMessage } from '../../lib'; interface Summary { @@ -46,8 +46,6 @@ interface AuctionAverages { }; } -type Results = [Promise, Promise, Promise, Promise]; - export default class PriceCommand extends BushCommand { public constructor() { super('price', { @@ -101,16 +99,13 @@ export default class PriceCommand extends BushCommand { if (message.util.isSlash) await (message.interaction as CommandInteraction).deferReply(); const errors = new Array(); - const promises = ( - await Promise.all([ - fetch('https://api.hypixel.net/skyblock/bazaar').catch(() => errors.push('bazaar')), - fetch('https://moulberry.codes/lowestbin.json').catch(() => errors.push('current lowest BIN')), - fetch('https://moulberry.codes/auction_averages_lbin/3day.json').catch(() => errors.push('average Lowest BIN')), - fetch('https://moulberry.codes/auction_averages/3day.json').catch(() => errors.push('auction average')) - ]) - ).map(async (request) => await (typeof request === 'number' ? null : request.json())) as unknown as Results; - - const [bazaar, currentLowestBIN, averageLowestBIN, auctionAverages] = await Promise.all(promises); + //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')) + ])) as [Bazaar, LowestBIN, LowestBIN, AuctionAverages]; let parsedItem = item.toString().toUpperCase().replace(/ /g, '_').replace(/'S/g, ''); const priceEmbed = new MessageEmbed(); @@ -131,13 +126,12 @@ export default class PriceCommand extends BushCommand { // fuzzy search if (!strict) { - const _ = new Fuse(Array.from(itemNames), { + parsedItem = new Fuse(Array.from(itemNames), { isCaseSensitive: false, findAllMatches: true, threshold: 0.7, ignoreLocation: true - })?.search(parsedItem); - parsedItem = _[0]?.item; + })?.search(parsedItem)[0]?.item; } // if its a bazaar item then it there should not be any ah data @@ -180,18 +174,19 @@ export default class PriceCommand extends BushCommand { return await message.util.reply({ embeds: [priceEmbed] }); - // helper functions 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(); + return commas + ? (+price)?.toLocaleString(undefined, { minimumFractionDigits: digits, maximumFractionDigits: digits }) + : (+price)?.toFixed(digits); } function addPrice(name: string, price: number | undefined) { - if (price) priceEmbed.addField(name, price.toFixed(2).toLocaleString()); + if (price) + priceEmbed.addField(name, price.toLocaleString(undefined, { minimumFractionDigits: 2, maximumFractionDigits: 2 })); } } } diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index c15ca1c..5a71167 100644 --- a/src/lib/extensions/discord-akairo/BushClientUtil.ts +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -51,7 +51,6 @@ import got from 'got'; import humanizeDuration from 'humanize-duration'; import _ from 'lodash'; import moment from 'moment'; -import fetch from 'node-fetch'; import { inspect, InspectOptions, promisify } from 'util'; import CommandErrorListener from '../../../listeners/commands/commandError'; import { ActivePunishment, ActivePunishmentType } from '../../models/ActivePunishment'; @@ -1466,9 +1465,10 @@ export class BushClientUtil extends ClientUtil { public async getPronounsOf(user: User | Snowflake): Promise { const _user = await this.resolveNonCachedUser(user); if (!_user) throw new Error(`Cannot find user ${user}`); - const apiRes: { pronouns: PronounCode } | undefined = await fetch( - `https://pronoundb.org/api/v1/lookup?platform=discord&id=${_user.id}` - ).then(async (r) => (r.ok ? ((await r.json()) as { pronouns: PronounCode }) : undefined)); + const apiRes = (await got + .get(`https://pronoundb.org/api/v1/lookup?platform=discord&id=${_user.id}`) + .json() + .catch(() => undefined)) as { pronouns: PronounCode } | undefined; if (!apiRes) return undefined; if (!apiRes.pronouns) throw new Error('apiRes.pronouns is undefined'); diff --git a/src/lib/extensions/discord-akairo/BushSlashMessage.ts b/src/lib/extensions/discord-akairo/BushSlashMessage.ts index 442b0d4..d75d0a7 100644 --- a/src/lib/extensions/discord-akairo/BushSlashMessage.ts +++ b/src/lib/extensions/discord-akairo/BushSlashMessage.ts @@ -4,7 +4,6 @@ import { BushGuild } from '../discord.js/BushGuild'; import { BushGuildMember } from '../discord.js/BushGuildMember'; import { BushUser } from '../discord.js/BushUser'; import { BushClient } from './BushClient'; -import { BushCommand } from './BushCommand'; import { BushCommandUtil } from './BushCommandUtil'; export class BushSlashMessage extends AkairoMessage { @@ -12,8 +11,8 @@ export class BushSlashMessage extends AkairoMessage { public declare util: BushCommandUtil; public declare author: BushUser; public declare member: BushGuildMember | null; - public constructor(client: BushClient, interaction: CommandInteraction, command: BushCommand) { - super(client, interaction, command); + public constructor(client: BushClient, interaction: CommandInteraction) { + super(client, interaction); } public override get guild(): BushGuild | null { diff --git a/src/lib/models/Guild.ts b/src/lib/models/Guild.ts index 9b283ab..f59bed1 100644 --- a/src/lib/models/Guild.ts +++ b/src/lib/models/Guild.ts @@ -355,10 +355,10 @@ export class Guild extends BaseModel i logChannels: { type: DataTypes.TEXT, get: function (): LogChannelDB { - return jsonParseGet('logChannels', this); + return jsonParseGet.call(this, 'logChannels'); }, set: function (val: LogChannelDB) { - return jsonParseSet('logChannels', this, val); + return jsonParseSet.call(this, 'logChannels', val); }, allowNull: false, defaultValue: '{}' diff --git a/src/lib/models/ModLog.ts b/src/lib/models/ModLog.ts index a70913d..3675649 100644 --- a/src/lib/models/ModLog.ts +++ b/src/lib/models/ModLog.ts @@ -191,10 +191,10 @@ export class ModLog extends BaseModel