diff options
| author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-04-14 17:17:09 -0700 | 
|---|---|---|
| committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2014-04-14 17:17:09 -0700 | 
| commit | 77a8d4daa59b668473794d083e3bbc89eab94648 (patch) | |
| tree | 2a5b0faad87e4053725695253c8ae5f446f91ce5 /dinobot.rb | |
| parent | 81344c57f7ccba7bc1e4ef25c24f9ad832c64372 (diff) | |
| download | dinobot-77a8d4daa59b668473794d083e3bbc89eab94648.tar.gz dinobot-77a8d4daa59b668473794d083e3bbc89eab94648.tar.xz  | |
Recursive handling of piped commands.
Diffstat (limited to 'dinobot.rb')
| -rw-r--r-- | dinobot.rb | 40 | 
1 files changed, 21 insertions, 19 deletions
@@ -70,33 +70,35 @@ module Dinobot          message.sub!(@trigger, '') -        commands = nil -        mt = message.split(' | ') +        commands = parse_command(user, channel, message) -        mt.each_with_index do |m, i| -          mod = m.split.first.downcase.intern -          next unless @modules.has_key?(mod) +        exec_commands(commands) if commands.is_a?(Array) +      end +    end -          if i.zero? -            commands = @modules[mod].call(user, channel, m) -          else -            return unless commands.is_a?(Array) +    def parse_command(user, channel, message, pc=nil) +      mod = message.split.first.downcase.intern -            nc = [] +      m = message.split(' | ', 2) -            commands.each do |cmd| -              if cmd.first == :say -                nc.concat(@modules[mod].call(user, cmd[1], "#{m} #{cmd[2]}")) -              else -                nc << cmd -              end -            end +      if pc.nil? +        commands = @modules[mod].call(user, channel, m.first) +      else +        commands = [] -            commands = nc +        pc.each do |c| +          if c.first == :say +            commands.concat(@modules[mod].call(user, c[1], "#{m.first} #{c[2]}")) +          else +            commands << c            end          end +      end -        exec_commands(commands) if commands.is_a?(Array) +      if m.length == 2 +        parse_command(user, channel, m.last, commands) +      else +        commands        end      end  | 
