- # Counter to check the number of lines sent by this command
- cmd_lines = 0
- max_lines = opts[:max_lines]
- maxed = false
- line = String.new
- lines.each { |msg|
- begin
- if max_lines > 0 and cmd_lines == max_lines - 1
- truncate = opts[:truncate_text]
- truncate = @default_send_options[:truncate_text] if truncate.length > left
- truncate = "" if truncate.length > left
- maxed = true
- end
- if(left >= msg.length) and not maxed
- sendq "#{fixed}#{msg}", chan, ring
- log_sent(type, where, msg)
- cmd_lines += 1
- break
- end
- if truncate
- line.replace msg.slice(0, left-truncate.length)
- # line.sub!(/\s+\S*$/, truncate)
- line << 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)