Guest User

TOP VOICE&TEXT

a guest
Mar 31st, 2020
72
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const top = JSON.parse(fs.readFileSync("top.json", "UTF8"));
  2.  
  3. function save() {
  4. fs.writeFileSync("./top.json", JSON.stringify(top, null, 4));
  5. }
  6. client.on("voiceStateUpdate", async function(oldMember, newMember) {
  7. if (newMember.user.bot) return;
  8. if (!top[newMember.guild.id]) top[newMember.guild.id] = {};
  9. if (!top[newMember.guild.id][newMember.user.id]) top[newMember.guild.id][newMember.user.id] = {
  10. "text": 0,
  11. "voice": parseInt(Math.random()*10),
  12. "msgs": 0,
  13. "id": newMember.user.id
  14. }
  15. save();
  16. if (!oldMember.voiceChannel && newMember.voiceChannel) {
  17. var addXP = setInterval(async function () {
  18. top[newMember.guild.id][newMember.user.id].voice+=parseInt(Math.random()*4);
  19. save();
  20. if (!newMember.voiceChannel) {
  21. clearInterval(addXP);
  22. }
  23. }, 60000);
  24. }
  25. });
  26. client.on("message", async function (message) {
  27. if (message.author.bot) return;
  28. if (!message.guild) return;
  29. if (!top[message.guild.id]) top[message.guild.id] = {};
  30. if (!top[message.guild.id][message.author.id]) top[message.guild.id][message.author.id] = {
  31. "text": parseInt(Math.random()*10),
  32. "voice": 1,
  33. "msgs": 0,
  34. "id": message.author.id
  35. }
  36. if (top[message.guild.id][message.author.id].msgs > 10) {
  37. top[message.guild.id][message.author.id].text += parseInt(Math.random()*4);
  38. top[message.guild.id][message.author.id].msgs = 0;
  39. }
  40. save();
  41. var args = message.content.split(" ");
  42. var cmd = args[0].toLowerCase();
  43. if (!message.content.startsWith(prefix)) return;
  44. if(message.content.startsWith(prefix + "top text")) {
  45. var topArray = Object.values(top[message.guild.id]);
  46. var num = 0;
  47. var textStr = `${topArray.sort((a, b) => b.text - a.text).slice(0, 10).filter(user => user.text > 0 && message.guild.members.get(user.id)).map(function (user) {
  48. if (user.text > 0) {
  49. return `**#${++num} | <@${user.id}> XP: ${user.text} **`
  50. }
  51. }).join("n")}`;
  52. var embed = new Discord.RichEmbed()
  53. .setAuthor("📋 | Guild Score Leaderboards", message.guild.iconURL)
  54. .setColor("13B813")
  55. .addField(`**:speech_balloon: | TEXT LEADERBOARD**`, `${textStr} **✨ | For More: ${prefix}top text**`, true)
  56. .setFooter(message.author.tag, message.author.displayAvatarURL)
  57. .setTimestamp()
  58. message.channel.send({
  59. embed: embed
  60. });
  61. } else {
  62. if(message.content.startsWith(prefix + "top voice")) {
  63. var topArray = Object.values(top[message.guild.id]);
  64. var num = 0;
  65. var voiceStr = `${topArray.sort((a, b) => b.voice - a.voice).slice(0, 10).filter(user => user.voice > 0 && message.guild.members.get(user.id)).map(function (user) {
  66. if (user.voice > 0) {
  67. return `**#${++num} | <@${user.id}> XP: ${user.voice}**`
  68. }
  69. }).join("n")}`;
  70. var embed = new Discord.RichEmbed()
  71. .setAuthor("📋 | Guild Score Leaderboards", message.guild.iconURL)
  72. .setColor("13B813")
  73. .addField(`**:microphone2: | VOICE LEADERBOARD**`, `${voiceStr} **:sparkles: More?** ${prefix}top voice`, true)
  74.  
  75. .setFooter(message.author.tag, message.author.displayAvatarURL)
  76. .setTimestamp()
  77. message.channel.send({
  78. embed: embed
  79. });
  80. } else {
  81. if(message.content.startsWith(prefix + "top")) {
  82. var topArray = Object.values(top[message.guild.id]);
  83. var num = 0;
  84. var textStr = `${topArray.sort((a, b) => b.text - a.text).slice(0, 5).filter(user => user.text > 0 && message.guild.members.get(user.id)).map(function (user) {
  85. if (user.text > 0) {
  86. return `**#${++num} | <@${user.id}> XP: ${user.text} **`
  87. }
  88. }).join("n")}`;
  89. num = 0;
  90. var voiceStr = `${topArray.sort((a, b) => b.voice - a.voice).slice(0, 5).filter(user => user.voice > 0 && message.guild.members.get(user.id)).map(function (user) {
  91. if (user.voice > 0) {
  92. return `**#${++num} | <@${user.id}> XP: ${user.voice} **`
  93. }
  94. }).join("n")}`;
  95. var embed = new Discord.RichEmbed()
  96. .setAuthor("📋 | Guild Score Leaderboards", message.guild.iconURL)
  97. .addField("**TOP 5 TEXT :speech_balloon:**", `${textStr} **:sparkles: More?** ${prefix}top text`, true)
  98. .addField("**TOP 5 VOICE :microphone2:**", `${voiceStr} **:sparkles: More?** ${prefix}top voice`, true)
  99. .setFooter(message.author.tag, message.author.displayAvatarURL)
  100. .setTimestamp()
  101. .setColor("13B813");
  102. message.channel.send({
  103. embed: embed
  104.  
  105.  
  106. });
  107. }
  108. }
  109. }
  110. });
RAW Paste Data