Ticket #63: url.diff

File url.diff, 1.4 kB (added by broderson@gmail.com, 3 years ago)

url.rb diff file

  • url.rb

    old new  
    11require 'net/http' 
    22require 'uri' 
    33require 'cgi' 
     4require 'shorturl' 
    45 
    56Url = Struct.new("Url", :channel, :nick, :time, :url) 
    67TITLE_RE = /<\s*?title\s*?>(.+?)<\s*?\/title\s*?>/im 
     
    2223    "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>" 
    2324  end 
    2425 
     26 
     27  def get_short_url(url) 
     28    surl = WWW::ShortURL.shorten(url) 
     29  end 
     30 
    2531  def get_title_from_html(pagedata) 
    2632    return unless TITLE_RE.match(pagedata) 
    2733    title = $1.strip.gsub(/\s*\n+\s*/, " ") 
     
    8692      if m.message =~ /((f|ht)tps?:\/\/.*?)(?:\s+|$)/ 
    8793        urlstr = $1 
    8894        list = @registry[m.target] 
    89  
     95        if urlstr.size > 45 
     96                short = get_short_url(urlstr) 
     97        end 
    9098        if @bot.config['url.display_link_info'] 
    9199          debug "Getting title for #{urlstr}..." 
    92100          title = get_title_for_url urlstr 
    93101          if title 
    94102            m.reply title 
     103                        m.reply "rubyurl: #{short}" if short 
    95104            debug "Title found!" 
    96105          else 
    97106            debug "Title not found!" 
     107                        m.reply "rubyurl: #{short}" if short 
    98108          end         
    99109        end 
    100110