Skip to content

Instantly share code, notes, and snippets.

@mateuspontes
Last active August 29, 2015 14:23
Show Gist options
  • Save mateuspontes/cde41f876aceb8781fe8 to your computer and use it in GitHub Desktop.
Save mateuspontes/cde41f876aceb8781fe8 to your computer and use it in GitHub Desktop.
GugouPI
var irc = require("irc");
var google = require('google')
var config = {
channels: ["##gurupi"],
server: "irc.freenode.net",
botName: "gugoupi"
};
var bot = new irc.Client(config.server, config.botName, {
channels: config.channels
});
bot.addListener("message", function(from, to, text, message) {
if (text.indexOf(config.botName) === 0) {
message = text.replace(config.botName, "");
console.log("é tetra!");
searcher(message, from, to);
}
});
// bot.addListener("join", function(channel, who) {
// bot.say(channel, who + "... welcome hu3 hu3!");
// });
function searcher(search, from, to) {
google.resultsPerPage = 2;
var nextCounter = 1;
google(search, function (err, next, links){
var results = []
if (err) console.error(err)
for (var i = 0; i < links.length; ++i) {
results.push(links[i].description)
}
if (nextCounter < 1) {
nextCounter += 1
if (next) next()
}
results.forEach(function(value, index, ar) {
if (value && value.length > 5) {
bot.say(to, value.replace(/(?:\\[rn]|[\r\n]+)+/g, ""));
}
});
})
}
{
"name": "ircbot",
"version": "1.0.0",
"description": "Search google and send to IRC",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "@mateuspontes",
"license": "ISC",
"dependencies": {
"google": "^1.2.0",
"irc": "^0.3.12"
},
"devDependencies": {},
"keywords": [
"nodejs",
"irc",
"google",
"bot"
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment