-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelp-message.js
136 lines (102 loc) Β· 3.47 KB
/
help-message.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
//
// Part of XJ-1812
// License: MITA
//
exports.helpMessage = helpMessage;
exports.init = init;
var commandModules;
var commandSequence;
var name;
function init(config, theCommandModules) {
commandModules = theCommandModules;
commandSequence = config.commandSequence;
name = config.name;
}
function helpMessage(message) {
var response = "Hi! My name is " + name + " and I'm a bot. React with π€ to learn more.";
message.channel.send(response).then(function (myMessage) {
myMessage.react("π€");
var collector = myMessage.createReactionCollector((reaction, user) => reaction.emoji.name == "π€");
collector.on('collect', function (reaction) {
var user = reaction.users.last();
if (user != message.client.user) {
basicHelp(user);
}
});
});
}
function basicHelp(user) {
response = "These are some of the commands I respond to: \n\n";
commandModules.forEach(function (commandModule) {
commandModule.commands.forEach(function (command) {
if (command.includeInBasicHelp) {
response += commandHelpText(command);
response += '\n';
}
});
});
response += '\nFeel free to experiment!';
response += ' \n\nReact with π’ to see more commands as well as the command modules loaded';
user.send(response).then(function (myMessage) {
myMessage.react("π’");
var collector = myMessage.createReactionCollector((reaction, user) => reaction.emoji.name == "π’", { max: 2 });
collector.on('collect', function (reaction) {
var user = reaction.users.last();
if (user != user.client.user) {
listModules(user);
}
});
});
}
function listModules(user) {
var response = "These are the command modules I have loaded: \n";
commandModules.forEach(function (commandModule) {
if (!commandModule.hidden) {
response += "\n";
response += moduleHelpText(commandModule);
}
});
response += ' \n\nReact with π to see any hidden command modules';
user.send(response).then(function (message) {
message.react("π");
var collector = message.createReactionCollector((reaction, user) => reaction.emoji.name == "π", { max: 2 });
collector.on('collect', function (reaction) {
var user = reaction.users.last();
if (user != user.client.user) {
listHiddenModules(user);
}
});
});
}
function listHiddenModules(user) {
var response = "These are the hidden command modules I have loaded: \n";
commandModules.forEach(function (commandModule) {
if (commandModule.hidden) {
response += "\n";
response += moduleHelpText(commandModule);
}
});
user.send(response);
}
function moduleHelpText(commandModule) {
var output = "The " + commandModule.name + " module: \n";
output += commandModule.description + "\n";
commandModule.commands.forEach(function (command) {
output += commandHelpText(command);
output += '\n';
});
return output;
}
function commandHelpText(command) {
var output;
if (command.rawCommand) {
output = command.rawCommand;
}
else {
output = commandSequence + command.command;
}
if (command.usageHint) {
output += ' ' + command.usageHint;
}
return output;
}