Advertisement
Ayoub-toxic

profile with level system

Jan 12th, 2020
295
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Enmap = require("enmap")
  2. const clientx = new Enmap({ name: "profile" });
  3. client.on("message", async message => {
  4.   if (message.author.bot || !message.guild) return;
  5.   const key = `${message.author.id}`;
  6.   if (!clientx.get(key)) {
  7.     clientx.ensure(`${message.author.id}`, {
  8.       user: message.author.id,
  9.       xp: 0,
  10.       level: 1
  11.     });
  12.   }
  13.   let rxp = getRandom(100, 20);
  14.   let authorx = clientx.get(key);
  15.   clientx.set(key, Math.floor(authorx.xp + rxp), "xp");
  16.   if (clientx.get(key, "xp") >= 10000) {
  17.     clientx.set(key, Math.floor(authorx.level) + 1, "level");
  18.     clientx.set(key, 0, "xp");
  19.   }
  20.   const args = message.content.slice(prefix.length).trim().split(/ +/g);
  21.   const command = args.shift().toLowerCase();
  22.   if (!message.content.startsWith(prefix)) return;
  23.   if (command === "profile") {
  24.     let user = message.mentions.users.first() || message.author;
  25.     if (message.author.bot) return;
  26.     if (clientx.get(`${user.id}`) === undefined) {
  27.         clientx.ensure(`${user.id}`, {
  28.         user: user.id,
  29.         xp: 0,
  30.         level: 1
  31.       });
  32.     }
  33.     let canvas = Canvas.createCanvas(674, 1024);
  34.     const applyname = (canvas, text) => {
  35.       const ctx = canvas.getContext("2d");
  36.       let fontSize = 45;
  37.       do {
  38.         ctx.font = `${(fontSize -= 10)}px Comic SANS`;
  39.       } while(ctx.measureText(text).width > canvas.width - 354.736842105);
  40.       return ctx.font;
  41.     };
  42.     const applylevel = (canvas, text) => {
  43.       const ctx = canvas.getContext("2d");
  44.       let fontSize = 45;
  45.       do {
  46.         ctx.font = `${(fontSize -= 10)}px Comic SANS`;
  47.       } while (ctx.measureText(text).width > canvas.width - 530);
  48.       return ctx.font;
  49.     };
  50.     const applyxp = (canvas, text) => {
  51.       const ctx = canvas.getContext("2d");
  52.       let fontSize = 30;
  53.       do {
  54.         ctx.font = `${(fontSize -= 10)}px Comic SANS`;
  55.       } while (ctx.measureText(text).width > canvas.width - 346);
  56.       return ctx.font;
  57.     };
  58.     let ctx = canvas.getContext("2d");
  59.     const background = await Canvas.loadImage("https://cdn.discordapp.com/attachments/627894631153270818/659212680212643850/20191225_055539.png");
  60.     ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
  61.     ctx.fillStyle = "#000000";
  62.     ctx.textAlign = "center";
  63.     ctx.font = applyname(canvas, user.username);
  64.     ctx.fillText(user.username, canvas.width / 1.9, canvas.height / 2);
  65.     ctx.font = applylevel(canvas, clientx.get(user.id, "level"));
  66.     ctx.fillText(clientx.get(user.id, "level"),530,780);
  67.     ctx.font = applyxp(canvas, clientx.get(user.id, "xp"));
  68.     ctx.fillStyle = "#ffffff";
  69.     ctx.font = "23px Comic SANS";
  70.     ctx.fillText(clientx.get(user.id, "xp") + " / 10000 xp",342,968);
  71.     const avatar = await Canvas.loadImage(user.displayAvatarURL);
  72.     ctx.beginPath();
  73.     ctx.arc(340, 300, 150, 0, Math.PI * 2, true);
  74.     ctx.closePath();
  75.     ctx.clip();
  76.     ctx.drawImage(avatar, 190, 150, 370, 370);
  77.     const attachment = new Discord.Attachment(canvas.toBuffer());
  78.     message.channel.send(attachment);
  79.   }
  80. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement