1 Url = Struct.new("Url", :channel, :nick, :time, :url)
3 class UrlPlugin < Plugin
6 @registry.set_default(Array.new)
8 def help(plugin, topic="")
9 "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>"
12 return unless m.kind_of?(PrivMessage)
14 # TODO support multiple urls in one line
15 if m.message =~ /(f|ht)tps?:\/\//
16 if m.message =~ /((f|ht)tps?:\/\/.*?)(?:\s+|$)/
18 list = @registry[m.target]
19 # check to see if this url is already listed
20 return if list.find {|u|
23 url = Url.new(m.target, m.sourcenick, Time.new, urlstr)
24 debug "#{list.length} urls so far"
25 if list.length > 50 # TODO make this configurable
28 debug "storing url #{url.url}"
30 debug "#{list.length} urls now"
31 @registry[m.target] = list
37 channel = params[:channel] ? params[:channel] : m.target
38 max = params[:limit].to_i
41 list = @registry[channel]
43 m.reply "no urls seen yet for channel #{channel}"
45 list[0..(max-1)].each do |url|
46 m.reply "[#{url.time.strftime('%Y/%m/%d %H:%M:%S')}] <#{url.nick}> #{url.url}"
52 channel = params[:channel] ? params[:channel] : m.target
53 max = params[:limit].to_i
54 string = params[:string]
57 regex = Regexp.new(string)
58 list = @registry[channel].find_all {|url|
59 regex.match(url.url) || regex.match(url.nick)
62 m.reply "no matches for channel #{channel}"
64 list[0..(max-1)].each do |url|
65 m.reply "[#{url.time.strftime('%Y/%m/%d %H:%M:%S')}] <#{url.nick}> #{url.url}"
70 plugin = UrlPlugin.new
71 plugin.map 'urls search :channel :limit :string', :action => 'search',
72 :defaults => {:limit => 4},
73 :requirements => {:limit => /^\d+$/},
75 plugin.map 'urls search :limit :string', :action => 'search',
76 :defaults => {:limit => 4},
77 :requirements => {:limit => /^\d+$/},
79 plugin.map 'urls :channel :limit', :defaults => {:limit => 4},
80 :requirements => {:limit => /^\d+$/},
82 plugin.map 'urls :limit', :defaults => {:limit => 4},
83 :requirements => {:limit => /^\d+$/},