forked from TeaLightbot/Dot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
86 lines (75 loc) · 2.31 KB
/
bot.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
'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 = {};
var previousMessage = [''];
var previousCommand = [''];
var count = 1;
console.log();
bot.on('join', function (channel, who) {
bot.say(channel, 'HeyGuys');
});
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);
previousCommand = [command];
} catch (err) {
resp = responses.parse(bot, from, split, sendTo);
}
} else {
resp = responses.parse(bot, from, split, sendTo);
}
if (resp) {
bot.say(sendTo, resp);
if (resp === '*BANG!*') {
bot.say(sendTo, '.timeout ' + from + ' 30');
}
}
});
bot.on('response', function (resp, sendTo) {
if (typeof resp === 'string') {
resp = [resp];
}
if (previousMessage[0] !== resp[0]
|| previousCommand[0] === 'ud'
|| previousCommand[0] === 'list'
|| previousCommand[0] === 'getRankedConqStats'
|| previousCommand[0] === 'getGeneralStats') {
previousCommand[0] = '';
previousMessage[0] = resp[0];
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);
});