1 | var formatters = require('../utils/formatters.js');
|
2 |
|
3 | exports.command = {
|
4 | name: "rmrank",
|
5 | autoload: true,
|
6 | unloadable: true,
|
7 | min_rank: 9,
|
8 | display: "removes a rank",
|
9 | help: "Removes a rank from the rank list, adjusting all the others.",
|
10 | usage: ".rmrank <rank number>",
|
11 | weigth: 0,
|
12 |
|
13 |
|
14 | execute: function(socket, command, command_access) {
|
15 | var chalk = require('chalk');
|
16 | if (typeof command !== 'string' || command.length < 1) {
|
17 | socket.write(chalk.yellow(":: ") + "What rank do you want to remove?\r\n");
|
18 | return;
|
19 | }
|
20 |
|
21 | var rank = parseInt(command, 10);
|
22 | if (
|
23 | Number(command) !== rank ||
|
24 | rank < 0 ||
|
25 | rank >= command_access.ranks.list.length
|
26 | ) {
|
27 | socket.write(chalk.red(":: ") + "That is an invalid rank number!\r\n");
|
28 | return;
|
29 | }
|
30 |
|
31 | if (rank > socket.db.rank) {
|
32 | socket.write(chalk.red(":: ") + "You cannot manage ranks to which you have no access.\r\n");
|
33 | return;
|
34 | }
|
35 |
|
36 | for (var c in command_access.commands) {
|
37 | if (command_access.getCmdRank(c) == rank) {
|
38 | socket.write(formatters.text_wrap(chalk.red(":: ") + "Can't remove that rank: command " +
|
39 | chalk.bold(command_access.commands[c].name) +
|
40 | " exists on it. Maybe you want to " + chalk.yellow(".setcmdlev") + " it to another rank?\r\n"));
|
41 | return;
|
42 | }
|
43 | if (command_access.getCmdRank(c) > rank) {
|
44 | command_access.setCmdRank(command_access.commands[c].name, command_access.getCmdRank(c) - 1);
|
45 | }
|
46 | }
|
47 |
|
48 | var highest = (rank == command_access.ranks.list.length-1);
|
49 | var users = command_access.getUsersList();
|
50 | for (var u=0; u < users.length; u++) {
|
51 | if (users[u].rank >= rank) {
|
52 | if (users[u].rank == rank && !highest) {
|
53 | socket.write(formatters.text_wrap(chalk.red(":: ") + "Can't remove that rank: user " +
|
54 | chalk.bold(users[u].username) +
|
55 | " is of that rank! You might want to " + chalk.bold(".demote") + " or " + chalk.bold(".promote") + " them first.\r\n"));
|
56 | return;
|
57 | } else {
|
58 | var online = command_access.getOnlineUser(users[u].username);
|
59 | if (online) {
|
60 | online.db.rank = online.db.rank-1;
|
61 | command_access.updateUser(online.username, online.db);
|
62 | } else {
|
63 | var w = command_access.getUser(users[u].username);
|
64 | w.rank = w.rank-1;
|
65 | command_access.updateUser(users[u].username, w);
|
66 | }
|
67 | }
|
68 | }
|
69 | }
|
70 | var updated = command_access.ranks;
|
71 |
|
72 | if (updated.entrylevel >= rank) updated.entrylevel = updated.entrylevel - 1;
|
73 |
|
74 | updated.list.splice(command,1);
|
75 | command_access.updateRanks(updated);
|
76 | socket.write(chalk.green(":: ") + "Rank removed!\r\n");
|
77 | }
|
78 | }
|