aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-04-14 16:24:40 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2014-04-14 16:24:40 -0700
commit81344c57f7ccba7bc1e4ef25c24f9ad832c64372 (patch)
treea3067627efaf74987f30f732e9807c9d19e4bf1e
parent0fee37a63b588d84b4d91e5ad5074ffb71f698a4 (diff)
downloaddinobot-81344c57f7ccba7bc1e4ef25c24f9ad832c64372.tar.gz
dinobot-81344c57f7ccba7bc1e4ef25c24f9ad832c64372.tar.xz
Allow piping of commands (needs cleanup).
-rw-r--r--dinobot.rb30
-rw-r--r--test.rb10
2 files changed, 34 insertions, 6 deletions
diff --git a/dinobot.rb b/dinobot.rb
index 68c901a..03f6291 100644
--- a/dinobot.rb
+++ b/dinobot.rb
@@ -70,13 +70,33 @@ module Dinobot
message.sub!(@trigger, '')
- mod = message.split.first.downcase.intern
-
- if @modules.has_key?(mod)
- commands = @modules[mod].call(user, channel, message)
+ commands = nil
+ mt = message.split(' | ')
+
+ mt.each_with_index do |m, i|
+ mod = m.split.first.downcase.intern
+ next unless @modules.has_key?(mod)
+
+ if i.zero?
+ commands = @modules[mod].call(user, channel, m)
+ else
+ return unless commands.is_a?(Array)
+
+ nc = []
+
+ commands.each do |cmd|
+ if cmd.first == :say
+ nc.concat(@modules[mod].call(user, cmd[1], "#{m} #{cmd[2]}"))
+ else
+ nc << cmd
+ end
+ end
- exec_commands(commands) unless commands.nil?
+ commands = nc
+ end
end
+
+ exec_commands(commands) if commands.is_a?(Array)
end
end
diff --git a/test.rb b/test.rb
index bc9db29..665c21e 100644
--- a/test.rb
+++ b/test.rb
@@ -5,7 +5,7 @@ module Dinobot
def initialize
super
- @commands << :echo << :error << :timeout
+ @commands << :echo << :error << :timeout << :x3 << :wrongreturn
end
def echo(user, channel, argument)
@@ -19,5 +19,13 @@ module Dinobot
def timeout(user, channel, argument)
sleep 60
end
+
+ def x3(user, channel, argument)
+ [[:say, channel, argument]] * 3
+ end
+
+ def wrongreturn(user, channel, argument)
+ 0
+ end
end
end