1 | exports.command = {
|
2 | name: "demote",
|
3 | autoload: true,
|
4 | unloadable: true,
|
5 | min_rank: 3,
|
6 | display: "Lower someone's rank!",
|
7 | help: "Lower someone's rank!",
|
8 | usage: ".demote <user>",
|
9 |
|
10 |
|
11 | execute: function(socket, command, command_access) {
|
12 | var chalk = require('chalk');
|
13 | var me = socket;
|
14 | var whom = command.split(' ')[0];
|
15 | var w = null;
|
16 |
|
17 | if (typeof whom === 'undefined' || whom.length < 1) {
|
18 | return me.write("Demote whom?\r\n");
|
19 | } else {
|
20 | var wArr = command_access.getAproxUser(whom);
|
21 | if (wArr.length === 0) return me.write("Demote whom?\r\n");
|
22 | if (wArr.length > 1) {
|
23 | var possibilities = "";
|
24 | for (var p = 0; p < wArr.length - 1; p++) {
|
25 | possibilities += wArr[p] + ", ";
|
26 | }
|
27 | possibilities += wArr[wArr.length - 1];
|
28 | return me.write("Be more explicit: whom do you want to demote ("+possibilities+")?\r\n");
|
29 | }
|
30 | whom = wArr[0];
|
31 | w = command_access.getUser(whom);
|
32 | }
|
33 | if (w.rank == 0) {
|
34 | socket.write("How low do you think someone can be?\r\n");
|
35 | } else if (me.db.rank > w.rank) {
|
36 |
|
37 | var online = command_access.getOnlineUser(whom);
|
38 | var rankName;
|
39 | if (online) {
|
40 | online.db.rank = online.db.rank-1;
|
41 | rankName = command_access.ranks.list[online.db.rank];
|
42 | command_access.updateUser(online.username, online.db);
|
43 | } else {
|
44 | w.rank = w.rank-1;
|
45 | rankName = command_access.ranks.list[w.rank];
|
46 | command_access.updateUser(whom, w);
|
47 | }
|
48 | whom = whom.toLowerCase().charAt(0).toUpperCase() + whom.toLowerCase().slice(1);
|
49 | var sentence = chalk.red(":: ") + chalk.white(me.username) + chalk.red(" has demoted ") +
|
50 | chalk.yellow(whom) + chalk.red(" to the rank of ") + chalk.green(rankName) + chalk.red("! ::\r\n");
|
51 | command_access.allButMe(socket,function(me,to){to.write(sentence);});
|
52 | socket.write("You " + chalk.red("demoted ") + chalk.yellow(whom) + " to the rank of " + chalk.green(rankName) + "!\r\n");
|
53 | } else {
|
54 | me.write("You cannot demote someone with the same or an higher rank than yours!\r\n");
|
55 | }
|
56 | }
|
57 | }
|