Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- let moment = require('moment');
- let request = require('request');
- let fs = require("fs");
- let color = ['blue', 'red', 'green', 'orange'];
- let suggestions = 'config/db/suggestions.json';
- let suggestionsCache;
- try {
- suggestionsCache = JSON.parse(fs.readFileSync(suggestions, 'utf8'));
- }
- catch (e) {
- suggestionsCache = {};
- }
- exports.commands = {
- fj: 'forcejoin',
- forcejoin: function (target, room, user) {
- if (!user.can('mute')) return false;
- if (!target) return this.sendReply('/forcejoin [target], [room] - Forces a user to join a room');
- let parts = target.split(',');
- if (!parts[0] || !parts[1]) return this.sendReply('/forcejoin [target], [room] - Forces a user to join a room');
- let userid = toId(parts[0]);
- let roomid = toId(parts[1]);
- if (!Users.get(userid)) return this.sendReply ('User not found.');
- if (!Rooms.get(roomid)) return this.sendReply ('Room not found.');
- Users.get(userid).joinRoom(roomid);
- },
- roomlist: function (target, room, user) {
- if(!this.can('pban')) return;
- var totalUsers = 0;
- for (var u of Users.users) {
- u = u[1];
- if (Users(u).connected) {
- totalUsers++;
- }
- }
- var rooms = Object.keys(Rooms.rooms),
- len = rooms.length,
- header = ['<b><font color="#DA9D01" size="2">Total users connected: ' + totalUsers + '</font></b><br />'],
- official = ['<b><font color="#1a5e00" size="2">Official chat rooms:</font></b><br />'],
- nonOfficial = ['<hr><b><font color="#000b5e" size="2">Public chat rooms:</font></b><br />'],
- privateRoom = ['<hr><b><font color="#ff5cb6" size="2">Private chat rooms:</font></b><br />'],
- groupChats = ['<hr><b><font color="#740B53" size="2">Group Chats:</font></b><br />'],
- battleRooms = ['<hr><b><font color="#0191C6" size="2">Battle Rooms:</font></b><br />'];
- while (len--) {
- var _room = Rooms.rooms[rooms[(rooms.length - len) - 1]];
- if (_room.type === 'battle') {
- battleRooms.push('<a href="/' + _room.id + '" class="ilink">' + _room.title + '</a> (' + _room.userCount + ')');
- }
- if (_room.type === 'chat') {
- if (_room.isPersonal) {
- groupChats.push('<a href="/' + _room.id + '" class="ilink">' + _room.id + '</a> (' + _room.userCount + ')');
- continue;
- }
- if (_room.isOfficial) {
- official.push('<a href="/' + toId(_room.title) + '" class="ilink">' + _room.title + '</a> (' + _room.userCount + ')');
- continue;
- }
- if (_room.isPrivate) {
- privateRoom.push('<a href="/' + toId(_room.title) + '" class="ilink">' + _room.title + '</a> (' + _room.userCount + ')');
- continue;
- }
- }
- if (_room.type !== 'battle' && _room.id !== 'global') nonOfficial.push('<a href="/' + toId(_room.title) + '" class="ilink">' + _room.title + '</a> (' + _room.userCount + ')');
- }
- this.sendReplyBox(header + official.join(' ') + nonOfficial.join(' ') + privateRoom.join(' ') + (groupChats.length > 1 ? groupChats.join(' ') : '') + (battleRooms.length > 1 ? battleRooms.join(' ') : ''));
- },
- cgdeclare: 'customgdeclare',
- customgdeclare: function (target, room, user) {
- let parts = target.split(',');
- if (!target) return this.parse('/help customgdeclare');
- if (!parts[4]) return this.parse('/help customgdeclare');
- if (!this.can('gdeclare')) return false;
- for (let id in Rooms.rooms) {
- 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>');
- }
- this.logModCommand(user.name + " globally custom declared " + target);
- },
- 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: &, ~"],
- stafflist: 'authority',
- auth: 'authority',
- authlist: 'authority',
- authority: function (target, room, user, connection) {
- let rankLists = {};
- let ranks = Object.keys(Config.groups);
- for (let u in Users.usergroups) {
- let rank = Users.usergroups[u].charAt(0);
- // In case the usergroups.csv file is not proper, we check for the server ranks.
- if (ranks.indexOf(rank) > -1) {
- let name = Users.usergroups[u].substr(1);
- if (!rankLists[rank]) rankLists[rank] = [];
- if (name) rankLists[rank].push(((Users.getExact(name) && Users.getExact(name).connected) ? '**' + name + '**' : name));
- }
- }
- let buffer = [];
- Object.keys(rankLists).sort(function (a, b) {
- return (Config.groups[b] || {rank: 0}).rank - (Config.groups[a] || {rank: 0}).rank;
- }).forEach(function (r) {
- buffer.push((Config.groups[r] ? r + Config.groups[r].name + "s (" + rankLists[r].length + ")" : r) + ":\n" + rankLists[r].sort().join(", "));
- });
- if (!buffer.length) {
- return connection.popup("This server has no auth.");
- }
- connection.popup(buffer.join("\n\n"));
- },
- clearall: function (target, room, user) {
- if (!this.can('declare')) return false;
- if (room.battle) return this.sendReply("You cannot clearall in battle rooms.");
- Ultra.clearRoom(room);
- },
- gclearall: 'globalclearall',
- globalclearall: function (target, room, user) {
- if (!this.can('gdeclare')) return false;
- for (let u in Users.users) {
- Users.users[u].popup("All rooms are being clear.");
- }
- for (let r in Rooms.rooms) {
- Ultra.clearRoom(Rooms.rooms[r]);
- }
- },
- hide: function (target, room, user) {
- if (!this.can('lock')) return false;
- user.hiding = true;
- user.updateIdentity();
- this.sendReply("You have hidden your staff symbol.");
- },
- show: function (target, room, user) {
- if (!this.can('lock')) return false;
- user.hiding = false;
- user.updateIdentity();
- this.sendReply("You have revealed your staff symbol.");
- },
- rk: 'kick',
- roomkick: 'kick',
- kick: function (target, room, user) {
- if (!target) return this.parse('/help kick');
- if (!this.canTalk() && !user.can('bypassall')) {
- return this.sendReply("You cannot do this while unable to talk.");
- }
- target = this.splitTarget(target);
- let targetUser = this.targetUser;
- if (!targetUser || !targetUser.connected) return this.sendReply("User \"" + this.targetUsername + "\" not found.");
- if (!this.can('mute', targetUser, room)) return false;
- this.addModCommand(targetUser.name + " was kicked from the room by " + user.name + ".");
- Ultra.kick(targetUser, room.id, "You were kicked from " + room.id + " by " + user.name + ".");
- },
- kickhelp: ["/kick - Kick a user out of a room. Requires: % @ # & ~"],
- masspm: 'pmall',
- pmall: function (target, room, user) {
- if (!this.can('pmall')) return false;
- if (!target) return this.parse('/help pmall');
- Ultra.pmAll(target);
- },
- pmallhelp: ["/pmall [message] - PM all users in the server."],
- staffpm: 'pmallstaff',
- pmstaff: 'pmallstaff',
- pmallstaff: function (target, room, user) {
- if (!this.can('forcewin')) return false;
- if (!target) return this.parse('/help pmallstaff');
- Ultra.pmAllStaff(target);
- },
- pmallstaffhelp: ["/pmallstaff [message] - Sends a PM to every staff member online."],
- regdate: function (target, room, user) {
- if (!this.runBroadcast()) return;
- if (!target || !toId(target)) return this.parse('/help regdate');
- let username = toId(target);
- request('http://pokemonshowdown.com/users/' + username, function (error, response, body) {
- if (error && response.statusCode !== 200) {
- this.sendReplyBox(Tools.escapeHTML(target) + " is not registered.");
- return room.update();
- }
- let regdate = body.split('<small>')[1].split('</small>')[0].replace(/(<em>|<\/em>)/g, '');
- if (regdate === '(Unregistered)') {
- this.sendReplyBox(Tools.escapeHTML(target) + " is not registered.");
- } else if (regdate === '(Account disabled)') {
- this.sendReplyBox(Tools.escapeHTML(target) + "'s account is disabled.");
- } else {
- this.sendReplyBox(Tools.escapeHTML(target) + " was registered on " + regdate.slice(7) + ".");
- }
- room.update();
- }.bind(this));
- },
- regdatehelp: ["/regdate - Please specify a valid username."],
- sb: 'showdownboilerplate',
- showdownboilerplate: function (target, room, user) {
- if (!this.runBroadcast()) return;
- this.sendReply("|raw|This server uses <a href='https://github.com/CreaturePhil/Showdown-Boilerplate'>Showdown-Boilerplate</a>.");
- },
- showdownboilerplatehelp: ["/showdownboilerplate - Links to the Showdown-Boilerplate repository on Github."],
- seen: function (target, room, user) {
- if (!this.runBroadcast()) return;
- if (!target) return this.parse('/help seen');
- let targetUser = Users.get(target);
- if (targetUser && targetUser.connected) return this.sendReplyBox(targetUser.name + " is <b>currently online</b>.");
- target = Tools.escapeHTML(target);
- let seen = Ultra.lastSeen(target);
- if (!seen) return this.sendReplyBox(target + " has never been online on this server.");
- this.sendReplyBox(target + " was last seen <b>" + moment(seen).fromNow() + "</b>.");
- },
- seenhelp: ["/seen - Shows when the user last connected on the server."],
- tell: function (target, room, user, connection) {
- if (!target) return this.parse('/help tell');
- target = this.splitTarget(target);
- let targetUser = this.targetUser;
- if (!target) {
- this.sendReply("You forgot the comma.");
- return this.parse('/help tell');
- }
- if (targetUser && targetUser.connected) {
- return this.parse('/pm ' + this.targetUsername + ', ' + target);
- }
- if (user.locked) return this.popupReply("You may not send offline messages when locked.");
- if (target.length > 255) return this.popupReply("Your message is too long to be sent as an offline message (>255 characters).");
- if (Config.tellrank === 'autoconfirmed' && !user.autoconfirmed) {
- return this.popupReply("You must be autoconfirmed to send an offline message.");
- } else if (!Config.tellrank || Config.groupsranking.indexOf(user.group) < Config.groupsranking.indexOf(Config.tellrank)) {
- return this.popupReply("You cannot send an offline message because offline messaging is " +
- (!Config.tellrank ? "disabled" : "only available to users of rank " + Config.tellrank + " and above") + ".");
- }
- let userid = toId(this.targetUsername);
- if (userid.length > 18) return this.popupReply("\"" + this.targetUsername + "\" is not a legal username.");
- let sendSuccess = Tells.addTell(user, userid, target);
- if (!sendSuccess) {
- if (sendSuccess === false) {
- return this.popupReply("User " + this.targetUsername + " has too many offline messages queued.");
- } else {
- return this.popupReply("You have too many outgoing offline messages queued. Please wait until some have been received or have expired.");
- }
- }
- return connection.send('|pm|' + user.getIdentity() + '|' +
- (targetUser ? targetUser.getIdentity() : ' ' + this.targetUsername) +
- "|/text This user is currently offline. Your message will be delivered when they are next online.");
- },
- tellhelp: ["/tell [username], [message] - Send a message to an offline user that will be received when they log in."],
- 'etour': 'elimtour',
- elimtour: function (target, room, user) {
- let tiers = ['Random Battle', 'CC1v1', 'OU', 'RU', 'Ubers', 'Battle Factory', 'AG', 'Monotype'];
- if (!target) return this.parse('/tour new ' + tiers[Math.floor(Math.random()) * tiers.length] + ', elimination');
- this.parse('/tour new ' + target + ', elimination');
- },
- rtour: function (target, room, user) {
- let tiers = ['Random Battle', 'CC1v1', 'OU', 'RU', 'Ubers', 'Battle Factory', 'AG', 'Monotype'];
- if (!target) return this.parse('/tour new ' + tiers[Math.floor(Math.random()) * tiers.length] + ', round robin');
- this.parse('/tour new ' + target + ', round robin');
- },
- shrug: function (target, room, user) {
- if (user.can('broadcast', null, room)) return '¯\\_(ツ)_/¯';
- this.errorReply('You must be voiced in this room to use this command.');
- },
- rko: function (target, room, user) {
- let params = target.split(',');
- if (!params[1]) return this.sendReply('Usage: ' + '/rko user, message - kicks the user out of a room and gives them a popup saying [message]');
- if (!this.canTalk() && !user.can('bypassall')) {
- return this.sendReply("You cannot do this while unable to talk.");
- }
- let targetUser = Users.get(params[0]);
- if (!targetUser) return this.sendReply("User \"" + params[0] + "\" not found.");
- if (!this.can('mute', targetUser, room)) return false;
- if (params[0] === 'megas4ever' && user.userid !== 'megas4ever') return this.parse('/rko ' + user.userid + ', LOL NOPE');
- if (params[0] === 'iFlexy' && user.userid !== 'megas4ever' && user.userid !== 'execute') return this.parse('/rko ' + user.userid + ', NO YOU CALL ME DADDY BITCH');
- this.addModCommand(params[0] + " was RKO'D OUTTA NOWHERE by " + user.name + ".");
- Ultra.kick(targetUser, room.id, user.name + ' RKO\'d you in ' + room.id + '. ' + params[1])
- },
- broadcast: function (target, room, user) {
- let params = target.split(',');
- let targetUser = Users.get(params[0]);
- if (!this.can('declare', null, room)) return false;
- if (!params[1]) return this.sendReply('Usage: /broadcast color, message - broadcast a declare in a certain color.');
- if (!color.includes(params[0])) return this.errorReply('Not a valid color. Valid colors are: ' + color.sort().join(', '));
- room.add('|html|<div class=broadcast-' + params[0] + '>' + params[1] + '</div>');
- },
- sprite: function (target, user, room) {
- if (!this.runBroadcast()) return;
- if(!target) return this.parse('/spritehelp');
- if(!pokedex.includes(target)) return this.errorReply('Please enter a valid Pokemon name.');
- this.sendReplyBox('<b>' + target + ' sprite: </b> <img src=http://play.pokemonshowdown.com/sprites/xyani/' + target + '.gif>');
- },
- spritehelp: function(target,user,room){
- if (!this.runBroadcast()) return;
- this.sendReplyBox('/sprite - Gives you the animated gen 6 sprite of a pokemon.');
- },
- /* suggest: function (target, room, user) {
- if (!target) return this.sendReplyBox('/suggest (suggestion) - Suggest something to be added to the server.');
- if (!suggestionsCache[user.userid]) {
- suggestionsCache[user.userid] = [];
- suggestionsCache[user.userid].push(target);
- fs.writeFile(suggestions, JSON.stringify(suggestionsCache));
- }
- 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.');
- suggestionsCache[user.userid].push(target);
- fs.writeFile(suggestions, JSON.stringify(suggestionsCache));
- Rooms.rooms.staff.add('|html|<b>SUGGESTION FROM: ' + user.name + ' - ' + target + '</b>').update();
- this.sendReplyBox('Your suggestion has been sent to staff n_n');
- },*/
- }
- Object.assign(Ultra, {
- reloadCSS: function () {
- request('http://play.pokemonshowdown.com/customcss.php?server=ultra&invalidate',
- function callback (error, res, body) {
- if (error) console.log('reloadCSS error: ' + error);
- });
- },
- clearRoom: function (room) {
- let len = (room.log && room.log.length) || 0;
- let users = [];
- while (len--) {
- room.log[len] = '';
- }
- for (let u in room.users) {
- users.push(u);
- Users.get(u).leaveRoom(room, Users.get(u).connections[0]);
- }
- len = users.length;
- setTimeout(function () {
- while (len--) {
- Users.get(users[len]).joinRoom(room, Users.get(users[len]).connections[0]);
- }
- });
- },
- lastSeen: function (user) {
- let seen = Db('seen').get(toId(user));
- if (!seen) return false;
- return seen;
- },
- pmAll: function (message) {
- let pmName = ' Ultra Server [Do not reply]';
- Users.users.forEach(function (user) {
- user.send('|pm|' + pmName + '|' + user.getIdentity() + '|' + message);
- });
- },
- pmAllStaff: function (message) {
- let pmName = ' Staff PM [Do not reply]';
- Users.users.forEach(function (user) {
- if (!user.isStaff) return;
- user.send('|pm|' + pmName + '|' + user.getIdentity() + '|' + message);
- });
- },
- pmUpperStaff: function (message) {
- let pmName = ' Upper Staff PM [Do not reply]';
- Users.users.forEach(function (user) {
- if (!user.can('forcewin')) return;
- user.send('|pm|${pmName}|${user.getIdentity()}|${message}');
- }
- },
- kick: function (user, room, message) {
- user.popup(message);
- user.leaveRoom(room);
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement