;Text cutter/colorer
;Made to keep from 'over running' the irc text buffer.
;There is no commands for this script. On any /me statement containing certain quote formats, it will activate and color them acordingly
;The script also detects if the current channel has +c (colorban) and if it does, it turns the color featuer off.
;On any post longer then 420 characters, the script will chop the text at the closest space, then post the runoff a second later.
;
;The quote coloring works like this:
; ((text)) for out of character or OOC text
; [text] for 'AI' text
; <text> for telepathic text
; "text" for normal speech text
; .oO( text ) for 'thought' bubble text (As requested by Draconia)
;
;
;I wrote this mostly for RolePlayers to stop the 'you got cut off' and such on IRC
;If you'd like more types of text quotes to be added, I can be contacted at nyghtwulf@gmail.com
;


on 1:input:*:{
  ;force script to only work with /me statements.
  ;if you would like to remove this restriction, comment out the following line,
  ;AND the marked line towards the end of this script

  ;this section turns the text coloring engine on and off.
  ;If you would like to do this manualy, comment out these lines
  ;and set %AutoFormatting to either 'ON' or 'OFF'

  if (c isincs $chan($chan).mode) {
    %AutoFormatting = OFF
  }
  else {
    %AutoFormatting = ON
  }

  ;-------------------------------------------------------------
  ;Settings for the text parser engine

  ; Modify %CutStyle to your liking.
  %CutStyle = 

  ;Modify %CStrailer to your liking.
  %CStrailer = 6 

  if ($mid(%AutoFormatting,1,1) != O) {
    %AutoFormatting = ON
  }

  ;The following sets colors and formatting for quoted text.
  ;Don't change the characters or things will look funny

  %whisperTone = 12[

  ;telepath color set
  %softTone = 4<

  ;normal speech color set
  %normalTone = "

  ;OOC color setting
  %loudTone = 10((

  ;Cloud Text
  %cloudTone = 12.oO(

  ;sets colors off at end *DO NOT CHANGE*
  %endTone = "6
  %endTone2 = >6
  %endTone3 = ]6
  %endTone4 = ))6
  %endtone5 = )6


  ; The following sets the search codes for automatic text coloring.
  ;DO NOT CHANGE BELOW THIS LINE!
  ;-----------------------------------------------------------------
  %whisperQuote = [
  %softQuote = <
  %normalQuote = "
  %loudQuote = ((
  %cloudQuote = .oO(

  %endquote = "
  %endquote2 = >
  %endquote3 = ]
  %endquote4 = ))
  %endquote5 = )

  %n = 1
  %act = 0
  %cut = 0
  %QEnc = 0
  %codes = $chr(0)
  %chr = $chr(0)

  if (($mid($1,1,2) == 6) || ($mid($1,1,1) == ") || ($mid($1,2,1) == ")) {
    %QEnc = 1
  }

  if ($1 == /me)  {
    %codes = $chr(3) $+ 6
    %act = 1
    %QEnc = 1
    %len = 424 - $len($me)
  }
  else {
    %act = 0
    %len = 430 - $len($me)
  }
  if ($len($1-) > %len) {
    %cut = 1
    while (%chr != $chr(32)) {
      %len = %len - 1
      %chr = $mid($1-,%len,1)
    }
    %scantext = $left($1-,%len)
    %lefttext = %scantext
    %cuttext = $right($1-,$mid($1-,%len,0))
  }
  else {
    %lefttext = $1-
  }

  if ((%AutoFormatting == ON) && (%QEnc == 1)) {
    %scantext = $QuoteEncode(%scantext)
    %lefttext = $QuoteEncode(%lefttext)
    %cuttext = $QuoteEncode(%cuttext)
  }

  while (%n != 0) {
    %n = $regsub(scan,%scantext,/([­]|\d{1 $+ $chr(44) $+ 2} $+ $chr(44) $+ ?\d?\d?)/,$chr(0),%scantext)
    %codes = %codes $+ $regml(scan,1)
  }
  if (%cut == 1) {
    /timerCutScript 1 1 /say %CutStyle $+  $+ %codes %cuttext
    %lefttext = %lefttext $+ %CSTrailer
  }
  if (%act == 1) {
    /me $deltok(%lefttext,1,32)
    /halt
  }
  else {
    if ($mid(%lefttext,1,1) != /) {
      /say %lefttext
      /halt
    }
  }
}
;comment out the following one line to allow the script to act on all text that is inputed


alias QuoteEncode {
  %CSQtext = $1-
  %CSQtext = $replace(%CSQtext,$chr(32) $+ %whisperQuote,$chr(32) $+ %whisperTone)
  %CSQtext = $replace(%CSQtext,$chr(32) $+ %softQuote,$chr(32) $+ %softTone)
  %CSQtext = $replace(%CSQtext,$chr(32) $+ %normalQuote,$chr(32) $+ %normalTone)
  %CSQtext = $replace(%CSQtext,$chr(32) $+ %loudQuote,$chr(32) $+ %loudTone)
  %CSQtext = $replace(%CSQtext,$chr(32) $+ %CLoudQuote,$chr(32) $+ %cloudTone)

  %CSQtext = $replace(%CSQtext,%endQuote $+ $chr(32),%endTone $+ $chr(32))
  %CSQtext = $replace(%CSQtext,%endQuote2 $+ $chr(32),%endTone2 $+ $chr(32))
  %CSQtext = $replace(%CSQtext,%endQuote3 $+ $chr(32),%endTone3 $+ $chr(32))
  %CSQtext = $replace(%CSQtext,%endQuote4 $+ $chr(32),%endTone4 $+ $chr(32))
  %CSQtext = $replace(%CSQtext,%endQuote5 $+ $chr(32),%endTone5 $+ $chr(32))
  /return %CSQtext
}
