Plugin prefix examples fixes and Google plugin example update #105

Closed
wants to merge 3 commits into
from
@@ -14,16 +14,17 @@
# Extremely basic method, grabs the first result returned by Google
# or "No results found" otherwise
def google(query)
- url = "http://www.google.com/search?q=#{CGI.escape(query)}"
- res = Nokogiri::HTML(open(url)).at("h3.r")
+ url = "https://www.google.com/search?q=#{CGI.escape(query)}"
+ res = Nokogiri::HTML(open(url)).at(".s")
- title = res.text
- link = res.at('a')[:href]
- desc = res.at("./following::div").children.first.text
+ title = res.at('cite b').text
+ link = res.at('cite').text
+ desc = res.at('.st').text
+ CGI.unescape_html "#{title} - #{desc} (#{link})".dup.force_encoding('binary')
rescue
"No results found"
else
- CGI.unescape_html "#{title} - #{desc} (#{link})"
+ CGI.unescape_html "#{title} - #{desc} (#{link})".dup.force_encoding('binary')
end
end
@@ -3,7 +3,7 @@
class SomeCommand
include Cinch::Plugin
- prefix /^~/
+ set :prefix, /^~/
match "somecommand"
def execute(m)
@@ -8,13 +8,13 @@ class Google
match /google (.+)/
def search(query)
- url = "http://www.google.com/search?q=#{CGI.escape(query)}"
- res = Nokogiri::HTML(open(url)).at("h3.r")
+ url = "https://www.google.com/search?q=#{CGI.escape(query)}"
+ res = Nokogiri::HTML(open(url)).at(".s")
- title = res.text
- link = res.at('a')[:href]
- desc = res.at("./following::div").children.first.text
- CGI.unescape_html "#{title} - #{desc} (#{link})"
+ title = res.at('cite b').text
+ link = res.at('cite').text
+ desc = res.at('.st').text
+ CGI.unescape_html "#{title} - #{desc} (#{link})".dup.force_encoding('binary')
rescue
"No results found"
end
@@ -9,7 +9,7 @@ class DirectAddressing
#
# The reason we are using a lambda is that the bot's nick can change
# and the prefix has to be up to date.
- prefix lambda{ |m| Regexp.new("^" + Regexp.escape(m.bot.nick + ": " ))}
+ set :prefix, lambda{ |m| Regexp.new("^" + Regexp.escape(m.bot.nick + ": " ))}
match "hello", method: :greet
def greet(m)