Skip to content

Instantly share code, notes, and snippets.

@sorah
Created April 26, 2009 01:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sorah/101829 to your computer and use it in GitHub Desktop.
Save sorah/101829 to your computer and use it in GitHub Desktop.
# -*-ruby-*-
require "kconv"
require "cgi"
require "open-uri"
#「gcalc: 1+1」とかするとgoogle検索で計算し結果を表示します
class GcalcBot < Nadoka::NDK_Bot
#url http://www.google.co.jp/search?q=
# Yes person
def on_privmsg prefix, ch, msg
#send_notice(ch, "Yes, #{prefix.nick}!")
if /^gcalc:(.+)$/ =~ msg
open("http://www.google.co.jp/search?q="+CGI.escape($1.toutf8)) {|f|
html = ""
f.each_line {|n| html += n}
if /<h2 class=r style="font-size:138%"><b>(.+)<\/b><\/h2>/ =~ html
result = $1
send_notice(ch,"gcalc: "+result.tojis)
else
send_notice(ch,"gcalc: error")
end
}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment