From 3ec20a1a5ff219c94adae36426479f81fdb82cf6 Mon Sep 17 00:00:00 2001 From: AnxietyisReal <96593068+AnxietyisReal@users.noreply.github.com> Date: Sun, 22 Jan 2023 22:21:32 +1100 Subject: [PATCH] Add statsGraph command and use fs instead of require --- src/client.ts | 4 +++- src/commands/dev.ts | 13 +++++++++++++ src/commands/mp.ts | 2 +- src/index.ts | 4 ++-- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/client.ts b/src/client.ts index c3fa5e4..30aa082 100644 --- a/src/client.ts +++ b/src/client.ts @@ -39,6 +39,7 @@ export class TClient extends Client { bonkCount: bonkCount; bannedWords: bannedWords; repeatedMessages: any; + statsGraph: number; constructor(){ super({ @@ -76,7 +77,8 @@ export class TClient extends Client { this.punishments = new punishments(this); this.bannedWords = new bannedWords(this); this.repeatedMessages = {}; - this.setMaxListeners(80) + this.setMaxListeners(80); + this.statsGraph = -60; } async init(){ MPDB.sync(); diff --git a/src/commands/dev.ts b/src/commands/dev.ts index 2e101ea..7181cfd 100644 --- a/src/commands/dev.ts +++ b/src/commands/dev.ts @@ -2,6 +2,8 @@ import Discord,{SlashCommandBuilder} from 'discord.js'; import { TClient } from 'src/client'; import * as util from 'node:util'; import {exec} from 'node:child_process'; +import { readFileSync } from 'node:fs'; +import path from 'node:path'; const removeUsername = (text: string)=>{ let matchesLeft = true; const array = text.split('\\'); @@ -77,6 +79,10 @@ export default { } }); break + case 'statsgraph': + client.statsGraph = -(interaction.options.getInteger('number', true)) + interaction.reply(`Successfully set to \`${client.statsGraph}\`\n*Total data points: **${JSON.parse(readFileSync(path.join(__dirname, '../database/MPPlayerData.json'), {encoding: 'utf8'})).length.toLocaleString()}***`); + break } }, data: new SlashCommandBuilder() @@ -98,4 +104,11 @@ export default { .addSubcommand((optt)=>optt .setName('update') .setDescription('Pull from repository and restart')) + .addSubcommand((optt)=>optt + .setName('statsgraph') + .setDescription('Edit the number of data points to pull') + .addIntegerOption((hiTae)=>hiTae + .setName('number') + .setDescription('Number of data points to pull') + .setRequired(true))) } diff --git a/src/commands/mp.ts b/src/commands/mp.ts index 6c9900a..788787e 100644 --- a/src/commands/mp.ts +++ b/src/commands/mp.ts @@ -63,7 +63,7 @@ export default { break; case 'players': const embed1 = new client.embed(); - const data = JSON.parse(fs.readFileSync(path.join(__dirname, '../database/MPPlayerData.json'), {encoding: 'utf8'})).slice(-60) + const data = JSON.parse(fs.readFileSync(path.join(__dirname, '../database/MPPlayerData.json'), {encoding: 'utf8'})).slice(client.statsGraph) // handle negative days data.forEach((change: number, i: number) => { diff --git a/src/index.ts b/src/index.ts index 56d2736..4d60bc9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -117,9 +117,9 @@ setInterval(async()=>{ return; } - const DB = require(`./database/MPPlayerData.json`); + const DB = JSON.parse(fs.readFileSync(__dirname + '/database/MPPlayerData.json', {encoding: 'utf8'})); DB.push(FSdss.data.slots.used) - fs.writeFileSync(__dirname + `/database/MPPlayerData.json`, JSON.stringify(DB)) + fs.writeFileSync(__dirname + '/database/MPPlayerData.json', JSON.stringify(DB)) // Number format function function formatNumber(number: any, digits: any, icon: any){