-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
47 lines (38 loc) · 1.56 KB
/
server.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
//HSBNE IRC Bot
var http = require("http"),
irc = require('irc'),
linksnip = require("linksnip"),
url = require('url'),
request = require('request');
var bot = new irc.Client('chat.freenode.net', 'HSBNEBot' || 'borkbott', {
botName: 'botbott',
userName: 'hsbnebot',
channels: ['#hsbne'],
port: 8001,
debug: true,
showerrors: true
});
var port = process.env.OPENSHIFT_NODEJS_IP || 8080;
// ip = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";
http.createServer(function(request,response){
response.writeHead(200, { "Content-Type": "text/plain" });
response.write("Hello I are IRCbot!");
response.end();
}).listen(port);
console.log("Server Running on " + port);
bot.addListener('error', function(message) {bot.say('#hsbne', message);});
bot.addListener('message', function(from, to, message) {
if( message.indexOf('http') > -1 ) {
var regex = new RegExp(/(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?/);
if ( regex.test(message)) {
var httpurl = message.match(regex);
// Request URL's title.
linksnip(httpurl[0].toString(), function(results){
bot.say(to, "Title: " + JSON.stringify(results.title, null, 2));
});
}
}
if( message.toLowerCase().indexOf('we should') > -1 ) {
bot.say(to, message.replace(/(.*?)we should/i, (from + " should") ));
}
});