Importing external modules.
var querystring = require('querystring');
var http=require('http')
var fbdata=require('./FBconnector')
This function is responsible to get message from Gary bot. Well, some of the parts of this code are kept secret, which will reveal later ;)
function getMessage(msg,name){
var post_data = querystring.stringify({
'message':msg
});
var post_options = {
host: 'THIS IS A SECRET',
port: '80',
path: 'THIS IS A SECRET',
method: 'POST',
headers: {
'Host': 'THIS IS A SECRET',
'Proxy-Connection': 'keep-alive',
'Content-Length': post_data.length,
'Cache-Control': 'max-age=0',
'Origin': 'THIS IS A SECRET',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.57 Safari/536.11',
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Referer': 'THIS IS A SECRET',
'Accept-Language': 'en-US,en;q=0.8',
'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
'Cookie': 'OUR COOKIE'
}
};
Prepare the message and send via sockets. Some kind of formatting is happening here, which will also be reveal later... :p
// Set up the request
var post_req = http.request(post_options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
//formatting portions are removed....
complete_message=chunk
var data="<tr><td class=\"image-td\"><img class=\"img\" src=\"http://dl.dropbox.com/u/51021761/chat4fun/gary.png\" "+
"title=\"Gary\"/></td><td class=\"message-td\">@"+name+" "+complete_message+"</td></tr>";
io.sockets.emit("eventB",data);
});
});
post_req.write(post_data);
post_req.end();
}
Prepare the welcome message from Gary bot to user.
function welcomeUser(name){
console.log('Gary Wlcome Msg')
var data="<tr><td class=\"image-td\"><img class=\"img\" src=\"http://dl.dropbox.com/u/51021761/chat4fun/gary.png\" "+
"title=\"Gary\"/></td><td class=\"message-td\">Welcome "+name.toString()+". If you want to talk to me, then type @gary<your message> and send.</td></tr>";
io.sockets.emit("eventB",data);
}
Export functions
exports.garyMsg=getMessage;
exports.garyWelcome=welcomeUser;