From f94f1192bfcbf5f64c9661e5d3a482b31350a284 Mon Sep 17 00:00:00 2001 From: Vermium Sifell Date: Sun, 10 Apr 2022 18:15:19 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=92=EF=B8=8F=20fixed=20work=20command?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 4 ++++ src/commands/credits/modules/work.ts | 12 ++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 9513571..07981dc 100644 --- a/package.json +++ b/package.json @@ -26,9 +26,12 @@ "dependencies": { "@discordjs/builders": "^0.12.0", "@discordjs/rest": "^0.3.0", + "@nastyox/rando.js": "^2.0.5", "axios": "^0.26.0", "better-sqlite3": "^7.5.0", + "chance": "^1.1.8", "common": "^0.2.5", + "crypto": "^1.0.1", "dbd-dark-dashboard": "^1.6.45", "discord-api-types": "^0.31.0", "discord-dashboard": "^2.3.14", @@ -45,6 +48,7 @@ "uuid": "^8.3.2" }, "devDependencies": { + "@types/chance": "^1.1.3", "@types/node-schedule": "^1.3.2", "@types/uuid": "^8.3.4", "@typescript-eslint/eslint-plugin": "^5.15.0", diff --git a/src/commands/credits/modules/work.ts b/src/commands/credits/modules/work.ts index ae3847c..295e085 100644 --- a/src/commands/credits/modules/work.ts +++ b/src/commands/credits/modules/work.ts @@ -1,5 +1,6 @@ // Dependencies import { CommandInteraction, ColorResolvable } from 'discord.js'; +import Chance from 'chance'; // Configurations import config from '../../../../config.json'; @@ -20,6 +21,9 @@ export default async (interaction: CommandInteraction) => { // Destructure member const { guild, user } = interaction; + // Chance module + const chance = new Chance(); + // Check if user has a timeout const isTimeout = await timeouts?.findOne({ guildId: guild?.id, @@ -33,10 +37,10 @@ export default async (interaction: CommandInteraction) => { // If user is not on timeout if (!isTimeout) { - // Make a variable of how much credits user will earn based on random multiplied with work rate - const creditsEarned = Math?.floor( - Math?.random() * guildDB?.credits?.workRate - ); + const creditsEarned = chance.integer({ + min: 0, + max: guildDB?.credits?.workRate, + }); const userDB = await userSchema?.findOne({ userId: user?.id,