Ticket #63: url.diff
| File url.diff, 1.4 kB (added by broderson@gmail.com, 3 years ago) |
|---|
-
url.rb
old new 1 1 require 'net/http' 2 2 require 'uri' 3 3 require 'cgi' 4 require 'shorturl' 4 5 5 6 Url = Struct.new("Url", :channel, :nick, :time, :url) 6 7 TITLE_RE = /<\s*?title\s*?>(.+?)<\s*?\/title\s*?>/im … … 22 23 "urls [<max>=4] => list <max> last urls mentioned in current channel, urls search [<max>=4] <regexp> => search for matching urls. In a private message, you must specify the channel to query, eg. urls <channel> [max], urls search <channel> [max] <regexp>" 23 24 end 24 25 26 27 def get_short_url(url) 28 surl = WWW::ShortURL.shorten(url) 29 end 30 25 31 def get_title_from_html(pagedata) 26 32 return unless TITLE_RE.match(pagedata) 27 33 title = $1.strip.gsub(/\s*\n+\s*/, " ") … … 86 92 if m.message =~ /((f|ht)tps?:\/\/.*?)(?:\s+|$)/ 87 93 urlstr = $1 88 94 list = @registry[m.target] 89 95 if urlstr.size > 45 96 short = get_short_url(urlstr) 97 end 90 98 if @bot.config['url.display_link_info'] 91 99 debug "Getting title for #{urlstr}..." 92 100 title = get_title_for_url urlstr 93 101 if title 94 102 m.reply title 103 m.reply "rubyurl: #{short}" if short 95 104 debug "Title found!" 96 105 else 97 106 debug "Title not found!" 107 m.reply "rubyurl: #{short}" if short 98 108 end 99 109 end 100 110
