97 lines
3.2 KiB
JavaScript
97 lines
3.2 KiB
JavaScript
const { MessageAttachment } = require('discord.js');
|
|
const Canvas = require('canvas');
|
|
|
|
module.exports.run = async function(bot, message, args){
|
|
// Create a 700x250 pixel canvas and get its context
|
|
// The context will be used to modify the canvas
|
|
const canvas = Canvas.createCanvas(700, 250);
|
|
const context = canvas.getContext('2d');
|
|
const background = await Canvas.loadImage('./background.png');
|
|
const avatar = await Canvas.loadImage(message.author.displayAvatarURL({ format: 'jpg' }));
|
|
const progressWidth = 400;
|
|
let type = "image";
|
|
let xp = 300;
|
|
let max = 1500;
|
|
let perc = ((xp/max)*100)/100;
|
|
let prog = Math.floor(progressWidth*(perc-4));
|
|
let position;
|
|
let text;
|
|
let correction = 0;
|
|
|
|
if(type == "image") {
|
|
context.drawImage(background, 0, 0, canvas.width, canvas.height);
|
|
} else if(type === "solid") {
|
|
context.fillStyle = "#2d3436";
|
|
context.fillRect(0, 0, canvas.width, canvas.height);
|
|
}
|
|
|
|
// Set the color of the stroke
|
|
context.strokeStyle = '#0099ff';
|
|
|
|
// Select the font size and type from one of the natively available fonts
|
|
context.font = '40px sans-serif';
|
|
|
|
// Select the style that will be used to fill the text in
|
|
context.fillStyle = '#ffffff';
|
|
|
|
// Actually fill the text with a solid color
|
|
context.fillText(message.member.displayName, canvas.width / 2.5, canvas.height / 2);
|
|
// Select the font size and type from one of the natively available fonts
|
|
text = xp + "/" + max + "xp";
|
|
context.font = '25px sans-serif';
|
|
position = (canvas.width / 1.225);
|
|
|
|
// correcting level text overflow
|
|
if(canvas.width - ((canvas.width / 1.225) + context.measureText(text).width) <= 23){
|
|
correction = (canvas.width - ((canvas.width / 1.225) + context.measureText(text).width)) - 24;
|
|
}
|
|
|
|
context.fillText(text, position + correction, canvas.height / 2);
|
|
|
|
// rank banner
|
|
// Select the font size and type from one of the natively available fonts
|
|
context.font = '30px sans-serif';
|
|
position = (canvas.width / 1.225);
|
|
text = "Level 300";
|
|
correction = 0;
|
|
// correcting level text overflow
|
|
if(canvas.width - ((canvas.width / 1.225) + context.measureText(text).width) <= 23){
|
|
correction = (canvas.width - ((canvas.width / 1.225) + context.measureText(text).width)) - 24;
|
|
}
|
|
|
|
context.fillText(text, position + correction, canvas.height / 4);
|
|
|
|
// progressbar
|
|
context.fillStyle = '#636e72';
|
|
context.fillRect(canvas.width / 2.5, canvas.height / 1.8, progressWidth, 50);
|
|
context.moveTo(220, 200);
|
|
context.fillStyle = '#2d3436';
|
|
if(prog < 0) {prog = Math.floor(progressWidth*perc);}
|
|
context.fillRect(canvas.width / 2.5 + 2, (canvas.height / 1.8) + 3, prog, 44);
|
|
|
|
// Pick up the pen
|
|
context.beginPath();
|
|
|
|
// Start the arc to form a circle
|
|
context.arc(125, 125, 100, 0, Math.PI * 2, true);
|
|
|
|
// Put the pen down
|
|
context.closePath();
|
|
|
|
// Clip off the region you drew on
|
|
context.clip();
|
|
|
|
// Move the image downwards vertically and constrain its height to 200, so that it's square
|
|
context.drawImage(avatar, 25, 25, 200, 200);
|
|
|
|
// Use the helpful Attachment class structure to process the file for you
|
|
const attachment = new MessageAttachment(canvas.toBuffer(), 'profile-image.png');
|
|
|
|
message.channel.send({
|
|
files: [attachment],
|
|
});
|
|
}
|
|
|
|
module.exports.help = {
|
|
name: "stats"
|
|
} |