Created
April 26, 2009 01:01
-
-
Save sorah/101829 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*-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