forked from TeaLightbot/Dot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.js
More file actions
71 lines (64 loc) · 1.94 KB
/
Copy pathbot.js
File metadata and controls
71 lines (64 loc) · 1.94 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
'use strict';
var config = require('./setup/config.json');
var irc = require('irc');
var hotload = require('-hotload');
var commands = hotload('./commands');
var responses = hotload('./responses');
var helper = hotload('./helper');
var mongoCon = require('./setup/mongoConnection').connect(config.db, config.dbName);
var Q = require('q');
var express = require('express');
var app = express();
var setup = require('./setup/express')(app, config.secret);
var server = require('http').createServer(app);
var routes = require('./routes')(app);
var twitterStreams = require('./modules/twitterStreams/');
server.listen(config.httpPort);
var bot = new irc.Client(config.server, config.name, config);
var userList = {};
bot.on('join', function(channel, who) {
var text = ['Hey, ', 'Howdy, ', 'Hi, ', 'Greetings, '];
if (who !== config.name){
bot.say(channel, helper.choose(text) + who );
} else {
bot.say(channel, '...');
}
});
bot.on('message', function(from, to, text, message) {
console.log(message);
var sendTo = from;
if (to.indexOf('#') > -1) {
sendTo = to;
}
var split = text.split(' ');
var resp = null;
if (split[0].charAt(0) === '.'){
var command = split[0].split('.')[1];
try{
resp = commands[command](bot, from, to, text, split, sendTo, userList);
} catch(err){
resp = responses.parse(bot, from, split, sendTo);
}
} else {
resp = responses.parse(bot, from, split, sendTo);
}
if(resp){
bot.say(sendTo, resp);
}
});
bot.on('response', function(resp, sendTo) {
if(typeof resp === 'string') {
resp = [resp];
}
resp.forEach(function(string) {
bot.say(sendTo, string);
});
});
bot.on('names', function(channel, nicks) {
userList[channel] = nicks;
console.log(userList);
twitterStreams.query(bot);
});
bot.on('error', function(message) {
console.log('error: ', message);
});