UNPKG

1.23 kBJavaScriptView Raw
1exports.command = {
2 name: "addrank",
3 autoload: true,
4 unloadable: true,
5 min_rank: 9,
6 display: "adds a rank",
7 help: "Adds a rank.",
8 usage: ".addrank <rank name>",
9 weigth: 0,
10
11 // Function to execute the command
12 execute: function(socket, command, command_access) {
13 var chalk = require('chalk');
14 if (typeof command !== 'string' || command.length < 1) {
15 socket.write(chalk.yellow(":: You'll have to give the new rank a name...\r\n"));
16 return;
17 }
18 // add the new rank
19 var updated = command_access.ranks;
20 updated.list.push(command);
21 command_access.updateRanks(updated);
22 // promote top-rank users to the new rank
23 var oldrank = updated.list.length - 2;
24 var users = command_access.getUsersList();
25 for (var u=0; u < users.length; u++) {
26 if (users[u].rank === oldrank) {
27 // promote users[u].username
28 var online = command_access.getOnlineUser(users[u].username);
29 if (online) {
30 online.db.rank = online.db.rank+1;
31 command_access.updateUser(online.username, online.db);
32 } else {
33 var w = command_access.getUser(users[u].username);
34 w.rank = w.rank+1;
35 command_access.updateUser(users[u].username, w);
36 }
37 }
38 }
39 socket.write(chalk.bold("Rank added!\r\n"));
40 }
41}