diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/commands/config/config.ts | 2 | ||||
-rw-r--r-- | src/commands/config/log.ts | 2 | ||||
-rw-r--r-- | src/commands/dev/superUser.ts | 2 | ||||
-rw-r--r-- | src/commands/moderation/evidence.ts | 2 | ||||
-rw-r--r-- | src/commands/moderation/role.ts | 2 | ||||
-rw-r--r-- | src/commands/utilities/price.ts | 35 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushClientUtil.ts | 8 | ||||
-rw-r--r-- | src/lib/extensions/discord-akairo/BushSlashMessage.ts | 5 | ||||
-rw-r--r-- | src/lib/models/Guild.ts | 4 | ||||
-rw-r--r-- | src/lib/models/ModLog.ts | 8 | ||||
-rw-r--r-- | src/lib/models/__helpers.ts | 12 |
11 files changed, 38 insertions, 44 deletions
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<ArgumentOptions | Flag> { + override *args(message: BushMessage): IterableIterator<ArgumentOptions | Flag> { 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<ArgumentOptions | Flag> { + override *args(): IterableIterator<ArgumentOptions | Flag> { 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<ArgumentOptions | Flag> { + override *args(): IterableIterator<ArgumentOptions | Flag> { 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<ArgumentOptions | Flag> { + override *args(message: BushMessage): IterableIterator<ArgumentOptions | Flag> { 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<ArgumentOptions | Flag> { + override *args(message: BushMessage): IterableIterator<ArgumentOptions | Flag> { 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<Bazaar>, Promise<LowestBIN>, Promise<LowestBIN>, Promise<AuctionAverages>]; - 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<string>(); - 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<Pronoun | undefined> { 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<GuildModel, GuildModelCreationAttributes> 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<ModLogModel, ModLogModelCreationAttributes pseudo: { type: DataTypes.STRING, get: function (): boolean { - return jsonParseGet('pseudo', this); + return jsonParseGet.call(this, 'pseudo'); }, set: function (val: boolean) { - return jsonParseSet('pseudo', this, val); + return jsonParseSet.call(this, 'pseudo', val); }, allowNull: false, defaultValue: 'false' @@ -202,10 +202,10 @@ export class ModLog extends BaseModel<ModLogModel, ModLogModelCreationAttributes hidden: { type: DataTypes.STRING, get: function (): boolean { - return jsonParseGet('hidden', this); + return jsonParseGet.call(this, 'hidden'); }, set: function (val: boolean) { - return jsonParseSet('hidden', this, val); + return jsonParseSet.call(this, 'hidden', val); }, allowNull: false, defaultValue: 'false' diff --git a/src/lib/models/__helpers.ts b/src/lib/models/__helpers.ts index b65c014..243b274 100644 --- a/src/lib/models/__helpers.ts +++ b/src/lib/models/__helpers.ts @@ -1,21 +1,21 @@ import { DataTypes, Model } from 'sequelize'; export const NEVER_USED = 'This should never be executed'; -export function jsonParseGet(key: string, that: Model): any { - return JSON.parse(that.getDataValue(key)); +export function jsonParseGet(this: Model, key: string): any { + return JSON.parse(this.getDataValue(key)); } -export function jsonParseSet(key: string, that: Model, value: any): any { - return that.setDataValue(key, JSON.stringify(value)); +export function jsonParseSet(this: Model, key: string, value: any): any { + return this.setDataValue(key, JSON.stringify(value)); } export function jsonArrayInit(key: string): any { return { type: DataTypes.TEXT, get: function (): string[] { - return jsonParseGet(key, this); + return jsonParseGet.call(this, key); }, set: function (val: string[]) { - return jsonParseSet(key, this, val); + return jsonParseSet.call(this, key, val); }, allowNull: false, defaultValue: '[]' |