Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Plugin prefix examples fixes and Google plugin example update #105

Closed
wants to merge 3 commits into from

2 participants

@FiXato

This fixes issue #98 and updates the Google plugin so it works with current Google responses.

FiXato added some commits
@FiXato FiXato Fixing incorrect prefix syntax
The prefix should be set through 'set'.
Fixes issue #98 on the original repo.
21e5a0d
@FiXato FiXato Updated google plugin example
Google's search results formatting apparently had changed at some point.
This update makes it work again.
ada5df5
@FiXato FiXato Updated the basic google example as well a311cd0
@dominikh dominikh referenced this pull request from a commit
@dominikh dominikh update the google example bots
Instead of parsing the ever-changing markup of Google, use their
deprecated API. Due to it being deprecated, it will stop working one
day, too, but at least until then it will be stable.

Closes gh-105
21442ef
@dominikh dominikh closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 1, 2012
  1. @FiXato

    Fixing incorrect prefix syntax

    FiXato authored
    The prefix should be set through 'set'.
    Fixes issue #98 on the original repo.
  2. @FiXato

    Updated google plugin example

    FiXato authored
    Google's search results formatting apparently had changed at some point.
    This update makes it work again.
  3. @FiXato
This page is out of date. Refresh to see the latest.
View
13 examples/basic/google.rb
@@ -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
View
2  examples/plugins/custom_prefix.rb
@@ -3,7 +3,7 @@
class SomeCommand
include Cinch::Plugin
- prefix /^~/
+ set :prefix, /^~/
match "somecommand"
def execute(m)
View
12 examples/plugins/google.rb
@@ -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
View
2  examples/plugins/lambdas.rb
@@ -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)
Something went wrong with that request. Please try again.