-
Notifications
You must be signed in to change notification settings - Fork 0
/
irc.js
57 lines (46 loc) · 1.58 KB
/
irc.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
var irc = require('irc'),
client,
api,
messageCallback;
exports.getApi = function() {
return api;
};
exports.start = function (callback) {
messageCallback = callback;
if (!exports.config.server) {
throw new Error("'server' must be set in config!");
}
if (!exports.config.nick) {
throw new Error("'nick' must be set in config")
}
client = new irc.Client(exports.config.server,
exports.config.nick,
exports.config || [] // This lets you simply set any custom irc node.js module's options by putting them into config, you can start with "channels", look at https://github.com/martynsmith/node-irc/blob/master/lib/irc.js for more
);
client.addListener('message', function (from, to, message) {
let event = shim.createEvent(to, from, from, message);
messageCallback(api, event);
});
// Dump errors to the console
client.addListener('error', function(message) {
console.log('error: ', message);
});
class IRCIntegration extends shim {
sendMessage(message, thread) {
client.say(thread, message);
}
getUsers(thread) {
let obj = {};
if (thread == exports.config.threadId) {
obj[exports.config.senderId] = {
name: exports.config.senderName
}
}
return obj;
}
}
api = new IRCIntegration(exports.config.commandPrefix);
};
exports.stop = function () {
client.stop();
};