Class: Muzang::Plugins::Google

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/muzang-plugins/muzang-google.rb

Instance Method Summary collapse

Methods included from Helpers

#create_database, #match, #on_channel, #on_join

Constructor Details

#initialize(bot) ⇒ Google

Returns a new instance of Google.



6
7
8
# File 'lib/muzang-plugins/muzang-google.rb', line 6

def initialize(bot)
  @bot = bot
end

Instance Method Details

#call(connection, message) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/muzang-plugins/muzang-google.rb', line 10

def call(connection, message)
  on_channel(message) do
    message.message.match(/^(!|@)google (.*?)$/) do |m|
      http = EventMachine::HttpRequest.new("http://ajax.googleapis.com/ajax/services/search/web").get :query => { :v => "1.0", :q => m[2] }
      http.callback { 
        results = JSON.parse(http.response)
        result  = results["responseData"]["results"].first
        connection.msg(message.channel, "#{result["url"]} | #{result["titleNoFormatting"]}")
      }
    end
  end
end