UNPKG

3.43 kBJavaScriptView Raw
1var formatters = require('../utils/formatters.js');
2
3exports.command = {
4 name: "help",
5 autoload: true,
6 unloadable: false,
7 min_rank: 0,
8 display: "Shows all commands or information about one of them.",
9 help: "Shows you this list of commands or detailed help for a particular command.",
10 usage: ".help, .help <command>",
11
12 execute: function(socket, command, command_access) {
13
14 var chalk = require('chalk');
15 var userRank = socket.db.rank;
16 command = command.trim();
17
18 // if command called without parameters
19 if (command.trim() === "") {
20 socket.write(chalk.blue("+-----------------------------------------------------------------------------+\r\n"));
21 socket.write(" Helpful commands on " + chalk.bold(command_access.talkername) + "\r\n");
22 socket.write(chalk.blue("+-----------------------------------------------------------------------------+\r\n"));
23
24 for (var l = 0; l <= userRank; l++) {
25 // some separation between commands of different ranks
26 socket.write(chalk.blue("| |\r\n"));
27 for (var c in command_access.commands) {
28 // show commands of level l
29 if (l == command_access.getCmdRank(c)) {
30 var cmd = command_access.commands[c].name;
31 var desc = command_access.commands[c].display;
32
33 if(cmd.length > 10) {
34 cmd = cmd.substr(0, 10);
35 }
36
37 if(desc.length > 60) {
38 desc = desc.substr(0, 57) + "...";
39 }
40
41 socket.write(chalk.blue("| " + chalk.bold("." + cmd) +
42 Array(11 - cmd.length).join(' ') + chalk.yellow(" - ") +
43 chalk.green(desc) + Array(62 - desc.length).join(' ') +
44 " |\r\n"));
45 }
46 }
47 }
48 socket.write(chalk.blue("+-----------------------------------------------------------------------------+\r\n"));
49 socket.write(chalk.blue("| " + chalk.white.bold("Remember: ") + chalk.magenta("all commands start with a dot (" + chalk.bold(".") + "), like " + chalk.blue.bold(".help")) + " |\r\n"));
50 socket.write(chalk.blue("+-----------------------------------------------------------------------------+\r\n"));
51 } else {
52 // if command called with parameters
53 var commands = command_access.findCommand(socket, command);
54 if (commands.length === 0) {
55 socket.write(chalk.yellow(":: Sorry, there is no help on that topic.\r\n"));
56 return;
57 }
58 if (commands.length > 1) {
59 var possibilities = "";
60 for (var p = 0; p < commands.length - 1; p++) {
61 possibilities += chalk.bold(commands[p].name) + ", ";
62 }
63 possibilities += chalk.bold(commands[commands.length - 1].name);
64 return socket.write(chalk.yellow(":: Found " + chalk.magenta(commands.length) + " possible help files (" + possibilities + "). Please be more specific.\r\n"));
65 }
66 var command_to_show = commands[0];
67
68 socket.write(chalk.bold("Command : ") + command_to_show.name + "\r\n");
69 socket.write(chalk.bold("Usage : ") + command_to_show.usage + "\r\n");
70 socket.write("" + "\r\n");
71 socket.write(formatters.text_wrap(command_to_show.help) + "\r\n");
72 socket.write("" + "\r\n");
73 if (command_access.getCmdRank(command_to_show.name) === 0) {
74 socket.write(chalk.bold("Level :") + " Everyone!\r\n");
75 } else {
76 socket.write(chalk.bold("Level : ") +
77 chalk.green(command_access.ranks.list[
78 command_access.getCmdRank(command_to_show.name)
79 ]) + " or greater.\r\n");
80 }
81 }
82 }
83}