1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-09-29 08:20:59 -04:00

Drop-in replacement for Canvas

This commit is contained in:
toast-ts 2024-02-09 22:27:08 +11:00
parent 635a22998f
commit f427b81cbb
6 changed files with 200 additions and 2520 deletions

1422
.pnp.cjs generated

File diff suppressed because it is too large Load Diff

View File

@ -32,10 +32,10 @@
"engineStrict": true, "engineStrict": true,
"packageManager": "yarn@4.1.0+sha256.81a00df816059803e6b5148acf03ce313cad36b7f6e5af6efa040a15981a6ffb", "packageManager": "yarn@4.1.0+sha256.81a00df816059803e6b5148acf03ce313cad36b7f6e5af6efa040a15981a6ffb",
"dependencies": { "dependencies": {
"@napi-rs/canvas": "0.1.45",
"@octokit/rest": "20.0.2", "@octokit/rest": "20.0.2",
"@toast/tokenservice-client": "1.0.11", "@toast/tokenservice-client": "1.0.11",
"ansi-colors": "4.1.3", "ansi-colors": "4.1.3",
"canvas": "2.11.2",
"dayjs": "1.11.10", "dayjs": "1.11.10",
"discord.js": "14.14.1", "discord.js": "14.14.1",
"fast-xml-parser": "4.3.4", "fast-xml-parser": "4.3.4",

View File

@ -62,7 +62,7 @@ export default class MP {
.setImage(`attachment://${attachmentName}`) .setImage(`attachment://${attachmentName}`)
.setAuthor({name: `${DSS.slots.used}/${DSS.slots.capacity}`}) .setAuthor({name: `${DSS.slots.used}/${DSS.slots.capacity}`})
.setFooter({text: `Current time: ${('0'+Math.floor((DSS?.server.dayTime/3600/1000))).slice(-2)}:${('0'+Math.floor((DSS?.server.dayTime/60/1000)%60)).slice(-2)}`}) .setFooter({text: `Current time: ${('0'+Math.floor((DSS?.server.dayTime/3600/1000))).slice(-2)}:${('0'+Math.floor((DSS?.server.dayTime/60/1000)%60)).slice(-2)}`})
], files: [new client.attachment(canvas.toBuffer(), {name: attachmentName})]}) ], files: [new client.attachment(canvas.toBuffer('image/jpeg'), {name: attachmentName})]})
}, },
details: async()=>{ details: async()=>{
const DSS = await fetchData(client, interaction, choiceSelector) as FSData; const DSS = await fetchData(client, interaction, choiceSelector) as FSData;

View File

@ -42,7 +42,7 @@ export default class Rank {
name: 'Top users sorted by messages sent:', name: 'Top users sorted by messages sent:',
value: allData.sort((a,b)=>b.messages - a.messages).slice(0,15).map((x,i)=>`${i+1}. <@${x.dataValues.id}>: ${x.messages.toLocaleString('en-US')}`).join('\n') value: allData.sort((a,b)=>b.messages - a.messages).slice(0,15).map((x,i)=>`${i+1}. <@${x.dataValues.id}>: ${x.messages.toLocaleString('en-US')}`).join('\n')
}).setImage('attachment://dailyMessages.jpg').setFooter({text: 'Graph updates daily'})], }).setImage('attachment://dailyMessages.jpg').setFooter({text: 'Graph updates daily'})],
files: [new client.attachment(graph.toBuffer(), {name: 'dailyMessages.jpg'})] files: [new client.attachment(graph.toBuffer('image/jpeg'), {name: 'dailyMessages.jpg'})]
}) })
}, },
notification: async()=>{ notification: async()=>{

View File

@ -1,9 +1,9 @@
import {createCanvas, Canvas, CanvasRenderingContext2D} from 'canvas'; 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 readonly canvas: Canvas; private readonly canvas: Canvas;
private readonly ctx: CanvasRenderingContext2D; private readonly ctx: SKRSContext2D;
private readonly config: Config; private readonly config: Config;
private 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.
@ -119,7 +119,7 @@ export default class CanvasBuilder {
} }
// Draw text // Draw text
this.ctx.font = '400 ' + textSize + 'px sans-serif'; this.ctx.font = `400 ${textSize}px Ubuntu`;
this.ctx.fillStyle = this.palette.textColor; this.ctx.fillStyle = this.palette.textColor;
// Highest value // Highest value

1286
yarn.lock

File diff suppressed because it is too large Load Diff