MrMcShroom

Untitled

Feb 7th, 2018
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.83 KB | None | 0 0
  1. const request = require('request');
  2. const Discord = require("discord.js");
  3. const config = require('../config.json');
  4. const sql = require("sqlite");
  5. sql.open("./db/data.sqlite");
  6.  
  7.  
  8.  
  9. async function rankcolor(data) {
  10. if (data.chat_admin === "1") {
  11. return "0xFF0000";
  12. } else if (data.chat_moderator === "2") {
  13. return "0x3498DB";
  14. } else if (data.chat_moderator === "1") {
  15. return "0x00F5FF";
  16. } else if (data.multiplayer_moderator === "1") {
  17. return "0x26FF00";
  18. } else {
  19. return sql.get(`SELECT * FROM pb2 WHERE pb2login ="${data.login}" AND discordid IS NOT NULL`).then(row => {
  20. if (!row) return "0xE67E22";
  21. return "0xF1C40F";
  22. });
  23. }
  24. }
  25.  
  26.  
  27. function blank(value) {
  28. if (value) {
  29. return value;
  30. } else {
  31. return "None";
  32. }
  33. }
  34.  
  35. function profilepicture(data) {
  36. var number = ("0000" + data.mdl).slice(-4);
  37. if (data.mdl >= 41 && data.mdl <= 49) {
  38. var chicken = data.mdl - 40;
  39. var number = ("0000" + chicken).slice(-4);
  40. return "http://mcshroom.com/pb2characters/pb2characters/chars_hero" + number + ".jpg";
  41. } else if (data.mdl === 61) {
  42. return "http://mcshroom.com/pb2characters/pb2characters/chars_proxy.jpg";
  43. } else {
  44. return "http://mcshroom.com/pb2characters/pb2characters/chars" + number + ".jpg";
  45. }
  46. }
  47.  
  48.  
  49.  
  50. exports.run = (client, message, args) => {
  51. var colors = ["0x67037b","0xff2492","0x1e90ff","0xc71585","0x7fff00","0xdc143c","0x48d1cc","0x9932cc"]
  52. var embed = new Discord.RichEmbed();
  53. embed.setTitle("Loading the requested stats!")
  54. .setDescription("Be patient, the PB2 API is working hard :)")
  55. .setColor(colors[Math.floor(Math.random() * colors.length)])
  56. .setThumbnail("https://i.imgur.com/aHtisOM.jpg")
  57. .setFooter("Loading stats with love from the PB2 API.", message.client.user.avatarURL)
  58. async function rank(data) {
  59. if (data.chat_admin === "1") {
  60. return "Admin";
  61. } else if (data.chat_moderator === "2") {
  62. return "Head Moderator";
  63. } else if (data.chat_moderator === "1") {
  64. return "Moderator";
  65. } else if (data.multiplayer_moderator === "1") { // ?????
  66. return "Trial Staff / Site Support";
  67. } else {
  68. return sql.get(`SELECT * FROM pb2 WHERE pb2login ="${data.login}" AND discordid IS NOT NULL`).then(row => {
  69. console.log(row)
  70. if (!row) return "Not Verified on Discord";
  71. if(message.client.guilds.get("328650645793931267").member(row.discordid) && message.client.guilds.get("328650645793931267").member(row.discordid).roles.exists("name", "Creator")) {
  72. return "Contributor";
  73. } else {
  74. return "Verified Discord User"
  75. }
  76.  
  77. });
  78. }
  79. }
  80. async function pb2data(e, res, olddata) {
  81. message.channel.send({embed:embed}).then((oldembed) => {
  82. // If there is no error
  83. if (!e) {
  84. // If there is a response and a response code of 200 (that's a good thing)
  85. if (res && res.statusCode === 200) {
  86. // Whatever you want to do with your data goes in here. Just console logging it for the purpose of the example.
  87. let data = JSON.parse(olddata); //This will make it so your code makes the data from PB2 readable and usable!
  88. if (data.Error === "User not found") {
  89. message.channel.send("This user didn't exist! `!pb2 login name`");
  90. } else {
  91. var kdr = data.s_kills / data.s_deaths;
  92. var loginurlformat = data.login;
  93. loginurlformat = loginurlformat.replace(/\s/g, '%20');
  94. let prank = await rank(data);
  95. let prankcolor = await rankcolor(data);
  96. var creationdate = new Date(data.real_register * 1000);
  97. var embed = new Discord.RichEmbed()
  98. .setDescription(data.nickname + "'s PB2 Profile")
  99. .addField("Slogan", blank(data.slogan))
  100. .addField("Country", blank(data.country_code), true)
  101. .addField("Gender", blank(data.gender), true)
  102. .addField("Birthday", blank(data.birth), true)
  103. .addField("Kills", blank(data.s_kills), true)
  104. .addField("Deaths", blank(data.s_deaths), true)
  105. .addField("PPP", blank(data.player_rank), true)
  106. .addField("LDR", blank(data.dev_rank), true)
  107. .addField("KDR", kdr.toFixed(2), true)
  108. .addField("Rank", prank)
  109. .addField("Skype", blank(data.skype), true)
  110. .addField("Discord", blank(data.icq), true)
  111. .addField("XMPP", blank(data.xmpp), true)
  112. .addField("Earliest action on account", creationdate, true)
  113. .addField("Profile Link", 'http://plazmaburst2.com/?a=&s=7&ac=' + loginurlformat + '&id=' + data.uid, true)
  114. .setThumbnail(profilepicture(data))
  115. .setColor(prankcolor)
  116. .setFooter("Pulled with love from the Plazma Burst 2 API by " + config.botname);
  117. sql.get(`SELECT * FROM pb2 WHERE pb2login ="${data.login}" AND discordid IS NOT NULL`).then(row => {
  118. if (!row) return oldembed.edit(embed)
  119. client.fetchUser(row.discordid).then(discorduser => {
  120. embed.setAuthor(discorduser.tag, discorduser.avatarURL);
  121. oldembed.edit(newembed)
  122. });
  123. });
  124. }
  125. } else {
  126. // No response or wasn't a successful request (not code 200), so log it to the console
  127. console.error("Response error: " + res.toString());
  128. }
  129. } else {
  130. // There was some other error
  131. console.error("Error: " + e.toString())
  132. }
  133. });
  134. }
  135. if (message.mentions.users.first()) {
  136. sql.get(`SELECT * FROM pb2 WHERE discordid ="${message.mentions.users.first().id}"`).then(row => {
  137. if (!row) return message.reply("This user has not linked their PB2 account!");
  138. let username = row.pb2login;
  139. username = username.replace(" ", "%20");
  140. request.get("https://www.plazmaburst2.com/extract.php?login=" + username, pb2data);
  141. console.log("Displaying " + username + "'s PB2 profile through a discord mention.");
  142. });
  143. }
  144. else if (!args[0]) {
  145. sql.get(`SELECT * FROM pb2 WHERE discordid ="${message.author.id}"`).then(row => {
  146. if (!row) return message.reply("If you want to pull your own stats by not supplying a user, you need to link your discord! `!pb2verify`");
  147. let username = row.pb2login;
  148. username = username.replace(" ", "%20");
  149. request.get("https://www.plazmaburst2.com/extract.php?login=" + username, pb2data);
  150. console.log("Displaying " + username + "'s PB2 profile through a discord mention.");
  151. });
  152. }
  153. else {
  154. let username = args.join("%20"); //This is a variable that will take the first string in array named args, and make it my login name
  155. request.get("https://www.plazmaburst2.com/extract.php?login=" + username, pb2data);
  156. console.log("Displaying " + username + "'s PB2 profile without a discord mention.");
  157. }
  158. }
Advertisement
Add Comment
Please, Sign In to add comment