1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-12-27 04:15:38 -05:00

Add statsGraph command and use fs instead of require

This commit is contained in:
toast-ts 2023-01-22 22:21:32 +11:00
parent cf0f4642b7
commit a43c659ffc
4 changed files with 19 additions and 4 deletions

View File

@ -39,6 +39,7 @@ export class TClient extends Client {
bonkCount: bonkCount; bonkCount: bonkCount;
bannedWords: bannedWords; bannedWords: bannedWords;
repeatedMessages: any; repeatedMessages: any;
statsGraph: number;
constructor(){ constructor(){
super({ super({
@ -76,7 +77,8 @@ export class TClient extends Client {
this.punishments = new punishments(this); this.punishments = new punishments(this);
this.bannedWords = new bannedWords(this); this.bannedWords = new bannedWords(this);
this.repeatedMessages = {}; this.repeatedMessages = {};
this.setMaxListeners(80) this.setMaxListeners(80);
this.statsGraph = -60;
} }
async init(){ async init(){
MPDB.sync(); MPDB.sync();

View File

@ -2,6 +2,8 @@ import Discord,{SlashCommandBuilder} from 'discord.js';
import { TClient } from 'src/client'; import { TClient } from 'src/client';
import * as util from 'node:util'; import * as util from 'node:util';
import {exec} from 'node:child_process'; import {exec} from 'node:child_process';
import { readFileSync } from 'node:fs';
import path from 'node:path';
const removeUsername = (text: string)=>{ const removeUsername = (text: string)=>{
let matchesLeft = true; let matchesLeft = true;
const array = text.split('\\'); const array = text.split('\\');
@ -77,6 +79,10 @@ export default {
} }
}); });
break 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() data: new SlashCommandBuilder()
@ -98,4 +104,11 @@ export default {
.addSubcommand((optt)=>optt .addSubcommand((optt)=>optt
.setName('update') .setName('update')
.setDescription('Pull from repository and restart')) .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)))
} }

View File

@ -63,7 +63,7 @@ export default {
break; break;
case 'players': case 'players':
const embed1 = new client.embed(); 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 // handle negative days
data.forEach((change: number, i: number) => { data.forEach((change: number, i: number) => {

View File

@ -117,9 +117,9 @@ setInterval(async()=>{
return; 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) 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 // Number format function
function formatNumber(number: any, digits: any, icon: any){ function formatNumber(number: any, digits: any, icon: any){