Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Enmap = require("enmap")
- const clientx = new Enmap({ name: "profile" });
- client.on("message", async message => {
- if (message.author.bot || !message.guild) return;
- const key = `${message.author.id}`;
- if (!clientx.get(key)) {
- clientx.ensure(`${message.author.id}`, {
- user: message.author.id,
- xp: 0,
- level: 1
- });
- }
- let rxp = getRandom(100, 20);
- let authorx = clientx.get(key);
- clientx.set(key, Math.floor(authorx.xp + rxp), "xp");
- if (clientx.get(key, "xp") >= 10000) {
- clientx.set(key, Math.floor(authorx.level) + 1, "level");
- clientx.set(key, 0, "xp");
- }
- const args = message.content.slice(prefix.length).trim().split(/ +/g);
- const command = args.shift().toLowerCase();
- if (!message.content.startsWith(prefix)) return;
- if (command === "profile") {
- let user = message.mentions.users.first() || message.author;
- if (message.author.bot) return;
- if (clientx.get(`${user.id}`) === undefined) {
- clientx.ensure(`${user.id}`, {
- user: user.id,
- xp: 0,
- level: 1
- });
- }
- let canvas = Canvas.createCanvas(674, 1024);
- const applyname = (canvas, text) => {
- const ctx = canvas.getContext("2d");
- let fontSize = 45;
- do {
- ctx.font = `${(fontSize -= 10)}px Comic SANS`;
- } while(ctx.measureText(text).width > canvas.width - 354.736842105);
- return ctx.font;
- };
- const applylevel = (canvas, text) => {
- const ctx = canvas.getContext("2d");
- let fontSize = 45;
- do {
- ctx.font = `${(fontSize -= 10)}px Comic SANS`;
- } while (ctx.measureText(text).width > canvas.width - 530);
- return ctx.font;
- };
- const applyxp = (canvas, text) => {
- const ctx = canvas.getContext("2d");
- let fontSize = 30;
- do {
- ctx.font = `${(fontSize -= 10)}px Comic SANS`;
- } while (ctx.measureText(text).width > canvas.width - 346);
- return ctx.font;
- };
- let ctx = canvas.getContext("2d");
- const background = await Canvas.loadImage("https://cdn.discordapp.com/attachments/627894631153270818/659212680212643850/20191225_055539.png");
- ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
- ctx.fillStyle = "#000000";
- ctx.textAlign = "center";
- ctx.font = applyname(canvas, user.username);
- ctx.fillText(user.username, canvas.width / 1.9, canvas.height / 2);
- ctx.font = applylevel(canvas, clientx.get(user.id, "level"));
- ctx.fillText(clientx.get(user.id, "level"),530,780);
- ctx.font = applyxp(canvas, clientx.get(user.id, "xp"));
- ctx.fillStyle = "#ffffff";
- ctx.font = "23px Comic SANS";
- ctx.fillText(clientx.get(user.id, "xp") + " / 10000 xp",342,968);
- const avatar = await Canvas.loadImage(user.displayAvatarURL);
- ctx.beginPath();
- ctx.arc(340, 300, 150, 0, Math.PI * 2, true);
- ctx.closePath();
- ctx.clip();
- ctx.drawImage(avatar, 190, 150, 370, 370);
- const attachment = new Discord.Attachment(canvas.toBuffer());
- message.channel.send(attachment);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement