Guest User

Untitled

a guest
Sep 22nd, 2019
95
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const { Canvas } = require('canvas-constructor');
  2. const { Attachment } = require('discord.js');
  3. const { resolve, join } = require('path');
  4. const fetch = require('node-fetch');
  5.  
  6. const imageUrlRegex = /\?size=2048$/g;
  7. const placeholder = new Map();
  8.  
  9.  
  10. module.exports = {
  11. config: {
  12. name: "level",
  13. description: "Check your level",
  14. usage: ".",
  15. category: "miscellaneous",
  16. accessableby: "Everyone",
  17. aliases: []
  18. },
  19. run: async (bot, message, args) => {
  20. let xp = require("../../xp.json")
  21. let User = message.guild.member(message.mentions.users.first()) || message.guild.members.get(args[0]) || message.author
  22. let curxp = xp[User.id].xp;
  23. let curlvl = xp[User.id].level;
  24. let nxtLvlXp = curlvl * 300;
  25. let difference = nxtLvlXp - curxp;
  26. const key = `${message.guild.id}-${User.id}`;
  27.  
  28. try {
  29. if (!placeholder.has(key)) {
  30. placeholder.set(key, {
  31. user: User.id, guild: message.guild.id, points: 500, level: 17
  32. });
  33. }
  34.  
  35. const buffer = await profile(message, placeholder.get(key));
  36. const filename = `profile-${User.id}.jpg`;
  37. const attachment = new Attachment(buffer, filename);
  38. await message.channel.send(attachment);
  39.  
  40. } catch (error) {
  41. client.logger.error(error.stack);
  42. return message.channel.send(`An error ocurred: **${error.message}**`);
  43. }
  44.  
  45.  
  46. async function profile(message, score) {
  47. const key = `${message.guild.id}-${message.author.id}`;
  48. const member = message.member;
  49. const { level, points } = placeholder.get(key);
  50.  
  51. try {
  52. const result = await fetch(member.user.displayAvatarURL.replace(imageUrlRegex, '?size=128'));
  53. if (!result.ok) throw new Error('Failed to get the avatar!');
  54. const avatar = await result.buffer();
  55.  
  56. const name = member.displayName.length > 30 ? member.displayName.substring(0, 17) + '...'
  57. : member.displayName;
  58.  
  59. return new Canvas(400, 180)
  60. .setColor('#7289DA')
  61. .addRect(84, 0, 316, 180)
  62. .setColor("#2C2F33")
  63. .addRect(0, 0, 84, 180)
  64. .addRect(169, 26, 231, 46)
  65. .addRect(224, 108, 176, 46)
  66. .setShadowColor('rgba(22, 22, 22, 1)')
  67. .setShadowOffsetY(5)
  68. .setShadowBlur(10)
  69. .addCircle(84, 90, 62)
  70. .addCircularImage(avatar, 85, 90, 64)
  71. .save()
  72. .createBeveledClip(20, 138, 128, 32, 5)
  73. .setColor('#23272A')
  74. .fill()
  75. .restore()
  76. .setTextAlign('center')
  77. .setTextFont('18pt Klavika Regular')
  78. .setColor('#FFFFFF')
  79. .addText(name, 285, 57)
  80. .addText(`Level: ${curlvl}`, 80, 161)
  81. .setTextAlign('left')
  82. .addText(`XP: ${curxp}`, 235, 140)
  83. .toBuffer();
  84. } catch (error) {
  85. await message.channel.send(`An error occurred: **${error.message}**`);
  86. }
  87. }
  88. }
  89. }
RAW Paste Data