From 762f732c33432c9a6f488dd5618e19b26fe47609 Mon Sep 17 00:00:00 2001 From: piernov Date: Thu, 2 Jun 2011 15:08:03 +0200 Subject: Réécrit entièrement. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/google.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 modules/google.rb (limited to 'modules/google.rb') diff --git a/modules/google.rb b/modules/google.rb new file mode 100644 index 0000000..2dff668 --- /dev/null +++ b/modules/google.rb @@ -0,0 +1,20 @@ +def module_google(msg_body, sender_nick, config) + def google(phrase) + response = Net::HTTP::get_response('www.google.fr', "/m/search?hl=fr&q=#{CGI::escape(phrase)}") + result = [] + html = Iconv.new('utf-8', 'utf-8').iconv(response.body) + html.scan(/(.+?)<\/a> <\/div>/) { |useless,url,title| + result.push("#{CGI::escapeHTML(title)}") + } + result + end + + if msg_body == "!google" + answer = "Veuillez entrer une recherche à effectuer." + return answer + elsif msg_body =~ /^!google+/ + searchresult = google(msg_body.gsub("!google ","")) + answer = searchresult[0..2].join("\n") + return answer + end +end \ No newline at end of file -- cgit v1.2.3-54-g00ecf