Skip to content

Instantly share code, notes, and snippets.

@sorah
Created April 26, 2009 01:00
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/101828 to your computer and use it in GitHub Desktop.
Save sorah/101828 to your computer and use it in GitHub Desktop.
# -*-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