-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbot.js
More file actions
91 lines (79 loc) · 2.24 KB
/
bot.js
File metadata and controls
91 lines (79 loc) · 2.24 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
90
91
var config = require("./config.js");
var irc = require("./irc/irc.js");
var fs = require('fs');
var plugins = Array();
var bot = new irc.Client(config.server, config.botName, {
channels:config.channels,
userName:config.userName,
realName:config.realName
});
bot.addListener('error', function(message) {
console.log(message);
});
// Auto Load All Plugins.
var i = 0;
require('fs').readdirSync(__dirname + '/plugins/').forEach(function(file) {
if (file.match(/.+\.js/g) !== null && file !== 'index.js') {
plugins[i] = require('./plugins/' + file);
if (typeof plugins[i].init == 'function') {
plugins[i].init(bot, config);
}
i++;
}
});
// Message Listener.
bot.addListener("message", function (from, to, text, message){
/** blacklist code **/
if(config.blacklist.length>0) {
for(var i=0;i<config.blacklist.length;i++) {
if(config.blacklist[i].toLowerCase() === from.toLowerCase()) { return; }
}
}
/** end blacklist code **/
for(var i=0;i<plugins.length;i++)
{
if(typeof plugins[i].message == 'function'){
plugins[i].message(from, to, text, message, bot, config);
}
}
});
// Join event handler.
bot.addListener("join", function (channel, nick, message) {
for(var i=0;i<plugins.length;i++)
{
if(typeof plugins[i].join == 'function'){
plugins[i].join(channel, nick, message, bot, config);
}
}
});
// Part event handler.
bot.addListener("part", function (channel, nick, message) {
for(var i=0;i<plugins.length;i++)
{
if(typeof plugins[i].part == 'function'){
plugins[i].part(channel, nick, message, bot, config);
}
}
});
// Raw event handler.
bot.addListener("raw", function (message) {
for(var i=0;i<plugins.length;i++)
{
if(typeof plugins[i].raw == 'function'){
plugins[i].raw(message, bot, config);
}
}
});
// Action event handler.
bot.addListener("action", function (from, to, message) {
for(var i=0;i<plugins.length;i++)
{
if(typeof plugins[i].action == 'function'){
plugins[i].action(from, to, message, bot, config);
}
}
});
// Load the current nicks into the config event handler.
bot.addListener("names", function (channel, nicks) {
config.nicks[channel] = Object.keys(nicks);
});