aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-09-18 21:16:18 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-09-18 21:16:18 -0400
commit04dc104726fa1519480ba1889c1307ec3ad9be19 (patch)
treeca63ea2e06e90d1c9b218bc1254ff8802ecbd100
parent91ee22fbb53f191167cac23437f9be17c1535795 (diff)
downloadtanzanite-04dc104726fa1519480ba1889c1307ec3ad9be19.tar.gz
tanzanite-04dc104726fa1519480ba1889c1307ec3ad9be19.tar.bz2
tanzanite-04dc104726fa1519480ba1889c1307ec3ad9be19.zip
fix some shit
-rw-r--r--package.json1
-rw-r--r--src/commands/config/config.ts2
-rw-r--r--src/commands/config/log.ts2
-rw-r--r--src/commands/dev/superUser.ts2
-rw-r--r--src/commands/moderation/evidence.ts2
-rw-r--r--src/commands/moderation/role.ts2
-rw-r--r--src/commands/utilities/price.ts35
-rw-r--r--src/lib/extensions/discord-akairo/BushClientUtil.ts8
-rw-r--r--src/lib/extensions/discord-akairo/BushSlashMessage.ts5
-rw-r--r--src/lib/models/Guild.ts4
-rw-r--r--src/lib/models/ModLog.ts8
-rw-r--r--src/lib/models/__helpers.ts12
-rw-r--r--yarn.lock44
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<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: '[]'
diff --git a/yarn.lock b/yarn.lock
index f2d38fc..9ed00c1 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -15,9 +15,9 @@ __metadata:
linkType: hard
"@babel/helper-validator-identifier@npm:^7.14.5":
- version: 7.14.9
- resolution: "@babel/helper-validator-identifier@npm:7.14.9"
- checksum: 58552531a7674363e74672434c312ddaf1545b8a43308e1a7f38db58bf79c796c095a6dab6a6105eb0d783b97441f6cbb525bb887f29a35f232fcdbd8cb240dc
+ version: 7.15.7
+ resolution: "@babel/helper-validator-identifier@npm:7.15.7"
+ checksum: f041c28c531d1add5cc345b25d5df3c29c62bce3205b4d4a93dcd164ccf630350acba252d374fad8f5d8ea526995a215829f27183ba7ce7ce141843bf23068a6
languageName: node
linkType: hard
@@ -781,7 +781,6 @@ __metadata:
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
@@ -1010,13 +1009,6 @@ __metadata:
languageName: node
linkType: hard
-"data-uri-to-buffer@npm:^3.0.1":
- version: 3.0.1
- resolution: "data-uri-to-buffer@npm:3.0.1"
- checksum: c59c3009686a78c071806b72f4810856ec28222f0f4e252aa495ec027ed9732298ceea99c50328cf59b151dd34cbc3ad6150bbb43e41fc56fa19f48c99e9fc30
- languageName: node
- linkType: hard
-
"debug@npm:4, debug@npm:^4.0.1, debug@npm:^4.1.0, debug@npm:^4.1.1, debug@npm:^4.3.1":
version: 4.3.2
resolution: "debug@npm:4.3.2"
@@ -1116,12 +1108,12 @@ discord-akairo-message-util@NotEnoughUpdates/discord-akairo-message-util:
discord-akairo@NotEnoughUpdates/discord-akairo:
version: 9.0.0
- resolution: "discord-akairo@https://github.com/NotEnoughUpdates/discord-akairo.git#commit=be14ce4023cf05ad11f4a0ab87da40af30bb1c6a"
+ resolution: "discord-akairo@https://github.com/NotEnoughUpdates/discord-akairo.git#commit=5942c3c13accbe48d45d05ecce0516fcf994ef00"
dependencies:
discord-akairo-message-util: NotEnoughUpdates/discord-akairo-message-util
lodash: ^4.17.21
source-map-support: ^0.5.19
- checksum: 7326de82d184ce9a68ac6d13d12ca7f844dd12ccf0cc5a29de820ac60d4ce8b0fd46b0134fbd12e5399081dc7360abb2b8c3e2c456d43c8d3db04bc721b07ce6
+ checksum: 95606f6e433dcc52c9cf527caf3c59e102176127068052dc8ef217284aa44a9e12ed91ce5c36f68efd2c56f8df10dfe0be92c17c812862093ef573bc9aec5f39
languageName: node
linkType: hard
@@ -1473,15 +1465,6 @@ discord-akairo@NotEnoughUpdates/discord-akairo:
languageName: node
linkType: hard
-"fetch-blob@npm:^3.1.2":
- version: 3.1.2
- resolution: "fetch-blob@npm:3.1.2"
- dependencies:
- web-streams-polyfill: ^3.0.3
- checksum: 3e3717cf30da9f204aee83dded63f1a9f9c8bda7a0dc59648f89eeb1e88ee592231f4d922e1f119e1390383520768594dd3a1fe5e844f2f2f014d17ce04213a5
- languageName: node
- linkType: hard
-
"file-entry-cache@npm:^6.0.1":
version: 6.0.1
resolution: "file-entry-cache@npm:6.0.1"
@@ -2289,16 +2272,6 @@ discord-akairo@NotEnoughUpdates/discord-akairo:
languageName: node
linkType: hard
-"node-fetch@npm:^3.0.0":
- version: 3.0.0
- resolution: "node-fetch@npm:3.0.0"
- dependencies:
- data-uri-to-buffer: ^3.0.1
- fetch-blob: ^3.1.2
- checksum: 50224bf682a0bc3d44faee0f38df6269d8ae646de343595ef37f9d94b4322d3763a49819fb7b2df9330fcae16e0a20e5fb129dfed8725cf0e8f720277db7611c
- languageName: node
- linkType: hard
-
"node-gyp@npm:latest":
version: 8.2.0
resolution: "node-gyp@npm:8.2.0"
@@ -3363,13 +3336,6 @@ typescript@^4.4.3:
languageName: node
linkType: hard
-"web-streams-polyfill@npm:^3.0.3":
- version: 3.1.1
- resolution: "web-streams-polyfill@npm:3.1.1"
- checksum: dac85f0a990fb1ddcd15e2eda8ce4696bc9bc567e34cfdaeb9e740e26417d8649a6f466468907f50fd6e09967c25e0cf1f296c30aef9650ab7b118d5f69fb176
- languageName: node
- linkType: hard
-
"which@npm:^2.0.1, which@npm:^2.0.2":
version: 2.0.2
resolution: "which@npm:2.0.2"