From 81344c57f7ccba7bc1e4ef25c24f9ad832c64372 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Mon, 14 Apr 2014 16:24:40 -0700 Subject: Allow piping of commands (needs cleanup). --- dinobot.rb | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'dinobot.rb') 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 -- cgit v1.2.3-70-g09d2