-
-
Save peerau/eabab84e4e02b67cea08 to your computer and use it in GitHub Desktop.
rachael plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
class Google | |
include Cinch::Plugin | |
match /g(?:oogle)? (.+)/i | |
def execute(m, query) | |
return unless ignore_nick(m.user.nick).nil? | |
begin | |
@bitly = Bitly.new($BITLYUSER, $BITLYAPI) | |
@url = "http://www.google.com/search?q=#{CGI.escape(query)}" | |
@res = Nokogiri::HTML(open(@url)).at("h3.r") | |
def search(number) | |
title = @res.text | |
link = @res.at('a')[:href] | |
link = @bitly.shorten("http://www.google.com#{link}") | |
desc = @res.at("./following::div").children.first.text | |
"Google 2| \"%s\" %s… 2| %s" % [title, desc[0..100], link.shorten] | |
end | |
more = @bitly.shorten("http://www.google.com/search?q=#{URI.escape(query)}") | |
m.reply search(1) | |
m.reply "Google 2| More results #{more.shorten}" | |
rescue | |
p $!; puts $@.join("\n") | |
m.reply "Google 2| Error" | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment