exports.process = function(sender, msg) { var content = msg.content.trim(); if(content.indexOf("壁纸") === 0) { content = content.substr(2).trim(); var url = "http://wallbase.cc/search?q=" + content; spider.get(url, function(data, status, respheader) { var array = getArray(data); var narr = []; if(array.length <= 3) { narr = array; for(var i = 0; i < narr.length; i++) narr[i].title = i; } else { var cur = 0; while(cur < 3) { var index = rand(arr.length - 1); while(array[index].vis) index = rand(arr.length - 1); array[index].vis = true; cur++; narr.push(array[index]); } } if(narr.length === 0) nextProcessor.process(sender, msg); else sender.sendRichContentBack(narr); }, "utf8").on("error", function(e) { nextProcessor.process(sender, msg); return; }); return true; } else return false; };
xml2js.parseString(data, function(err, json) { if(err) { nextProcessor.process(sender, msg); return true; } if(typeof json["result"] !== "object" || json["result"].count[0] < 0) { nextProcessor.process(sender, msg); return true; } json = json["result"]; if(json.count[0] != 0) { sendMusic(sender, msg, content, json); return true; } else { spider.get(url + paramstring[1], function(data, status, respheader) { xml2js.parseString(data, function(err, json) { if(err) { nextProcessor.process(sender, msg); return true; } if(typeof json["result"] !== "object" || json["result"].count[0] < 0) { nextProcessor.process(sender, msg); return true; } json = json["result"]; if(json.count[0] != 0) { sendMusic(sender, msg, content, json); } else nextProcessor.process(sender, msg); }); }); } });
exports.process = function(sender, msg) { var qs = querystring.stringify({ "text" : msg.content }); spider.get("http://xiaofengrobot.sinaapp.com/api.php?" + qs, function(data, status, respheader) { sender.sendTextBack(data.trim()); }, "utf8"); };
exports.query = function(num, company, callback) { var url = "http://baidu.kuaidi100.com/query?"; url += "type=" + company + "&"; url += "postid=" + num + "&"; var self = this; spider.get(url, function(data, status, respheader) { /** * Some error get. */ if(status !== 200) { util.callCallback(false, "Wrong status", {}, callback, self); return; } try { var json = JSON.parse(data); } catch(e) { util.callCallback(false, "Wrong data", {}, callback, self); return; } if(json["data"] === undefined) { util.callCallback(false, "Wrong data", {}, callback, self); return; } /** * OK. */ util.callCallback(true, "", json, callback, self); return; }, {}, "utf8").on("error", function(e) { util.callCallback(false, "Error while getting data: " + e.message, {}, callback, self); }); };
exports.process = function(sender, msg) { var content = msg.content.trim(); if(content.indexOf("搜歌") === 0 || content.indexOf("找歌") === 0 || content.indexOf("听歌") === 0 || content.indexOf("我要听") === 0) { if(content.indexOf("我要听") === 0) content = content.substr(3); else content = content.substr(2); content = content.trim(); /** * The API url of BAIDU. * @type {string} */ var url = "http://box.zhangmen.baidu.com/x?op=12&count=1&mtype=1&"; var param = [ { "title" : content + "$$$$$$" }, { "title" : "$$$$" + content + "$$" } ]; var paramstring = [ querystring.stringify(param[0]), querystring.stringify(param[1]) ]; /** * Fetch song information from baidu. (via song name) */ content = content.trim(); spider.get(url + paramstring[0], function(data, status, respheader) { xml2js.parseString(data, function(err, json) { if(err) { nextProcessor.process(sender, msg); return true; } if(typeof json["result"] !== "object" || json["result"].count[0] < 0) { nextProcessor.process(sender, msg); return true; } json = json["result"]; if(json.count[0] != 0) { sendMusic(sender, msg, content, json); return true; } else { spider.get(url + paramstring[1], function(data, status, respheader) { xml2js.parseString(data, function(err, json) { if(err) { nextProcessor.process(sender, msg); return true; } if(typeof json["result"] !== "object" || json["result"].count[0] < 0) { nextProcessor.process(sender, msg); return true; } json = json["result"]; if(json.count[0] != 0) { sendMusic(sender, msg, content, json); } else nextProcessor.process(sender, msg); }); }); } }); }); return true; } else return false; };