aboutsummaryrefslogtreecommitdiff
path: root/dinobot.rb
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-04-14 17:17:09 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-04-14 17:17:09 -0700
commit77a8d4daa59b668473794d083e3bbc89eab94648 (patch)
tree2a5b0faad87e4053725695253c8ae5f446f91ce5 /dinobot.rb
parent81344c57f7ccba7bc1e4ef25c24f9ad832c64372 (diff)
downloaddinobot-77a8d4daa59b668473794d083e3bbc89eab94648.tar.gz
dinobot-77a8d4daa59b668473794d083e3bbc89eab94648.tar.xz
Recursive handling of piped commands.
Diffstat (limited to 'dinobot.rb')
-rw-r--r--dinobot.rb40
1 files changed, 21 insertions, 19 deletions
diff --git a/dinobot.rb b/dinobot.rb
index 03f6291..16b8573 100644
--- a/dinobot.rb
+++ b/dinobot.rb
@@ -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