mirror of
https://github.com/toast-ts/Daggerbot-TS.git
synced 2024-11-18 00:31:00 -05:00
Compare commits
1 Commits
128d38bc45
...
d537e6d78d
Author | SHA1 | Date | |
---|---|---|---|
|
d537e6d78d |
@ -1,7 +1,7 @@
|
|||||||
import Discord from 'discord.js';
|
import Discord from 'discord.js';
|
||||||
import TClient from '../client.js';
|
import TClient from '../client.js';
|
||||||
import Logger from '../helpers/Logger.js';
|
import Logger from '../helpers/Logger.js';
|
||||||
import CanvasBuilder from '../components/CanvasBuilder.js';
|
import CanvasBuilder from '../components/CanvasGraph.js';
|
||||||
import RanIntoHumor from '../helpers/RanIntoHumor.js';
|
import RanIntoHumor from '../helpers/RanIntoHumor.js';
|
||||||
import MessageTool from '../helpers/MessageTool.js';
|
import MessageTool from '../helpers/MessageTool.js';
|
||||||
import PalletLibrary from '../helpers/PalletLibrary.js';
|
import PalletLibrary from '../helpers/PalletLibrary.js';
|
||||||
@ -43,7 +43,7 @@ export default class MP {
|
|||||||
if (!DSS) return console.log('Endpoint failed - players');
|
if (!DSS) return console.log('Endpoint failed - players');
|
||||||
|
|
||||||
const PDArr = await client.MPServer.fetchPlayerData(choiceSelector);
|
const PDArr = await client.MPServer.fetchPlayerData(choiceSelector);
|
||||||
const canvas = await CanvasBuilder.generateGraph(PDArr.slice(-120), 'players');
|
const canvas = await new CanvasBuilder().generateGraph(PDArr.slice(-120), 'players');
|
||||||
const players:string[] = [];
|
const players:string[] = [];
|
||||||
let embedColor:Discord.ColorResolvable;
|
let embedColor:Discord.ColorResolvable;
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import Discord from 'discord.js';
|
|||||||
import TClient from '../client.js';
|
import TClient from '../client.js';
|
||||||
import Formatters from '../helpers/Formatters.js';
|
import Formatters from '../helpers/Formatters.js';
|
||||||
import MessageTool from '../helpers/MessageTool.js';
|
import MessageTool from '../helpers/MessageTool.js';
|
||||||
import CanvasBuilder from '../components/CanvasBuilder.js';
|
import CanvasBuilder from '../components/CanvasGraph.js';
|
||||||
export default class Rank {
|
export default class Rank {
|
||||||
static async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
|
static async run(client: TClient, interaction: Discord.ChatInputCommandInteraction<'cached'>){
|
||||||
if (interaction.guildId !== client.config.dcServer.id) return interaction.reply({content: 'This command doesn\'t work in this server.', ephemeral: true});
|
if (interaction.guildId !== client.config.dcServer.id) return interaction.reply({content: 'This command doesn\'t work in this server.', ephemeral: true});
|
||||||
@ -32,7 +32,7 @@ export default class Rank {
|
|||||||
});
|
});
|
||||||
if (data.length < 2) return interaction.reply('Not enough data to generate graph.');
|
if (data.length < 2) return interaction.reply('Not enough data to generate graph.');
|
||||||
|
|
||||||
const graph = await CanvasBuilder.generateGraph(data, 'leaderboard');
|
const graph = await new CanvasBuilder().generateGraph(data, 'leaderboard');
|
||||||
interaction.reply({
|
interaction.reply({
|
||||||
embeds: [new client.embed().setColor(client.config.embedColor).setTitle('Leaderboard')
|
embeds: [new client.embed().setColor(client.config.embedColor).setTitle('Leaderboard')
|
||||||
.setDescription(MessageTool.concatMessage(
|
.setDescription(MessageTool.concatMessage(
|
||||||
|
@ -2,10 +2,10 @@ import {createCanvas, Canvas, SKRSContext2D} from '@napi-rs/canvas';
|
|||||||
import {Config} from 'src/interfaces';
|
import {Config} from 'src/interfaces';
|
||||||
import ConfigHelper from '../helpers/ConfigHelper.js';
|
import ConfigHelper from '../helpers/ConfigHelper.js';
|
||||||
export default class CanvasBuilder {
|
export default class CanvasBuilder {
|
||||||
private static readonly canvas: Canvas = createCanvas(1500, 750);
|
private readonly canvas: Canvas;
|
||||||
private static readonly ctx: SKRSContext2D = this.canvas.getContext('2d');
|
private readonly ctx: SKRSContext2D;
|
||||||
private static readonly config: Config = ConfigHelper.readConfig();
|
private readonly config: Config;
|
||||||
private static readonly palette = {
|
private readonly palette = {
|
||||||
// Color palette for the graph -- The variables are named exactly what it shows in graph to make it easier to be referenced to.
|
// Color palette for the graph -- The variables are named exactly what it shows in graph to make it easier to be referenced to.
|
||||||
oddHorizontal: '#555B63',
|
oddHorizontal: '#555B63',
|
||||||
evenHorizontal: '#3E4245',
|
evenHorizontal: '#3E4245',
|
||||||
@ -16,7 +16,13 @@ export default class CanvasBuilder {
|
|||||||
greenLine: '#57F287'
|
greenLine: '#57F287'
|
||||||
};
|
};
|
||||||
|
|
||||||
public static async generateGraph(data:number[], type:'players'|'leaderboard'):Promise<Canvas> {
|
constructor() {
|
||||||
|
this.canvas = createCanvas(1500, 750);
|
||||||
|
this.ctx = this.canvas.getContext('2d');
|
||||||
|
this.config = ConfigHelper.readConfig() as Config;
|
||||||
|
}
|
||||||
|
|
||||||
|
public async generateGraph(data:number[], type:'players'|'leaderboard'):Promise<Canvas> {
|
||||||
// Handle negative
|
// Handle negative
|
||||||
for (const [i, change] of data.entries()) if (change < 0) data[i] = data[i - 1] || data[i + 1] || 0;
|
for (const [i, change] of data.entries()) if (change < 0) data[i] = data[i - 1] || data[i + 1] || 0;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user