Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.16 KB | None | 0 0
  1. 'use strict';
  2.  
  3. let moment = require('moment');
  4. let request = require('request');
  5. let fs = require("fs");
  6. let color = ['blue', 'red', 'green', 'orange'];
  7. let suggestions = 'config/db/suggestions.json';
  8. let suggestionsCache;
  9. try {
  10. suggestionsCache = JSON.parse(fs.readFileSync(suggestions, 'utf8'));
  11. }
  12. catch (e) {
  13. suggestionsCache = {};
  14. }
  15.  
  16. exports.commands = {
  17. fj: 'forcejoin',
  18. forcejoin: function (target, room, user) {
  19. if (!user.can('mute')) return false;
  20. if (!target) return this.sendReply('/forcejoin [target], [room] - Forces a user to join a room');
  21. let parts = target.split(',');
  22. if (!parts[0] || !parts[1]) return this.sendReply('/forcejoin [target], [room] - Forces a user to join a room');
  23. let userid = toId(parts[0]);
  24. let roomid = toId(parts[1]);
  25. if (!Users.get(userid)) return this.sendReply ('User not found.');
  26. if (!Rooms.get(roomid)) return this.sendReply ('Room not found.');
  27. Users.get(userid).joinRoom(roomid);
  28. },
  29. roomlist: function (target, room, user) {
  30. if(!this.can('pban')) return;
  31. var totalUsers = 0;
  32. for (var u of Users.users) {
  33. u = u[1];
  34. if (Users(u).connected) {
  35. totalUsers++;
  36. }
  37.  
  38. }
  39. var rooms = Object.keys(Rooms.rooms),
  40. len = rooms.length,
  41. header = ['<b><font color="#DA9D01" size="2">Total users connected: ' + totalUsers + '</font></b><br />'],
  42. official = ['<b><font color="#1a5e00" size="2">Official chat rooms:</font></b><br />'],
  43. nonOfficial = ['<hr><b><font color="#000b5e" size="2">Public chat rooms:</font></b><br />'],
  44. privateRoom = ['<hr><b><font color="#ff5cb6" size="2">Private chat rooms:</font></b><br />'],
  45. groupChats = ['<hr><b><font color="#740B53" size="2">Group Chats:</font></b><br />'],
  46. battleRooms = ['<hr><b><font color="#0191C6" size="2">Battle Rooms:</font></b><br />'];
  47. while (len--) {
  48. var _room = Rooms.rooms[rooms[(rooms.length - len) - 1]];
  49. if (_room.type === 'battle') {
  50. battleRooms.push('<a href="/' + _room.id + '" class="ilink">' + _room.title + '</a> (' + _room.userCount + ')');
  51. }
  52. if (_room.type === 'chat') {
  53. if (_room.isPersonal) {
  54. groupChats.push('<a href="/' + _room.id + '" class="ilink">' + _room.id + '</a> (' + _room.userCount + ')');
  55. continue;
  56. }
  57. if (_room.isOfficial) {
  58. official.push('<a href="/' + toId(_room.title) + '" class="ilink">' + _room.title + '</a> (' + _room.userCount + ')');
  59. continue;
  60. }
  61. if (_room.isPrivate) {
  62. privateRoom.push('<a href="/' + toId(_room.title) + '" class="ilink">' + _room.title + '</a> (' + _room.userCount + ')');
  63. continue;
  64. }
  65. }
  66. if (_room.type !== 'battle' && _room.id !== 'global') nonOfficial.push('<a href="/' + toId(_room.title) + '" class="ilink">' + _room.title + '</a> (' + _room.userCount + ')');
  67. }
  68. this.sendReplyBox(header + official.join(' ') + nonOfficial.join(' ') + privateRoom.join(' ') + (groupChats.length > 1 ? groupChats.join(' ') : '') + (battleRooms.length > 1 ? battleRooms.join(' ') : ''));
  69. },
  70. cgdeclare: 'customgdeclare',
  71. customgdeclare: function (target, room, user) {
  72. let parts = target.split(',');
  73. if (!target) return this.parse('/help customgdeclare');
  74. if (!parts[4]) return this.parse('/help customgdeclare');
  75. if (!this.can('gdeclare')) return false;
  76.  
  77. for (let id in Rooms.rooms) {
  78. if (id !== 'global') Rooms.rooms[id].addRaw('<div class="broadcast-blue" style="border-radius: 5px;"><b>We are hosting a <font color="#57194A"><b>' + parts[0] + '</b></font> in <button name="send" value="/join ' + parts[1] + '" style="border-radius: 3px; margin: 3px; padding: 2px 5px; font-weight: bold; font-style: italic; box-shadow: 0px 0px 2px rgba(0, 0, 0, 0.35); color: #57194A; text-shadow: none;">' + parts[1] + '</button> !<br />The tier is <font style="color: #57194A; font-weight: bold;"><b>' + parts[2] + '</b></font>! Join up and have fun!<br /><br />The prize for the winner is <font style="color: #57194A; font-weight: bold;"><b>' + parts[3] + '</b></font> bucks, while the runner-up will get <font style="color: #57194A; font-weight: bold;"><b>' + parts[4] + '</b></font> bucks!<br /><small><i>~' + user.name + '</i></small></b></div>');
  79. }
  80. this.logModCommand(user.name + " globally custom declared " + target);
  81. },
  82. customgdeclarehelp: ["/customgdeclare [event name], [room], [tier], [buck reward], [runner-up buck reward] - Preset gdeclare which anonymously announces a message to every room on the server. Requires: &, ~"],
  83.  
  84. stafflist: 'authority',
  85. auth: 'authority',
  86. authlist: 'authority',
  87. authority: function (target, room, user, connection) {
  88. let rankLists = {};
  89. let ranks = Object.keys(Config.groups);
  90. for (let u in Users.usergroups) {
  91. let rank = Users.usergroups[u].charAt(0);
  92. // In case the usergroups.csv file is not proper, we check for the server ranks.
  93. if (ranks.indexOf(rank) > -1) {
  94. let name = Users.usergroups[u].substr(1);
  95. if (!rankLists[rank]) rankLists[rank] = [];
  96. if (name) rankLists[rank].push(((Users.getExact(name) && Users.getExact(name).connected) ? '**' + name + '**' : name));
  97. }
  98. }
  99.  
  100. let buffer = [];
  101. Object.keys(rankLists).sort(function (a, b) {
  102. return (Config.groups[b] || {rank: 0}).rank - (Config.groups[a] || {rank: 0}).rank;
  103. }).forEach(function (r) {
  104. buffer.push((Config.groups[r] ? r + Config.groups[r].name + "s (" + rankLists[r].length + ")" : r) + ":\n" + rankLists[r].sort().join(", "));
  105. });
  106.  
  107. if (!buffer.length) {
  108. return connection.popup("This server has no auth.");
  109. }
  110. connection.popup(buffer.join("\n\n"));
  111. },
  112.  
  113. clearall: function (target, room, user) {
  114. if (!this.can('declare')) return false;
  115. if (room.battle) return this.sendReply("You cannot clearall in battle rooms.");
  116.  
  117. Ultra.clearRoom(room);
  118. },
  119.  
  120. gclearall: 'globalclearall',
  121. globalclearall: function (target, room, user) {
  122. if (!this.can('gdeclare')) return false;
  123.  
  124. for (let u in Users.users) {
  125. Users.users[u].popup("All rooms are being clear.");
  126. }
  127.  
  128. for (let r in Rooms.rooms) {
  129. Ultra.clearRoom(Rooms.rooms[r]);
  130. }
  131. },
  132.  
  133. hide: function (target, room, user) {
  134. if (!this.can('lock')) return false;
  135. user.hiding = true;
  136. user.updateIdentity();
  137. this.sendReply("You have hidden your staff symbol.");
  138. },
  139.  
  140. show: function (target, room, user) {
  141. if (!this.can('lock')) return false;
  142. user.hiding = false;
  143. user.updateIdentity();
  144. this.sendReply("You have revealed your staff symbol.");
  145. },
  146.  
  147. rk: 'kick',
  148. roomkick: 'kick',
  149. kick: function (target, room, user) {
  150. if (!target) return this.parse('/help kick');
  151. if (!this.canTalk() && !user.can('bypassall')) {
  152. return this.sendReply("You cannot do this while unable to talk.");
  153. }
  154.  
  155. target = this.splitTarget(target);
  156. let targetUser = this.targetUser;
  157. if (!targetUser || !targetUser.connected) return this.sendReply("User \"" + this.targetUsername + "\" not found.");
  158. if (!this.can('mute', targetUser, room)) return false;
  159.  
  160. this.addModCommand(targetUser.name + " was kicked from the room by " + user.name + ".");
  161. Ultra.kick(targetUser, room.id, "You were kicked from " + room.id + " by " + user.name + ".");
  162. },
  163. kickhelp: ["/kick - Kick a user out of a room. Requires: % @ # & ~"],
  164.  
  165. masspm: 'pmall',
  166. pmall: function (target, room, user) {
  167. if (!this.can('pmall')) return false;
  168. if (!target) return this.parse('/help pmall');
  169.  
  170. Ultra.pmAll(target);
  171. },
  172. pmallhelp: ["/pmall [message] - PM all users in the server."],
  173.  
  174. staffpm: 'pmallstaff',
  175. pmstaff: 'pmallstaff',
  176. pmallstaff: function (target, room, user) {
  177. if (!this.can('forcewin')) return false;
  178. if (!target) return this.parse('/help pmallstaff');
  179.  
  180. Ultra.pmAllStaff(target);
  181. },
  182. pmallstaffhelp: ["/pmallstaff [message] - Sends a PM to every staff member online."],
  183.  
  184. regdate: function (target, room, user) {
  185. if (!this.runBroadcast()) return;
  186. if (!target || !toId(target)) return this.parse('/help regdate');
  187. let username = toId(target);
  188. request('http://pokemonshowdown.com/users/' + username, function (error, response, body) {
  189. if (error && response.statusCode !== 200) {
  190. this.sendReplyBox(Tools.escapeHTML(target) + " is not registered.");
  191. return room.update();
  192. }
  193. let regdate = body.split('<small>')[1].split('</small>')[0].replace(/(<em>|<\/em>)/g, '');
  194. if (regdate === '(Unregistered)') {
  195. this.sendReplyBox(Tools.escapeHTML(target) + " is not registered.");
  196. } else if (regdate === '(Account disabled)') {
  197. this.sendReplyBox(Tools.escapeHTML(target) + "'s account is disabled.");
  198. } else {
  199. this.sendReplyBox(Tools.escapeHTML(target) + " was registered on " + regdate.slice(7) + ".");
  200. }
  201. room.update();
  202. }.bind(this));
  203. },
  204. regdatehelp: ["/regdate - Please specify a valid username."],
  205.  
  206. sb: 'showdownboilerplate',
  207. showdownboilerplate: function (target, room, user) {
  208. if (!this.runBroadcast()) return;
  209. this.sendReply("|raw|This server uses <a href='https://github.com/CreaturePhil/Showdown-Boilerplate'>Showdown-Boilerplate</a>.");
  210. },
  211. showdownboilerplatehelp: ["/showdownboilerplate - Links to the Showdown-Boilerplate repository on Github."],
  212.  
  213. seen: function (target, room, user) {
  214. if (!this.runBroadcast()) return;
  215. if (!target) return this.parse('/help seen');
  216. let targetUser = Users.get(target);
  217. if (targetUser && targetUser.connected) return this.sendReplyBox(targetUser.name + " is <b>currently online</b>.");
  218. target = Tools.escapeHTML(target);
  219. let seen = Ultra.lastSeen(target);
  220. if (!seen) return this.sendReplyBox(target + " has never been online on this server.");
  221. this.sendReplyBox(target + " was last seen <b>" + moment(seen).fromNow() + "</b>.");
  222. },
  223. seenhelp: ["/seen - Shows when the user last connected on the server."],
  224.  
  225. tell: function (target, room, user, connection) {
  226. if (!target) return this.parse('/help tell');
  227. target = this.splitTarget(target);
  228. let targetUser = this.targetUser;
  229. if (!target) {
  230. this.sendReply("You forgot the comma.");
  231. return this.parse('/help tell');
  232. }
  233.  
  234. if (targetUser && targetUser.connected) {
  235. return this.parse('/pm ' + this.targetUsername + ', ' + target);
  236. }
  237.  
  238. if (user.locked) return this.popupReply("You may not send offline messages when locked.");
  239. if (target.length > 255) return this.popupReply("Your message is too long to be sent as an offline message (>255 characters).");
  240.  
  241. if (Config.tellrank === 'autoconfirmed' && !user.autoconfirmed) {
  242. return this.popupReply("You must be autoconfirmed to send an offline message.");
  243. } else if (!Config.tellrank || Config.groupsranking.indexOf(user.group) < Config.groupsranking.indexOf(Config.tellrank)) {
  244. return this.popupReply("You cannot send an offline message because offline messaging is " +
  245. (!Config.tellrank ? "disabled" : "only available to users of rank " + Config.tellrank + " and above") + ".");
  246. }
  247.  
  248. let userid = toId(this.targetUsername);
  249. if (userid.length > 18) return this.popupReply("\"" + this.targetUsername + "\" is not a legal username.");
  250.  
  251. let sendSuccess = Tells.addTell(user, userid, target);
  252. if (!sendSuccess) {
  253. if (sendSuccess === false) {
  254. return this.popupReply("User " + this.targetUsername + " has too many offline messages queued.");
  255. } else {
  256. return this.popupReply("You have too many outgoing offline messages queued. Please wait until some have been received or have expired.");
  257. }
  258. }
  259. return connection.send('|pm|' + user.getIdentity() + '|' +
  260. (targetUser ? targetUser.getIdentity() : ' ' + this.targetUsername) +
  261. "|/text This user is currently offline. Your message will be delivered when they are next online.");
  262. },
  263. tellhelp: ["/tell [username], [message] - Send a message to an offline user that will be received when they log in."],
  264.  
  265. 'etour': 'elimtour',
  266. elimtour: function (target, room, user) {
  267. let tiers = ['Random Battle', 'CC1v1', 'OU', 'RU', 'Ubers', 'Battle Factory', 'AG', 'Monotype'];
  268. if (!target) return this.parse('/tour new ' + tiers[Math.floor(Math.random()) * tiers.length] + ', elimination');
  269. this.parse('/tour new ' + target + ', elimination');
  270. },
  271.  
  272. rtour: function (target, room, user) {
  273. let tiers = ['Random Battle', 'CC1v1', 'OU', 'RU', 'Ubers', 'Battle Factory', 'AG', 'Monotype'];
  274. if (!target) return this.parse('/tour new ' + tiers[Math.floor(Math.random()) * tiers.length] + ', round robin');
  275. this.parse('/tour new ' + target + ', round robin');
  276. },
  277.  
  278. shrug: function (target, room, user) {
  279. if (user.can('broadcast', null, room)) return '¯\\_(ツ)_/¯';
  280. this.errorReply('You must be voiced in this room to use this command.');
  281. },
  282.  
  283. rko: function (target, room, user) {
  284. let params = target.split(',');
  285. if (!params[1]) return this.sendReply('Usage: ' + '/rko user, message - kicks the user out of a room and gives them a popup saying [message]');
  286. if (!this.canTalk() && !user.can('bypassall')) {
  287. return this.sendReply("You cannot do this while unable to talk.");
  288. }
  289. let targetUser = Users.get(params[0]);
  290. if (!targetUser) return this.sendReply("User \"" + params[0] + "\" not found.");
  291. if (!this.can('mute', targetUser, room)) return false;
  292. if (params[0] === 'megas4ever' && user.userid !== 'megas4ever') return this.parse('/rko ' + user.userid + ', LOL NOPE');
  293. if (params[0] === 'iFlexy' && user.userid !== 'megas4ever' && user.userid !== 'execute') return this.parse('/rko ' + user.userid + ', NO YOU CALL ME DADDY BITCH');
  294. this.addModCommand(params[0] + " was RKO'D OUTTA NOWHERE by " + user.name + ".");
  295. Ultra.kick(targetUser, room.id, user.name + ' RKO\'d you in ' + room.id + '. ' + params[1])
  296. },
  297.  
  298. broadcast: function (target, room, user) {
  299. let params = target.split(',');
  300. let targetUser = Users.get(params[0]);
  301. if (!this.can('declare', null, room)) return false;
  302. if (!params[1]) return this.sendReply('Usage: /broadcast color, message - broadcast a declare in a certain color.');
  303. if (!color.includes(params[0])) return this.errorReply('Not a valid color. Valid colors are: ' + color.sort().join(', '));
  304. room.add('|html|<div class=broadcast-' + params[0] + '>' + params[1] + '</div>');
  305.  
  306. },
  307. sprite: function (target, user, room) {
  308. if (!this.runBroadcast()) return;
  309. if(!target) return this.parse('/spritehelp');
  310. if(!pokedex.includes(target)) return this.errorReply('Please enter a valid Pokemon name.');
  311. this.sendReplyBox('<b>' + target + ' sprite: </b> <img src=http://play.pokemonshowdown.com/sprites/xyani/' + target + '.gif>');
  312. },
  313. spritehelp: function(target,user,room){
  314. if (!this.runBroadcast()) return;
  315. this.sendReplyBox('/sprite - Gives you the animated gen 6 sprite of a pokemon.');
  316. },
  317.  
  318. /* suggest: function (target, room, user) {
  319. if (!target) return this.sendReplyBox('/suggest (suggestion) - Suggest something to be added to the server.');
  320. if (!suggestionsCache[user.userid]) {
  321. suggestionsCache[user.userid] = [];
  322. suggestionsCache[user.userid].push(target);
  323. fs.writeFile(suggestions, JSON.stringify(suggestionsCache));
  324. }
  325. if (suggestionsCache[user.userid].length === 3) return this.sendReply('You cannot have more than three suggestions at a time. You must wait for an upper staff member to check your suggestion before suggesting again.');
  326. suggestionsCache[user.userid].push(target);
  327. fs.writeFile(suggestions, JSON.stringify(suggestionsCache));
  328. Rooms.rooms.staff.add('|html|<b>SUGGESTION FROM: ' + user.name + ' - ' + target + '</b>').update();
  329. this.sendReplyBox('Your suggestion has been sent to staff n_n');
  330. },*/
  331. }
  332.  
  333. Object.assign(Ultra, {
  334. reloadCSS: function () {
  335. request('http://play.pokemonshowdown.com/customcss.php?server=ultra&invalidate',
  336. function callback (error, res, body) {
  337. if (error) console.log('reloadCSS error: ' + error);
  338. });
  339. },
  340.  
  341. clearRoom: function (room) {
  342. let len = (room.log && room.log.length) || 0;
  343. let users = [];
  344. while (len--) {
  345. room.log[len] = '';
  346. }
  347. for (let u in room.users) {
  348. users.push(u);
  349. Users.get(u).leaveRoom(room, Users.get(u).connections[0]);
  350. }
  351. len = users.length;
  352. setTimeout(function () {
  353. while (len--) {
  354. Users.get(users[len]).joinRoom(room, Users.get(users[len]).connections[0]);
  355. }
  356. });
  357. },
  358.  
  359. lastSeen: function (user) {
  360. let seen = Db('seen').get(toId(user));
  361. if (!seen) return false;
  362. return seen;
  363. },
  364.  
  365. pmAll: function (message) {
  366. let pmName = ' Ultra Server [Do not reply]';
  367. Users.users.forEach(function (user) {
  368. user.send('|pm|' + pmName + '|' + user.getIdentity() + '|' + message);
  369. });
  370. },
  371.  
  372. pmAllStaff: function (message) {
  373. let pmName = ' Staff PM [Do not reply]';
  374. Users.users.forEach(function (user) {
  375. if (!user.isStaff) return;
  376. user.send('|pm|' + pmName + '|' + user.getIdentity() + '|' + message);
  377. });
  378. },
  379.  
  380. pmUpperStaff: function (message) {
  381. let pmName = ' Upper Staff PM [Do not reply]';
  382. Users.users.forEach(function (user) {
  383. if (!user.can('forcewin')) return;
  384. user.send('|pm|${pmName}|${user.getIdentity()}|${message}');
  385. });
  386. },
  387.  
  388. kick: function (user, room, message) {
  389. user.popup(message);
  390. user.leaveRoom(room);
  391. }
  392. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement