-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPlugin.js
More file actions
89 lines (72 loc) · 2.56 KB
/
Plugin.js
File metadata and controls
89 lines (72 loc) · 2.56 KB
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
var app = null;
class Plugin{
name = "Generic plugin";
pluginManager = null;
help = {}
commands = {
'help' :function(message, params){
if(params.length === 1){
let command = params[0];
console.log("Asking for help for a single command: " + command);
if(app.pluginManager.hasCommand(command)){
let plugin = app.pluginManager.getPluginForCommand(command);
message.reply(plugin.getHelpForCommand(command));
}
} else {
var helpresponse = {embed: {
color: 3447003,
title: "Kommandon:",
fields: []
}
}
app.pluginManager.getCommands().forEach((c) => {
if(c === "help"){
return;
}
var plugin = app.pluginManager.getPluginForCommand(c);
if(plugin.getHelpForCommand(c)){
let helptext = plugin.getHelpForCommand(c);
console.log("!" + c + " is " + helptext);
helpresponse.embed.fields.push(
{
name: "!" + c,
value: helptext,
inline: false
}
)
}
})
console.log("Done with help command. Sending data");
message.channel.send(helpresponse);
}
},
'contribute': function(message, params){
message.channel.send("Contribute @ https://github.com/larsemil/tentakelbot");
}
}
init(){
app = this;
console.log("Initializing " + this.name)
}
setPluginManager(PluginManager){
this.pluginManager = PluginManager;
}
getCommands(){
return Object.keys(this.commands);
}
run(command, message, params){
if(command in this.commands){
console.log("Running command " + command)
this.commands[command](message, params);
return true;
}
console.log("Could not run command " + command)
return false;
}
getHelpForCommand(command){
//console.log("Checking help for command: " + command);
var helpmessage = this.help[command] || "";
return helpmessage;
}
}
module.exports = Plugin;