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 <channel> [<max>=4] => list <max> last urls mentioned in <channel>, urls search <regexp> => search for matching urls, urls search <channel> <regexp>, search for matching urls in channel <channel>"
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+|$)/
17 url = Url.new(m.target, m.sourcenick, Time.new, $1)
18 list = @registry[m.target]
19 debug "#{list.length} urls so far"
23 debug "storing url #{url.url}"
25 debug "#{list.length} urls now"
26 @registry[m.target] = list
36 m.reply "in a private message, you need to specify a channel name for urls"
43 m.reply "in a private message, you need to specify a channel name for urls"
45 when (/^(#.*?)\s+(\d+)$/)
52 when (/^search\s+(#.*?)\s+(.*)$/)
55 search m, channel, string
56 when (/^search\s+(.*)$/)
59 search m, m.target, string
61 m.reply "in a private message, you need to specify a channel name for urls"
64 m.reply "incorrect usage: " + help(m.plugin)
68 def urls(m, channel, max=4)
71 list = @registry[channel]
73 m.reply "no urls seen yet for channel #{channel}"
75 list[0..(max-1)].each do |url|
76 m.reply "[#{url.time.strftime('%Y/%m/%d %H:%M:%S')}] <#{url.nick}> #{url.url}"
81 def search(m, channel, string, max=4)
84 regex = Regexp.new(string)
85 list = @registry[channel].find_all {|url|
86 regex.match(url.url) || regex.match(url.nick)
89 m.reply "no matches for channel #{channel}"
91 list[0..(max-1)].each do |url|
92 m.reply "[#{url.time.strftime('%Y/%m/%d %H:%M:%S')}] <#{url.nick}> #{url.url}"
97 plugin = UrlPlugin.new
98 plugin.register("urls")