Wizardsofdra

Untitled

Feb 28th, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.02 KB | None | 0 0
  1. 'use strict';
  2. const http = require("http");
  3.  
  4. function getData(link, callback, https) {
  5. http.get(link, function(res) {
  6. var data = '';
  7. res.on('data', function(part) {
  8. data += part;
  9. });
  10. res.on('end', function(end) {
  11. callback(data);
  12. });
  13. });
  14. }
  15.  
  16. exports.commands = {
  17. seen: function(target, room, user) {
  18. if(!target) return this.parse("/help seen");
  19. this.can("set");
  20. target = toId(target);
  21. let lastSeen = Db("seen").get(target, null);
  22. if (!lastSeen) return this.send("**" + target + "** was never seen before.");
  23. let seenRoom = Db("settings").get([toId(lastSeen[1], true), "isPrivate"], false) && ((!user.isDev() && !user.isStaff) || room) ? "a private room" : lastSeen[1];
  24. this.send("**" + target + "** was last seen " + Tools.getTimeAgo(lastSeen[0]) + " ago in " + seenRoom + ".");
  25. },
  26. rcmd: function(command) {
  27. if (command.indexOf("/") === 0 || command.indexOf("!") === 0) {
  28. this.can("say")
  29. this.send(command)
  30. }
  31. else {
  32. this.can("say")
  33. this.send("This text is not a command.")
  34. }
  35. },
  36. dank: function(howdank) {
  37. if (!(howdank > 1)) {
  38. for (var i = 0; i < howdank; i++) {
  39. this.can("say");
  40. this.send("Dankness levels are at an all time high");
  41. }
  42. }
  43. else {
  44. this.can("say")
  45. this.send("The amount of dankness you entered is too high. (Caps at one)")
  46. }
  47. },
  48. uptime: function(target, room, user) {
  49. this.can("set");
  50. let startTime = Date.now() - (process.uptime() * 1000);
  51. this.send("The bot's uptime is: " + Tools.getTimeAgo(startTime));
  52. },
  53. help: function(target, room, user) {
  54. if (!target) return this.parse("/guide");
  55. target = target.toLowerCase();
  56. this.can("say");
  57. if (!Tools.helpEntries[target]) return false;
  58. Tools.helpEntries[target].forEach(function(e) {
  59. this.send(e.replace(/^\//i, room ? room.commandCharacter[0] : Config.defaultCharacter));
  60. }.bind(this));
  61. },
  62. intro: function() {
  63. this.can("say")
  64. this.send("Hi! I'm " + Monitor.username + " ,and I'm Wizardsofdra's mecha/bot/machine. You can request any changes made to me and my owner will consider it");
  65. this.send("Have a good day!")
  66. },
  67. guide: function(target, room, user) {
  68. this.can("set");
  69. let useCommandCharacter = room ? room.commandCharacter[0] : Config.defaultCharacter[0];
  70. let hastebin = Object.keys(Tools.helpEntries).sort().map(function(entry) {
  71. return Tools.helpEntries[entry].join("\n").replace(/^\//i, useCommandCharacter).replace(/\n\//i, useCommandCharacter);
  72. }.bind(this)).join("\n\n");
  73. Tools.uploadToHastebin("Bot Commands: \n\n" + hastebin, function(link) {
  74. this.send("Bot Guide: " + link);
  75. }.bind(this));
  76. },
  77. git: function(target, room, user) {
  78. this.can("set");
  79. this.send("I'm sorry, I don't currently have a GitHub repo...");
  80. },
  81. owner: function() {
  82. this.can("say");
  83. this.send("My owner is ~Wizardsofdra");
  84. this.can("set");
  85. },
  86. usage: function(target, room, user) {
  87. let baseLink = "http://www.smogon.com/stats/2016-01/";
  88. if (!target) return this.send(baseLink);
  89.  
  90. //get stats
  91. let parts = target.split(",");
  92.  
  93. if (!Tools.Formats[toId(parts[0])]) return this.send("Invalid Pokémon.");
  94.  
  95. let tier = toId(parts[1]) || toId(Tools.Formats[toId(parts[0])].tier).replace("nfe", "pu");
  96. let mon = toId(parts[0]);
  97.  
  98. if (!mon || !tier) return this.parse("/help usage");
  99.  
  100. let self = this;
  101.  
  102. function parseUsageData(data) {
  103. let monData;
  104. let placement = {};
  105. for (let tMon in data) {
  106. if (toId(tMon) === mon) {
  107. monData = {
  108. "name": tMon,
  109. "data": data[tMon]
  110. };
  111. }
  112. placement[toId(tMon)] = data[tMon].usage;
  113. }
  114. if (!monData) return self.send("Invalid Pokémon.");
  115. monData.placement = Object.keys(placement).sort(function(a, b) {
  116. if (placement[a] > placement[b]) return -1;
  117. return 1;
  118. }).indexOf(mon) + 1;
  119. self.send(monData.name + " - #" + monData.placement + " in " + tier.toUpperCase() + " | Usage: " + monData.data.usage * 100 + "% | Raw Count: " + monData.data["Raw count"] + ".");
  120. }
  121.  
  122. getData(baseLink + "chaos/" + tier + "-1500.json", function(data) {
  123. try {
  124. data = JSON.parse(data).data;
  125. }
  126. catch (e) {
  127. return this.send("Unable to parse JSON data/Invalid tier.");
  128. }
  129. parseUsageData(data);
  130. }.bind(this));
  131. }
  132. };
Advertisement
Add Comment
Please, Sign In to add comment