mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-11-17 04:10:59 -05:00
Add path and fs to rank and mp
This commit is contained in:
parent
5a63c21532
commit
38be6827a7
@ -1,6 +1,8 @@
|
|||||||
import Discord,{EmbedBuilder, SlashCommandBuilder} from 'discord.js';
|
import Discord,{EmbedBuilder, SlashCommandBuilder} from 'discord.js';
|
||||||
import { TClient } from 'src/client';
|
import { TClient } from 'src/client';
|
||||||
import MPDB from '../models/MPServer';
|
import MPDB from '../models/MPServer';
|
||||||
|
import path from 'node:path';
|
||||||
|
import fs from 'node:fs';
|
||||||
|
|
||||||
async function MPdata(client:TClient, interaction:Discord.ChatInputCommandInteraction, embed: EmbedBuilder) {
|
async function MPdata(client:TClient, interaction:Discord.ChatInputCommandInteraction, embed: EmbedBuilder) {
|
||||||
let FSserver;
|
let FSserver;
|
||||||
@ -61,7 +63,7 @@ export default {
|
|||||||
break;
|
break;
|
||||||
case 'players':
|
case 'players':
|
||||||
const embed1 = new client.embed();
|
const embed1 = new client.embed();
|
||||||
const data = require('../database/MPPlayerData.json').slice(-60)
|
const data = JSON.parse(fs.readFileSync(path.join(__dirname, '../database/MPPlayerData.json'), {encoding: 'utf8'})).slice(-60)
|
||||||
|
|
||||||
// handle negative days
|
// handle negative days
|
||||||
data.forEach((change: number, i: number) => {
|
data.forEach((change: number, i: number) => {
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import Discord,{SlashCommandBuilder} from 'discord.js';
|
import Discord,{SlashCommandBuilder} from 'discord.js';
|
||||||
import { TClient } from 'src/client';
|
import { TClient } from 'src/client';
|
||||||
import { UserLevels } from 'src/typings/interfaces';
|
import { UserLevels } from 'src/typings/interfaces';
|
||||||
|
import path from 'node:path';
|
||||||
|
import fs from 'node:fs';
|
||||||
export default {
|
export default {
|
||||||
async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
|
async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
|
||||||
if (interaction.guildId !== client.config.mainServer.id) return interaction.reply({content: 'This command doesn\'t work in this server.', ephemeral: true});
|
if (interaction.guildId !== client.config.mainServer.id) return interaction.reply({content: 'This command doesn\'t work in this server.', ephemeral: true});
|
||||||
@ -10,7 +12,8 @@ export default {
|
|||||||
const messageCountsTotal = Object.values<UserLevels>(client.userLevels._content).reduce((a, b) => a + b.messages, 0);
|
const messageCountsTotal = Object.values<UserLevels>(client.userLevels._content).reduce((a, b) => a + b.messages, 0);
|
||||||
const timeActive = Math.floor((Date.now() - client.config.LRSstart)/1000/60/60/24);
|
const timeActive = Math.floor((Date.now() - client.config.LRSstart)/1000/60/60/24);
|
||||||
|
|
||||||
const data = require('../database/dailyMsgs.json').map((x: Array<number>, i: number, a: any) => {
|
const dailyMsgsPath = path.join(__dirname, '../database/dailyMsgs.json');
|
||||||
|
const data = JSON.parse(fs.readFileSync(dailyMsgsPath, {encoding: 'utf8'})).map((x: Array<number>, i: number, a: any) => {
|
||||||
const yesterday = a[i - 1] || [];
|
const yesterday = a[i - 1] || [];
|
||||||
return x[1] - (yesterday[1] || x[1]);
|
return x[1] - (yesterday[1] || x[1]);
|
||||||
}).slice(1).slice(-60);
|
}).slice(1).slice(-60);
|
||||||
@ -89,7 +92,6 @@ export default {
|
|||||||
ctx.fillStyle = client.config.embedColor;
|
ctx.fillStyle = client.config.embedColor;
|
||||||
ctx.lineWidth = 3;
|
ctx.lineWidth = 3;
|
||||||
|
|
||||||
|
|
||||||
function getYCoordinate(value: number) {
|
function getYCoordinate(value: number) {
|
||||||
return ((1 - (value / second_graph_top)) * graphSize[1]) + graphOrigin[1];
|
return ((1 - (value / second_graph_top)) * graphSize[1]) + graphOrigin[1];
|
||||||
}
|
}
|
||||||
@ -118,7 +120,6 @@ export default {
|
|||||||
ctx.fillStyle = 'white';
|
ctx.fillStyle = 'white';
|
||||||
|
|
||||||
// highest value
|
// highest value
|
||||||
//console.log(previousY)
|
|
||||||
const maxx = graphOrigin[0] + graphSize[0] + textSize;
|
const maxx = graphOrigin[0] + graphSize[0] + textSize;
|
||||||
const maxy = previousY[0] + (textSize / 3);
|
const maxy = previousY[0] + (textSize / 3);
|
||||||
ctx.fillText(previousY[1].toLocaleString('en-US'), maxx, maxy);
|
ctx.fillText(previousY[1].toLocaleString('en-US'), maxx, maxy);
|
||||||
@ -136,7 +137,7 @@ export default {
|
|||||||
const ty = graphOrigin[1] + graphSize[1] + (textSize);
|
const ty = graphOrigin[1] + graphSize[1] + (textSize);
|
||||||
ctx.fillText('time ->', tx, ty);
|
ctx.fillText('time ->', tx, ty);
|
||||||
|
|
||||||
const yeahok = new client.attachmentBuilder(img.toBuffer(), {name: "dailymsgs.png"})
|
const yeahok = new client.attachmentBuilder(img.toBuffer(), {name: 'dailymsgs.png'})
|
||||||
const embed = new client.embed()
|
const embed = new client.embed()
|
||||||
.setTitle('Ranking leaderboard')
|
.setTitle('Ranking leaderboard')
|
||||||
.setDescription(`Level System was created **${timeActive}** days ago. Since then, a total of **${messageCountsTotal.toLocaleString('en-US')}** messages have been sent in this server.`)
|
.setDescription(`Level System was created **${timeActive}** days ago. Since then, a total of **${messageCountsTotal.toLocaleString('en-US')}** messages have been sent in this server.`)
|
||||||
|
Loading…
Reference in New Issue
Block a user