summaryrefslogtreecommitdiff
path: root/data/rbot/plugins/googlefight.rb
diff options
context:
space:
mode:
authorRaine Virta <rane@kapsi.fi>2009-02-19 16:26:34 +0200
committerRaine Virta <rane@kapsi.fi>2009-02-19 16:26:34 +0200
commit783ffa4235330029d661752b1023db635b26f2b3 (patch)
treee60c7a89e7053120b33810230401f5490a3cb697 /data/rbot/plugins/googlefight.rb
parentff452ad1bf111025f0661274ac7fb8b2f769a293 (diff)
remove whitespace
Diffstat (limited to 'data/rbot/plugins/googlefight.rb')
-rwxr-xr-xdata/rbot/plugins/googlefight.rb18
1 files changed, 9 insertions, 9 deletions
diff --git a/data/rbot/plugins/googlefight.rb b/data/rbot/plugins/googlefight.rb
index 3f7cf5a1..0b9393ef 100755
--- a/data/rbot/plugins/googlefight.rb
+++ b/data/rbot/plugins/googlefight.rb
@@ -11,18 +11,18 @@ class GoogleFightPlugin < Plugin
def help(plugin, topic)
"googlefight <keyword 1> <keyword 2> [... <keyword n+1>] => battles given keywords based on amount of google search results and announces the winner!"
end
-
+
def fight(m, params)
keywords = parse_keywords(params)
return if keywords.nil?
-
+
keywords.map! do |k|
[k, google_count(k)]
end
-
+
m.reply output(keywords)
end
-
+
def output(result)
result = result.sort_by { |e| e[1] }.reverse
str = result.map do |kw|
@@ -31,26 +31,26 @@ class GoogleFightPlugin < Plugin
:count => kw[1].to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")
}
end.join(" vs. ")
-
+
unless result[0][1].zero?
str << _(" -- %{keyword} wins!") % {
:keyword => Bold+result[0][0]+Bold
}
else
str << _(" -- no winner here!")
- end
+ end
end
-
+
def parse_keywords(params)
str = params[:keywords].join(" ")
-
+
# foo "foo bar" bar
# no separators so assume they're all separate keywords
if str.match(/(?:"[\w\s]+"|\w+)(?: (?:"[\w\s]+"|\w+))+/)
str.scan(/"[^"]+"|\S+/).flatten
end
end
-
+
def google_count(query)
url = 'http://www.google.com/search?hl=en&safe=off&btnG=Search&q=' << CGI.escape(query)
html = Net::HTTP.get(URI.parse((url)))