diff options
author | Tom Gilbert <tom@linuxbrit.co.uk> | 2005-07-29 13:44:33 +0000 |
---|---|---|
committer | Tom Gilbert <tom@linuxbrit.co.uk> | 2005-07-29 13:44:33 +0000 |
commit | 676dd61e6b0bea5f506d064039a685944aefd6fb (patch) | |
tree | 60fa1936a11a67d6412f9db28532d623aabed5d1 /data/rbot/plugins/url.rb | |
parent | 438d56ceb82755961229d222d82a1c22ce04ab1d (diff) |
Fri Jul 29 13:07:56 BST 2005 Tom Gilbert <tom@linuxbrit.co.uk>
* Moved some stuff out of util.rb into the plugins that actually need
them. Those methods didn't belong in util as they were plugin-specific.
* moved a few more plugins to use map() where appropriate
* made the url plugin only store unique urls
Diffstat (limited to 'data/rbot/plugins/url.rb')
-rw-r--r-- | data/rbot/plugins/url.rb | 72 |
1 files changed, 29 insertions, 43 deletions
diff --git a/data/rbot/plugins/url.rb b/data/rbot/plugins/url.rb index ed82d1c1..ced92133 100644 --- a/data/rbot/plugins/url.rb +++ b/data/rbot/plugins/url.rb @@ -6,7 +6,7 @@ class UrlPlugin < Plugin @registry.set_default(Array.new) end def help(plugin, topic="") - "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>" + "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>" end def listen(m) return unless m.kind_of?(PrivMessage) @@ -14,10 +14,15 @@ class UrlPlugin < Plugin # TODO support multiple urls in one line if m.message =~ /(f|ht)tps?:\/\// if m.message =~ /((f|ht)tps?:\/\/.*?)(?:\s+|$)/ - url = Url.new(m.target, m.sourcenick, Time.new, $1) + urlstr = $1 list = @registry[m.target] + # check to see if this url is already listed + return if list.find {|u| + u.url == urlstr + } + url = Url.new(m.target, m.sourcenick, Time.new, urlstr) debug "#{list.length} urls so far" - if list.length > 50 + if list.length > 50 # TODO make this configurable list.pop end debug "storing url #{url.url}" @@ -27,45 +32,10 @@ class UrlPlugin < Plugin end end end - def privmsg(m) - case m.params - when nil - if m.public? - urls m, m.target - else - m.reply "in a private message, you need to specify a channel name for urls" - end - when (/^(\d+)$/) - max = $1.to_i - if m.public? - urls m, m.target, max - else - m.reply "in a private message, you need to specify a channel name for urls" - end - when (/^(#.*?)\s+(\d+)$/) - channel = $1 - max = $2.to_i - urls m, channel, max - when (/^(#.*?)$/) - channel = $1 - urls m, channel - when (/^search\s+(#.*?)\s+(.*)$/) - channel = $1 - string = $2 - search m, channel, string - when (/^search\s+(.*)$/) - string = $1 - if m.public? - search m, m.target, string - else - m.reply "in a private message, you need to specify a channel name for urls" - end - else - m.reply "incorrect usage: " + help(m.plugin) - end - end - def urls(m, channel, max=4) + def urls(m, params) + channel = params[:channel] ? params[:channel] : m.target + max = params[:limit].to_i max = 10 if max > 10 max = 1 if max < 1 list = @registry[channel] @@ -78,7 +48,10 @@ class UrlPlugin < Plugin end end - def search(m, channel, string, max=4) + def search(m, params) + channel = params[:channel] ? params[:channel] : m.target + max = params[:limit].to_i + string = params[:string] max = 10 if max > 10 max = 1 if max < 1 regex = Regexp.new(string) @@ -95,4 +68,17 @@ class UrlPlugin < Plugin end end plugin = UrlPlugin.new -plugin.register("urls") +plugin.map 'urls search :channel :limit :string', :action => 'search', + :defaults => {:limit => 4}, + :requirements => {:limit => /^\d+$/}, + :public => false +plugin.map 'urls search :limit :string', :action => 'search', + :defaults => {:limit => 4}, + :requirements => {:limit => /^\d+$/}, + :private => false +plugin.map 'urls :channel :limit', :defaults => {:limit => 4}, + :requirements => {:limit => /^\d+$/}, + :public => false +plugin.map 'urls :limit', :defaults => {:limit => 4}, + :requirements => {:limit => /^\d+$/}, + :private => false |