]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/blobdiff - lib/rbot/messagemapper.rb
Try to read old language-agnostic lart/praises if language-specific ones are not...
[user/henk/code/ruby/rbot.git] / lib / rbot / messagemapper.rb
index bb193cbf17ea5823a88e4ec1bc630e6cbaecb7b8..ec465e812ed86f77fef494045a6ea9756a114723 100644 (file)
@@ -240,11 +240,11 @@ module Irc
       raise ArgumentError, "template #{str.inspect} should be a String" unless str.kind_of?(String)
 
       # split and convert ':xyz' to symbols
-      items = str.strip.split(/\s+/).collect { |c|
+      items = str.strip.split(/\]?\s+\[?/).collect { |c|
+        # there might be extra (non-alphanumeric) stuff (e.g. punctuation) after the symbol name
         if /^(:|\*)(\w+)(.*)/ =~ c
-          # there might be extra (non-alphanumeric) stuff (e.g. punctuation) after the symbol name
           sym = ($1 == ':' ) ? $2.intern : "*#{$2}".intern
-          if $3.nil?
+          if $3.empty?
             sym
           else
             [sym, $3]
@@ -305,8 +305,9 @@ module Irc
       return nil, "#{m.message.inspect} doesn't match #{@dyn_items.first.inspect} (#{@regexp})" unless matching
       return nil, "#{m.message.inspect} only matches #{@dyn_items.first.inspect} (#{@regexp}) partially" unless matching[0] == m.message
 
-      debug "#{m.message.inspect} matched #{@regexp} with #{matching[1..-1].join(', ')}"
-      debug "Associating #{matching[1..-1].join(', ')} with dyn items #{@dyn_items[1..-1].join(', ')}"
+      debug_match = matching[1..-1].collect{ |d| d.inspect}.join(', ')
+      debug "#{m.message.inspect} matched #{@regexp} with #{debug_match}"
+      debug "Associating #{debug_match} with dyn items #{@dyn_items[1..-1].join(', ')}"
 
       (@dyn_items.length - 1).downto 1 do |i|
         it = @dyn_items[i]
@@ -329,19 +330,15 @@ module Irc
             case default
             when String
               value.instance_variable_set(:@string_value, default)
-              def value.to_s
-                @string_value
-              end
             else
-              def value.to_s
-                value.join(' ')
-              end
+              value.instance_variable_set(:@string_value, value.join(' '))
             end
           else
             value = matching[i].split
-            def value.to_s
-              matching[i]
-            end
+            value.instance_variable_set(:@string_value, matching[i])
+          end
+          def value.to_s
+            @string_value
           end
           options[item] = value
           debug "set #{item} to #{value.inspect}"
@@ -357,7 +354,7 @@ module Irc
             end
           else
             value = @defaults[item]
-            warning "No default value for optiona #{item.inspect} specified" unless @defaults.has_key?(item)
+            warning "No default value for option #{item.inspect} specified" unless @defaults.has_key?(item)
           end
           options[item] = value
           debug "set #{item} to #{options[item].inspect}"