- begin
- if(left >= message.length)
- sendq "#{fixed}#{message}", chan, ring
- log_sent(type, where, message)
- return
- end
- line = message.slice!(0, left)
- lastspace = line.rindex(/\s+/)
- if(lastspace)
- message = line.slice!(lastspace, line.length) + message
- message.gsub!(/^\s+/, "")
- end
- sendq "#{fixed}#{line}", chan, ring
- log_sent(type, where, line)
- end while(message.length > 0)
+
+ case opts[:overlong]
+ when :split
+ truncate = false
+ split_at = opts[:split_at]
+ when :truncate
+ truncate = opts[:truncate_text]
+ truncate = @default_send_options[:truncate_text] if truncate.length > left
+ truncate = "" if truncate.length > left
+ else
+ raise "Unknown :overlong option #{opts[:overlong]} while sending #{original_message.inspect}"
+ end
+
+ # Counter to check the number of lines sent by this command
+ cmd_lines = 0
+ max_lines = opts[:max_lines]
+ line = String.new
+ lines.each { |msg|
+ begin
+ if(left >= msg.length)
+ sendq "#{fixed}#{msg}", chan, ring
+ log_sent(type, where, msg)
+ return
+ end
+ if opts[:max_lines] and cmd_lines == max_lines - 1
+ debug "Max lines count reached for message #{original_message.inspect} while sending #{msg.inspect}, truncating"
+ truncate = opts[:truncate_text]
+ truncate = @default_send_options[:truncate_text] if truncate.length > left
+ truncate = "" if truncate.length > left
+ end
+ if truncate
+ line.replace msg.slice(0, left-truncate.length)
+ line.sub!(/\s+\S*$/, truncate)
+ raise "PROGRAMMER ERROR! #{line.inspect} of length #{line.length} > #{left}" if line.length > left
+ sendq "#{fixed}#{line}", chan, ring
+ log_sent(type, where, line)
+ return
+ end
+ line.replace msg.slice!(0, left)
+ lastspace = line.rindex(opts[:split_at])
+ if(lastspace)
+ msg.replace line.slice!(lastspace, line.length) + msg
+ msg.gsub!(/^#{opts[:split_at]}/, "") if opts[:purge_split]
+ end
+ sendq "#{fixed}#{line}", chan, ring
+ log_sent(type, where, line)
+ cmd_lines += 1
+ end while(msg.length > 0)
+ }