1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-11-17 20:30:58 -05:00

Compare commits

..

2 Commits

Author SHA1 Message Date
Toast
128d38bc45
Merge 8b541cbed3 into 0d24519555 2024-02-18 04:29:24 +11:00
toast-ts
0d24519555 Update CanvasBuilder to use methods instead of functions 2024-02-17 18:58:34 +11:00
3 changed files with 9 additions and 15 deletions

View File

@ -1,7 +1,7 @@
import Discord from 'discord.js';
import TClient from '../client.js';
import Logger from '../helpers/Logger.js';
import CanvasBuilder from '../components/CanvasGraph.js';
import CanvasBuilder from '../components/CanvasBuilder.js';
import RanIntoHumor from '../helpers/RanIntoHumor.js';
import MessageTool from '../helpers/MessageTool.js';
import PalletLibrary from '../helpers/PalletLibrary.js';
@ -43,7 +43,7 @@ export default class MP {
if (!DSS) return console.log('Endpoint failed - players');
const PDArr = await client.MPServer.fetchPlayerData(choiceSelector);
const canvas = await new CanvasBuilder().generateGraph(PDArr.slice(-120), 'players');
const canvas = await CanvasBuilder.generateGraph(PDArr.slice(-120), 'players');
const players:string[] = [];
let embedColor:Discord.ColorResolvable;

View File

@ -3,7 +3,7 @@ import Discord from 'discord.js';
import TClient from '../client.js';
import Formatters from '../helpers/Formatters.js';
import MessageTool from '../helpers/MessageTool.js';
import CanvasBuilder from '../components/CanvasGraph.js';
import CanvasBuilder from '../components/CanvasBuilder.js';
export default class Rank {
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});
@ -32,7 +32,7 @@ export default class Rank {
});
if (data.length < 2) return interaction.reply('Not enough data to generate graph.');
const graph = await new CanvasBuilder().generateGraph(data, 'leaderboard');
const graph = await CanvasBuilder.generateGraph(data, 'leaderboard');
interaction.reply({
embeds: [new client.embed().setColor(client.config.embedColor).setTitle('Leaderboard')
.setDescription(MessageTool.concatMessage(

View File

@ -2,10 +2,10 @@ import {createCanvas, Canvas, SKRSContext2D} from '@napi-rs/canvas';
import {Config} from 'src/interfaces';
import ConfigHelper from '../helpers/ConfigHelper.js';
export default class CanvasBuilder {
private readonly canvas: Canvas;
private readonly ctx: SKRSContext2D;
private readonly config: Config;
private readonly palette = {
private static readonly canvas: Canvas = createCanvas(1500, 750);
private static readonly ctx: SKRSContext2D = this.canvas.getContext('2d');
private static readonly config: Config = ConfigHelper.readConfig();
private static 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.
oddHorizontal: '#555B63',
evenHorizontal: '#3E4245',
@ -16,13 +16,7 @@ export default class CanvasBuilder {
greenLine: '#57F287'
};
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> {
public static async generateGraph(data:number[], type:'players'|'leaderboard'):Promise<Canvas> {
// Handle negative
for (const [i, change] of data.entries()) if (change < 0) data[i] = data[i - 1] || data[i + 1] || 0;