UNPKG

1.4 kBJavaScriptView Raw
1exports.command = {
2 name: "entrylevel",
3 autoload: true,
4 unloadable: true,
5 min_rank: 9,
6 display: "sets which rank new users start with",
7 help: "Sets which rank new users start with, when they enter for the first time.",
8 usage: ".entrylevel <rank number>",
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(":: What rank do you want to set as entry level?\r\n"));
16 return;
17 }
18 // is this a valid rank number?
19 var rank = parseInt(command, 10);
20 if (
21 Number(command) !== rank ||
22 rank < 0 ||
23 rank >= command_access.ranks.list.length
24 ) {
25 socket.write(chalk.red(":: That is an invalid rank number!\r\n"));
26 return;
27 }
28 // do I have access to this rank?
29 if (rank > socket.db.rank) {
30 socket.write(chalk.red(":: You cannot manage ranks to which you have no access.\r\n"));
31 return;
32 }
33 // is it the one we have already?
34 if (command_access.ranks.entrylevel === rank) {
35 socket.write(chalk.yellow(":: That is already the defined entry level!\r\n"));
36 return;
37 }
38 // adjust entrylevel
39 var updated = command_access.ranks;
40 updated.entrylevel = rank;
41 command_access.updateRanks(updated);
42 socket.write(chalk.green(":: ") + "Entry level updated to " + chalk.bold(rank) + ".\r\n");
43 }
44}