Skip to content

Commit

Permalink
Fix shit (#135)
Browse files Browse the repository at this point in the history
* refactor minion tasks to use singular tasks

* fix moment import

* only fetch prices intermittently in prod

* fix lots of stuff

* fix lots more shit

* ignore all js files?

* re-organize config

* remove unused props

* trivia file optional

* make sure msg actually has content

* typo

* force sync settings on setrsn

* fix a couple small things

* fix a few things
  • Loading branch information
gc committed Feb 14, 2020
1 parent fcb5404 commit ecd3aa4
Show file tree
Hide file tree
Showing 53 changed files with 302 additions and 206 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules/
dist/
*.js
20 changes: 16 additions & 4 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
{
"extends": ["klasa", "prettier"],
"parser": "@typescript-eslint/parser",
"extends": ["bamboo", "prettier/@typescript-eslint", "plugin:prettier/recommended"],
"rules": {
"no-mixed-operators": "off",
"consistent-return": "off",
"prettier/prettier": "error",
"array-callback-return": "off",
"id-length": "off",
"complexity": "off"
"complexity": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/explicit-member-accessibility": "off",
"@typescript-eslint/prefer-for-of": "off",
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/require-await": "off",
"radix": "off",
"no-throw-literal": "off",
"no-negated-condition": "off"
},
"plugins": ["prettier"]
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2018
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
bot/bwd/provider/json/
src/bwd/provider/json/
/config/private.js
/config/private.json
/private.json
resources/trivia-questions.json
dist/
bwd/
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"scripts": {
"lint": "eslint ./ --fix && prettier --check ./ --write",
"lint": "prettier --check \"*/**/*.ts\" --write && eslint \"*/**/*.ts\" --fix",
"build": "tsc -p .",
"start": "concurrently \"tsc -p . -w\" \"node dist/src\""
"start": "npm run build && concurrently \"tsc -p . -w\" \"node dist/src\""
},
"dependencies": {
"@kcp/tags": "^1.0.0",
Expand Down Expand Up @@ -46,7 +46,7 @@
"eslint": "^6.8.0",
"eslint-config-bamboo": "^3.0.0",
"eslint-config-klasa": "github:dirigeants/klasa-lint",
"eslint-config-prettier": "^6.0.0",
"eslint-config-prettier": "^6.10.0",
"eslint-plugin-prettier": "^3.1.2",
"prettier": "^1.19.1",
"typescript": "^3.7.5"
Expand Down
2 changes: 2 additions & 0 deletions src/arguments/image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ export default class extends Argument {
}
} else {
// If they mentioned someone, return their avatar.
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
const member = this.constructor.regex.userOrMember.test(arg)
? await msg
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.guild!.members.fetch(this.constructor.regex.userOrMember.exec(arg)[1])
.catch(() => null)
Expand Down
1 change: 1 addition & 0 deletions src/arguments/integer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default class extends Argument {
throw message.language.get('RESOLVER_INVALID_INT', possible.name);
}

// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore 2341
return this.constructor.minOrMax(this.client, number, min, max, possible, message)
? number
Expand Down
4 changes: 3 additions & 1 deletion src/arguments/restRsn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ export default class extends Argument {
if (!arg) return this.store.get('rsn')!.run(arg, possible, message);

const {
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
args,
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
usage: { usageDelim }
} =
} = // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
message.prompter;

Expand Down
2 changes: 2 additions & 0 deletions src/arguments/rsn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ export default class extends Argument {
throw `Please specify a username, or set one with \`${prefix}setrsn <username>\``;
}

// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
if (this.constructor.regex.userOrMember.test(arg)) {
const user = await this.client.users
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
.fetch(this.constructor.regex.userOrMember.exec(arg)[1])
.catch(() => null);
Expand Down
13 changes: 6 additions & 7 deletions src/commands/Configuration/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,13 @@ export default class extends BotCommand {
});

return msg.sendLocale('CHANNEL_DISABLED');
} else {
if (!isDisabled) throw `This channel is already enabled.`;
}
if (!isDisabled) throw `This channel is already enabled.`;

await msg.guild!.settings.update(GuildSettings.StaffOnlyChannels, msg.channel.id, {
arrayAction: 'remove'
});
await msg.guild!.settings.update(GuildSettings.StaffOnlyChannels, msg.channel.id, {
arrayAction: 'remove'
});

return msg.sendLocale('CHANNEL_ENABLED');
}
return msg.sendLocale('CHANNEL_ENABLED');
}
}
2 changes: 2 additions & 0 deletions src/commands/Configuration/cmd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default class extends Command {
});
}

// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore 2416
async enable(msg: KlasaMessage, [command]: [Command]) {
if (!msg.guild!.settings.get(GuildSettings.DisabledCommands).includes(command.name)) {
Expand All @@ -25,6 +26,7 @@ export default class extends Command {
return msg.sendLocale('CMD_ENABLED', [command.name]);
}

// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore 2416
async disable(msg: KlasaMessage, [command]: [Command]) {
if (msg.guild!.settings.get(GuildSettings.DisabledCommands).includes(command.name)) {
Expand Down
11 changes: 7 additions & 4 deletions src/commands/Configuration/setrsn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ export default class extends Command {
}

async run(msg: KlasaMessage, [newRSN]: [string]) {
const RSN = msg.author.settings.get('RSN');
await msg.author.settings.sync(true);
const RSN = msg.author.settings.get(UserSettings.RSN);
if (!newRSN && RSN) {
return msg.sendLocale('RSN_CURRENT', [msg.author.settings.get(UserSettings.RSN)]);
}

if (!newRSN && !RSN) {
return msg.sendLocale('RSN_NOT_SET', [msg.guild!.settings.get(GuildSettings.Prefix)]);
return msg.sendLocale('RSN_NOT_SET', [
msg.guild!.settings.get(GuildSettings.Prefix) ?? '+'
]);
}

newRSN = newRSN.toLowerCase();
Expand All @@ -31,10 +34,10 @@ export default class extends Command {
}

if (RSN !== null) {
await msg.author.settings.update('RSN', newRSN);
await msg.author.settings.update(UserSettings.RSN, newRSN);
msg.sendLocale('RSN_CHANGED', [RSN, newRSN]);
} else {
await msg.author.settings.update('RSN', newRSN);
await msg.author.settings.update(UserSettings.RSN, newRSN);
msg.sendLocale('RSN_SET_TO', [newRSN]);
}

Expand Down
4 changes: 2 additions & 2 deletions src/commands/Configuration/tweets.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Command } from 'klasa';
import { Command, CommandStore, KlasaMessage } from 'klasa';

import { GuildSettings } from '../../lib/GuildSettings';
import { CommandStore, KlasaMessage } from 'klasa';

export default class extends Command {
public constructor(store: CommandStore, file: string[], directory: string) {
Expand Down
7 changes: 4 additions & 3 deletions src/commands/Configuration/twitchnotifications.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Command, CommandStore } from 'klasa';
import { Command, CommandStore, KlasaMessage } from 'klasa';

import { GuildSettings } from '../../lib/GuildSettings';
import { KlasaMessage } from 'klasa';
import OSRSStreamers from '../../../data/osrs_streamers';

export default class extends Command {
Expand Down Expand Up @@ -67,8 +67,9 @@ export default class extends Command {
if (!name) {
return msg.sendLocale('TN_NO_STREAMER_REMOVE', [msg.guild!.settings.get('prefix')]);
}
if (!OSRSStreamers.includes(name.toLowerCase()))
if (!OSRSStreamers.includes(name.toLowerCase())) {
return msg.sendLocale('TN_INVALID_STREAMER');
}
if (
!msg
.guild!.settings.get(GuildSettings.TwitchNotifications.Streamers)
Expand Down
26 changes: 23 additions & 3 deletions src/commands/Fun/daily.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
import { CommandStore, KlasaMessage } from 'klasa';
import { TextChannel } from 'discord.js';
import * as fs from 'fs';

if (!fs.existsSync('./resources/trivia-questions.json')) {
fs.writeFileSync(
'./resources/trivia-questions.json',
JSON.stringify(
{
triviaQuestions: []
},
null,
4
)
);
console.log(`Created empty trivia questions file at ./resources/trivia-questions.json`);
}

const { triviaQuestions } = JSON.parse(
fs.readFileSync('./resources/trivia-questions.json').toString()
);

import { triviaQuestions } from '../../../resources/trivia-questions.json';
import { BotCommand } from '../../lib/BotCommand.js';
import { Time, Emoji, SupportServer, Channel } from '../../lib/constants.js';
import * as pets from '../../../data/pets';
import { randomHappyEmoji, isWeekend, formatDuration, rand, roll } from '../../lib/util.js';
import { UserSettings } from '../../lib/UserSettings.js';
import { ClientSettings } from '../../lib/ClientSettings.js';

const easyTrivia = triviaQuestions.slice(0, 40);
const easyTrivia = triviaQuestions!.slice(0, 40);

const options = {
max: 1,
Expand Down Expand Up @@ -42,6 +60,7 @@ export default class DailyCommand extends BotCommand {
const collected = await msg.channel.awaitMessages(
answer =>
answer.author.id === msg.author.id &&
answer.content &&
trivia.a.includes(answer.content.toLowerCase()),
options
);
Expand Down Expand Up @@ -81,7 +100,7 @@ export default class DailyCommand extends BotCommand {
}

if (msg.author.hasMinion) {
amount = amount / 4;
amount /= 4;
}

if (roll(73)) {
Expand Down Expand Up @@ -134,6 +153,7 @@ export default class DailyCommand extends BotCommand {
const channel = this.client.channels.get(Channel.Notifications);
if (channel) (channel as TextChannel).send(chStr);

// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
const gpImage = this.client.commands.get('bank').generateImage(amount);

Expand Down
2 changes: 1 addition & 1 deletion src/commands/Fun/mine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default class extends BotCommand {
finishDate: Date.now() + duration
};

await addSubTaskToActivityTask(this.client, Tasks.MonsterKillingTicker, data);
await addSubTaskToActivityTask(this.client, Tasks.MiningTicker, data);

return msg.send(
`${msg.author.minionName} is now mining ${quantity}x ${
Expand Down
2 changes: 2 additions & 0 deletions src/commands/Fun/open.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ export default class extends BotCommand {
const task = this.client.tasks.get('bankImage');

// TODO - add 'WTF' error handling, maybe coerce this
// eslint-disable-next-line @typescript-eslint/unbound-method
if (!task || !task.generateBankImage) throw '';

const image = await task!.generateBankImage(
loot,
`You opened a ${clueTier.name} clue and received...`
Expand Down
4 changes: 2 additions & 2 deletions src/commands/Fun/sell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class extends BotCommand {
}

async run(msg: KlasaMessage, [quantity, itemName]: [number, string]) {
let re = //gi;
const re = //gi;
const osItem = Items.get(itemName.replace(re, "'"));
if (!osItem) throw `That item doesnt exist.`;
if (
Expand All @@ -36,7 +36,7 @@ export default class extends BotCommand {
throw `That item isn't tradeable.`;
}

let priceOfItem = await this.client.fetchItemPrice(osItem.id);
const priceOfItem = await this.client.fetchItemPrice(osItem.id);
let totalPrice = priceOfItem * quantity;

const hasItem = await msg.author.hasItem(osItem.id, quantity);
Expand Down
3 changes: 2 additions & 1 deletion src/commands/OSRS_Fun/duel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export default class extends BotCommand {
await sleep(2000);
await duelMsg.edit(`${user.username} and ${msg.author.username} begin fighting...`);

let [winner, loser] = Math.random() > 0.5 ? [user, msg.author] : [msg.author, user];
const [winner, loser] = Math.random() > 0.5 ? [user, msg.author] : [msg.author, user];

await sleep(2000);
await duelMsg.edit(`The fight is almost over...`);
Expand All @@ -109,6 +109,7 @@ export default class extends BotCommand {

await winner.addGP(winningAmount - tax);

// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
const gpImage = this.client.commands.get('bank').generateImage(winningAmount);

Expand Down
6 changes: 3 additions & 3 deletions src/commands/OSRS_Fun/kill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export default class extends Command {
}

async run(msg: KlasaMessage, [quantity, bossName]: [number, string]) {
const result: ItemBank = await this.client.killWorkerThread.queue(async (fn: any) => {
return fn.kill({ quantity, bossName, limit: this.determineKillLimit(msg.author) });
});
const result: ItemBank = await this.client.killWorkerThread.queue(async (fn: any) =>
fn.kill({ quantity, bossName, limit: this.determineKillLimit(msg.author) })
);

if (typeof result === 'string') {
return msg.send(result);
Expand Down
10 changes: 5 additions & 5 deletions src/commands/Utility/bank.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { Command, KlasaMessage, CommandStore } from 'klasa';
import { Command, KlasaMessage, CommandStore, RichDisplay, util } from 'klasa';
import { MessageAttachment, MessageEmbed } from 'discord.js';
import { createCanvas, Image, registerFont } from 'canvas';
import * as fs from 'fs';
import { Items } from 'oldschooljs';

import { generateHexColorForCashStack, formatItemStackQuantity, chunkObject } from '../../lib/util';
import { Bank } from '../../lib/types';
import { Emoji } from '../../lib/constants';
import { Items } from 'oldschooljs';
import { RichDisplay } from 'klasa';
import { util } from 'klasa';
import { UserSettings } from '../../lib/UserSettings';

const bg = fs.readFileSync('./resources/images/coins.png');
Expand Down Expand Up @@ -45,6 +43,7 @@ export default class extends Command {
return new MessageAttachment(canvas.toBuffer(), `bank.jpg`);
}

// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
// @ts-ignore
async run(msg: KlasaMessage, [page = 1]: [number]) {
await msg.author.settings.sync(true);
Expand All @@ -71,7 +70,7 @@ export default class extends Command {
const display = new RichDisplay();
display.setFooterPrefix(`Page `);

let textBank = [];
const textBank = [];
for (const [id, qty] of Object.entries(bank)) {
textBank.push(`**${Items.get(parseInt(id))!.name}:** ${qty.toLocaleString()}`);
}
Expand All @@ -91,6 +90,7 @@ export default class extends Command {
const task = this.client.tasks.get('bankImage');

// TODO - add 'WTF' error handling, maybe coerce this
// eslint-disable-next-line @typescript-eslint/unbound-method
if (!task || !task.generateBankImage) throw '';

if (bankKeys.length < 57) {
Expand Down
Loading

0 comments on commit ecd3aa4

Please sign in to comment.