-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
48 lines (40 loc) · 1.25 KB
/
app.js
File metadata and controls
48 lines (40 loc) · 1.25 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
var conf = require('./config');
var Bot = require('./bot/bot.js');
var webhook = require('./modules/mailchimp/webhookListener.js');
var reddit = require('./modules/reddit/reddit.js');
var http = require('http');
var URI = require('URIjs');
var bot = new Bot(conf.server, conf.nick, conf.channel);
webhook.on('subscribe', function (data, meta) {
bot.say('New subscriber joined to the mailing list!');
});
bot.onEachMessage(function(from, to, text, raw){
var link = URI.withinString(text, function(url) {
if(url){
reddit.submitLink('hacklabmikkeli', url, url);
}
return false;
});
});
bot.message('hello', function(from, to, text, raw){
bot.say('Hello world!');
});
bot.pm('hello', function (from, text, raw) {
bot.sendPm(from, 'Private hello');
});
http.createServer(function (req, res) {
if(req.method == 'POST'){
var body = '';
req.on('data', function(data) {
body += data;
if (body.length > 1e6) // If body gets too large, kill the request.
req.connection.destroy(); // (In case someone is doing naughty things like sending endless post requests)
});
req.on('end', function (){
bot.say('Hacklab door opened!');
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('ok');
});
}
}).listen(9051);
bot.start();