diff options
author | Spencer Rinehart <anubis@overthemonkey.com> | 2009-02-23 12:45:21 -0500 |
---|---|---|
committer | Giuseppe Bilotta <giuseppe.bilotta@gmail.com> | 2009-02-23 21:01:41 +0100 |
commit | 4e4a5b8a91b3a5737773aab0ed7e67180f01a982 (patch) | |
tree | 01619edcef329b819a39c582f6f5413172c7f134 /data/rbot | |
parent | ec25dc6ce941dc9d6cafe197464e390d0844d492 (diff) |
seen: If nick doesn't match exactly, fallback to a regexp search (#19).
Diffstat (limited to 'data/rbot')
-rw-r--r-- | data/rbot/plugins/seen.rb | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/data/rbot/plugins/seen.rb b/data/rbot/plugins/seen.rb index 1483062c..1a1681fb 100644 --- a/data/rbot/plugins/seen.rb +++ b/data/rbot/plugins/seen.rb @@ -8,6 +8,10 @@ define_structure :Saw, :nick, :time, :type, :where, :message class SeenPlugin < Plugin + Config.register Config::IntegerValue.new('seen.max_results', + :default => 3, :validate => Proc.new{|v| v >= 0}, + :desc => "Maximum number of seen users to return in search (0 = no limit).") + def help(plugin, topic="") "seen <nick> => have you seen, or when did you last see <nick>" end @@ -23,7 +27,17 @@ class SeenPlugin < Plugin if @registry.has_key?(m.params) m.reply seen(@registry[m.params]) else - m.reply "nope!" + rx = Regexp.new(m.params, true) + num_matched = 0 + @registry.each {|nick, saw| + if nick.match(rx) + m.reply seen(saw) + num_matched += 1 + break if num_matched == @bot.config['seen.max_results'] + end + } + + m.reply "nope!" if num_matched.zero? end end |