summaryrefslogtreecommitdiffstats
path: root/modules/google.rb
diff options
context:
space:
mode:
Diffstat (limited to 'modules/google.rb')
-rw-r--r--modules/google.rb20
1 files changed, 20 insertions, 0 deletions
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 class="p" href="(.+?)u=(.+?)" >(.+?)<\/a> <\/div>/) { |useless,url,title|
+ result.push("<a href=\"#{url}\">#{CGI::escapeHTML(title)}</a>")
+ }
+ 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