From 8ddc8ed81f1f5065705c68d2abda5804319ff981 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Wed, 25 Mar 2009 23:31:14 +0100 Subject: messagemapper: include defaults in options This change allows the use of :defaults in maps to define values for parameters which are not actually present in the map itself. We also move the initialization further down, to skip it in case of early returns. --- lib/rbot/messagemapper.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/rbot/messagemapper.rb b/lib/rbot/messagemapper.rb index 1162a3a2..c1691aff 100644 --- a/lib/rbot/messagemapper.rb +++ b/lib/rbot/messagemapper.rb @@ -535,8 +535,6 @@ class Bot return nil, "template #{@template} is not configured for private messages" if @options.has_key?(:private) && !@options[:private] && m.private? return nil, "template #{@template} is not configured for public messages" if @options.has_key?(:public) && !@options[:public] && !m.private? - options = {} - matching = @regexp.match(m.message) return nil, "#{m.message.inspect} doesn't match #{@template} (#{@regexp})" unless matching return nil, "#{m.message.inspect} only matches #{@template} (#{@regexp}) partially: #{matching[0].inspect}" unless matching[0] == m.message @@ -545,6 +543,8 @@ class Bot debug "#{m.message.inspect} matched #{@regexp} with #{debug_match}" debug "Associating #{debug_match} with dyn items #{@dyn_items.join(', ')}" + options = @defaults.dup + @dyn_items.each_with_index { |it, i| next if i == 0 item = it.name -- cgit v1.2.3