module Wheaties
  module Concerns
    module Messaging
      def privmsg(message, *recipients)
        broadcast(:privmsg, recipients.join(" "), :text => message)
      end
      
      def notice(message, *recipients)
        broadcast(:notice, recipients.join(" "), :text => message)
      end
      
      def action(message, recipient)
        broadcast_ctcp(recipient, :action, message)
      end
      
      protected
        def broadcast(command, *args)
          Connection.broadcast(command, *args)
        end
        
        def broadcast_ctcp(recipient, command, *args)
          broadcast(:privmsg, recipient, :text => "\001#{command.to_s.upcase} #{args.join(" ")}\001")
        end
    end
  end
end

module Wheaties
  module Concerns
    module Messaging
      def privmsg(message, *recipients)
        ircify(message, *recipients) do |message, recipients|
          broadcast(:privmsg, recipients.join(" "), :text => message)
        end
      end
      
      def notice(message, *recipients)
        ircify(message, *recipients) do |message, recipients|
          broadcast(:notice, recipients.join(" "), :text => message)
        end
      end
      
      def action(message, recipient)
        broadcast_ctcp(recipient, :action, message)
      end
      
      protected
        def broadcast(command, *args)
          Connection.broadcast(command, *args)
        end
        
        def broadcast_ctcp(recipient, command, *args)
          broadcast(:privmsg, recipient, :text => "\001#{command.to_s.upcase} #{args.join(" ")}\001")
        end
        
        def ircify(message, *recipients, &block)
          case message
          when String
            message = message.split(/[\r\n]+/)
          when Array
            message = message.map do |line|
              line.split(/[\r\n]+/)
            end.flatten
          else
            return
          end
          
          message.each do |line|
            yield line, *recipients
          end
        end
    end
  end
end

Add special handling for splitting strings and arrays before sending messages
Add special handling for splitting strings and arrays before sending messages
