Skip to content
Permalink
Browse files

Fix shit (#135)

* 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 ecd3aa484e24fc36faca0baa8314439ca84cc01f
Showing with 302 additions and 206 deletions.
  1. +1 −0 .eslintignore
  2. +16 −4 .eslintrc.json
  3. +2 −0 .gitignore
  4. +3 −3 package.json
  5. +2 −0 src/arguments/image.ts
  6. +1 −0 src/arguments/integer.ts
  7. +3 −1 src/arguments/restRsn.ts
  8. +2 −0 src/arguments/rsn.ts
  9. +6 −7 src/commands/Configuration/channel.ts
  10. +2 −0 src/commands/Configuration/cmd.ts
  11. +7 −4 src/commands/Configuration/setrsn.ts
  12. +2 −2 src/commands/Configuration/tweets.ts
  13. +4 −3 src/commands/Configuration/twitchnotifications.ts
  14. +23 −3 src/commands/Fun/daily.ts
  15. +1 −1 src/commands/Fun/mine.ts
  16. +2 −0 src/commands/Fun/open.ts
  17. +2 −2 src/commands/Fun/sell.ts
  18. +2 −1 src/commands/OSRS_Fun/duel.ts
  19. +3 −3 src/commands/OSRS_Fun/kill.ts
  20. +5 −5 src/commands/Utility/bank.ts
  21. +4 −1 src/commands/Utility/leaderboard.ts
  22. +1 −2 src/commands/Utility/pay.ts
  23. +2 −3 src/commands/Utility/user.ts
  24. +16 −9 config/index.ts → src/config.ts
  25. +1 −2 src/events/commandError.ts
  26. +8 −8 src/events/redditPosts.ts
  27. +5 −4 src/events/tweets.ts
  28. +9 −9 src/extendables/UserExtendables.ts
  29. +8 −6 src/index.ts
  30. +2 −1 src/lib/5.2.0.ts
  31. +3 −2 src/lib/ClientSettings.ts
  32. +1 −0 src/lib/GuildSettings.ts
  33. +7 −6 src/lib/UserSettings.ts
  34. +1 −1 src/lib/collectionLog.ts
  35. +4 −6 src/lib/config/permissionLevels.ts
  36. +1 −1 src/lib/dailyTable.ts
  37. +9 −4 src/lib/killWorker.ts
  38. +1 −0 src/lib/pets.ts
  39. +0 −1 src/lib/types/Augments.d.ts
  40. +32 −1 src/lib/types/index.ts
  41. +14 −14 src/lib/util.ts
  42. +1 −8 src/lib/util/addSubTaskToActivityTask.ts
  43. +2 −2 src/lib/util/runActivityTask.ts
  44. +8 −4 src/monitors/commandHandler.ts
  45. +12 −2 src/providers/postgres.ts
  46. +1 −0 src/tasks/badges.ts
  47. +9 −13 src/tasks/bankImage.ts
  48. +2 −1 src/tasks/prices.ts
  49. +3 −0 src/tasks/reloadOnChanges.ts
  50. +2 −1 src/tasks/spawnWorkerThread.ts
  51. +4 −2 src/tasks/streamstatus.ts
  52. +0 −1 tsconfig.json
  53. +40 −52 yarn.lock
@@ -1,2 +1,3 @@
node_modules/
dist/
*.js
@@ -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,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/
@@ -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",
@@ -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"
@@ -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)
@@ -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
@@ -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;

@@ -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);
@@ -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');
}
}
@@ -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)) {
@@ -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)) {
@@ -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();
@@ -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]);
}

@@ -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) {
@@ -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 {
@@ -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)
@@ -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,
@@ -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
);
@@ -81,7 +100,7 @@ export default class DailyCommand extends BotCommand {
}

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

if (roll(73)) {
@@ -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);

@@ -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 ${
@@ -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...`
@@ -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 (
@@ -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);
@@ -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...`);
@@ -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);

@@ -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);
@@ -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');
@@ -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);
@@ -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()}`);
}
@@ -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) {

0 comments on commit ecd3aa4

Please sign in to comment.
You can’t perform that action at this time.