Created
April 26, 2009 01:00
-
-
Save sorah/101828 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 "open-uri" | |
require "kconv" | |
#URLを渡すと、HTMLからTitleを取得し表示します。HTML以外ならcontent-typeを表示します | |
class TitleBot < Nadoka::NDK_Bot | |
# Yes person | |
def on_privmsg prefix, ch, msg | |
if /^(https?)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)$/ =~ msg | |
html = "" | |
open(msg) do |f| | |
if f.content_type == "text/html" | |
f.each_line {|n| | |
html += n | |
} | |
if /<title>(.+)<\/title>/ =~ html | |
send_notice(ch,$1.tojis) | |
else | |
send_notice(ch,"Title not found") | |
end | |
else | |
send_notice(ch, "#{msg} is not a HTML. Content-Type is #{f.content_type}") | |
end | |
end | |
end | |
#send_notice(ch, "Yes, #{prefix.nick}!") | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment