1 | exports.command = {
|
2 | name: "promote",
|
3 | autoload: true,
|
4 | unloadable: true,
|
5 | min_rank: 3,
|
6 | display: "make one of your friends get a better rank!",
|
7 | help: "Make one of your friends get a better rank!",
|
8 | usage: ".promote <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(chalk.yellow(":: ") + "Promote whom?\r\n");
|
19 | } else {
|
20 | var wArr = command_access.getAproxUser(whom);
|
21 | if (wArr.length === 0) return me.write(chalk.yellow(":: ") + "Promote whom?\r\n");
|
22 | if (wArr.length > 1) {
|
23 | var possibilities = "";
|
24 | for (var p = 0; p < wArr.length - 1; p++) {
|
25 | possibilities += chalk.bold(wArr[p]) + ", ";
|
26 | }
|
27 | possibilities += chalk.bold(wArr[wArr.length - 1]);
|
28 | return me.write(chalk.yellow(":: ") + "Be more explicit: whom do you want to promote ("+possibilities+")?\r\n");
|
29 | }
|
30 | }
|
31 | whom = wArr[0];
|
32 | w = command_access.getUser(whom);
|
33 | if (me.db.rank > w.rank) {
|
34 |
|
35 | var online = command_access.getOnlineUser(whom);
|
36 | var rankName;
|
37 | if (online) {
|
38 | online.db.rank = online.db.rank+1;
|
39 | rankName = command_access.ranks.list[online.db.rank];
|
40 | command_access.updateUser(online.username, online.db);
|
41 | } else {
|
42 | w.rank = w.rank+1;
|
43 | rankName = command_access.ranks.list[w.rank];
|
44 | command_access.updateUser(whom, w);
|
45 | }
|
46 | whom = whom.toLowerCase().charAt(0).toUpperCase() + whom.toLowerCase().slice(1);
|
47 | var sentence = chalk.green(":: ") + chalk.cyan(me.username) + " has promoted " + chalk.bold(whom) + " to the rank of " + chalk.magenta(rankName) + "! " + chalk.green("::\r\n");
|
48 | command_access.allButMe(socket,function(me,to){to.write(sentence);});
|
49 | socket.write(chalk.green(":: ") + "You promoted " + chalk.bold(whom) + " to the rank of " + chalk.green(rankName) + "!\r\n");
|
50 | } else {
|
51 | me.write(chalk.red(":: ") + "You cannot promote someone to an higher level than yourse!\r\n");
|
52 | }
|
53 | }
|
54 | }
|