Code:


;author Ecronika
;script On Text Theme
;version 0.4.5
;public texttheme

; User functions
; --------------

alias texttheme {
  ;syntax /texttheme
  ;description Opens the Preferences Dialog.
  ;returns null

  if (!$isid) dialog $iif($dialog(theme_setup),-v,-m theme_setup) theme_setup
}

; Internal functions
; ------------------

alias -l _regfix { return $replacex($1-,.,\.,\,\\,|,\|,$chr(123),$+(\,$chr(123)),$&
    $chr(125),$+(\,$chr(125)),$chr(91),$+(\,$chr(91)),$chr(93),$+(\,$chr(93)))
}
alias -l _text {
  var %r = /(?<= |^)(?= |$)/g
  !.echo -q $regsub($right($rawmsg,- $+ $pos($rawmsg,:,2)),%r,,%r)
  return %r
}
alias -l _ddcolor {
  var %r = /(?<=\x03\d\d,|\x03\d,|\x03)(\d)(?!\d)/g
  !.echo -q $regsub($1,%r,0\1,%r)
  return %r
}
alias -l _cnick {
  var %j $cnick(0),%i 0,%p $nick($2,$1).pnick
  while (%i < %j) {
    inc %i
    if ($cnick(%i).method == 2) continue
    if (($cnick(%i) != $null) && ($v1 !iswm $1)) continue
    if ($2) {
      if (($cnick(%i).modes != $null) && (!$regex(%p,$+(^[,$_regfix($v1),]+.*$)))) continue
      if (($cnick(%i).anymode) && (!$cnick(%i).nomode) && (%p == $1)) continue
      if (($cnick(%i).nomode) && (!$cnick(%i).anymode) && (%p != $1)) continue
      ;The Idle-Setting seems to be crap since idle=0 when a new message appears
      ;I will have to think about that option again
      if (($cnick(%i).idle) && ($calc($nick($2,$1).idle / 60) < $v1)) continue
    }
    else return $_ddcolor($iif($cnick(%i).color != $color(normal),$+(,$v1,$1,),$1))
    return $_ddcolor($iif($cnick(%i).color != $color(normal),$+(,$v1),))
  }
  if (!$2) return $1
}
alias -l _usedqwindow return $gettok($readini($mircini,options,n0),22,44)
alias -l _showmode return $gettok($readini($mircini,options,n2),30,44)
alias -l _showinactive {
  if ($1 == query) return $gettok($readini($mircini,options,n4),5,44)
}
alias -l _set {
  if ($isid) return $hget(theme_hashtable,$1)
  else hadd -m theme_hashtable $1-
}
alias -l _addquery {
  var %r     = $+(\*.*,%theme_nick,.*\*)
  !.echo -q $regex($1-,%r (.*))

  var %t     = $regml(1)
  var %n     = %theme_nick
  var %theme = $_ddcolor($_set(OnTextQuery))
  var %m     = $replace(%theme,&1;,$_cnick(%n),&2;,%t)

  echo -cmti2 no %n %m
}

; mIRC Events
; -----------

on *:start: {
  if ($hget(theme_hashtable)) hfree theme_hashtable
  hmake theme_hashtable 1

  if ($isfile($+(",$scriptdir,theme.hsh"))) hload theme_hashtable $+(",$scriptdir,theme.hsh")

  if ($null == $_set(OnTextChan))    _set OnTextChan    <&1;> &2;
  if ($null == $_set(OnTextPrivate)) _set OnTextPrivate *&1;* &2;
  if ($null == $_set(OnTextQuery))   _set OnTextQuery   <&1;> &2;
  ; if ($null == $_set(OnActionChan))  _set OnActionChan  * &1; &2;
}
on ^*:text:*:#: {
  var %n     = $nick
  var %theme = $_ddcolor($_set(OnTextChan))
  var %m     = $iif($_showmode,$left($remove($nick(#,%n).pnick,$nick),1))

  echo -cmlbfti2 no # $replace(%theme,&1;,$+($_cnick(%n,#),%m,%n,),&2;,$strip($_text,o))
  haltdef
}
/*
on ^*:action:*:#: {
  var %n     = $nick
  var %theme = $_ddcolor($_set(OnActionChan))
  var %m     = $iif($_showmode,$left($remove($nick(#,%n).pnick,$nick),1))

  echo -cmlbfti2 no # $replace(%theme,&1;,$+($_cnick(%n,#),%m,%n,),&2;,$strip($_text,o))
  haltdef
}
*/
on ^*:text:*:?: {
  var %n     = $nick
  var %theme = $_ddcolor($_set(OnTextQuery))
  var %m     = $replace(%theme,&1;,$_cnick(%n),&2;,$strip($_text,o))

  if ($query($nick)) echo -cmti2 no $nick %m
  else {

    var %theme = $_ddcolor($_set(OnTextPrivate))
    var %m     = $replace(%theme,&1;,$_cnick(%n),&2;,$strip($_text,o))

    if ($window(Message Window)) echo -cdmti2 no %m
    elseif ($_usedqwindow) { dqwindow show | echo -cdmti2 no %m }
    elseif ($cid == $activecid) && (@* !iswm $active) && ($_showinactive(query)) {
      echo -camti2 no %m
    }
    else echo -csmti2 no %m
  }
  haltdef
}
alias query {
  .query $1
  var %theme = $_ddcolor($_set(OnTextPrivate))
  set -u0 %theme_nick $1
  filter -dk _addquery $replace(%theme,&1;,$+(*,$1,*),&2;,*)
}

; GUI
; ---

dialog -l theme_setup {
  title "On Text Theme [/texttheme]"
  size -1 -1 130 66
  option dbu
  text "Channel Msg:", 1, 6 8 37 8
  edit "", 2, 46 6 78 10, autohs limit 18
  edit "", 3, 0 0 78 10, hide autohs

  text "Query Msg:", 4, 6 20 37 8
  edit "", 5, 46 18 78 10, autohs limit 18
  edit "", 6, 0 0 78 10, hide autohs

  text "Private Msg:", 7, 6 32 37 8
  edit "", 8, 46 30 78 10, autohs limit 18
  edit "", 9, 0 0 78 10, hide autohs

  button "&OK", 100, 92 46 32 13, ok
  button "&Cancel", 101, 0 0 0 0, hide cancel
}
on *:dialog:theme_setup:init:0: {
  did -o $dname 2,3 1 $_set(OnTextChan)
  did -o $dname 5,6 1 $_set(OnTextQuery)
  did -o $dname 8,9 1 $_set(OnTextPrivate)
}
on *:dialog:theme_setup:edit:2,5,8: {
  _set $gettok(OnTextChan OnTextQuery OnTextPrivate,$calc(($did +1) /3),32) $did($did)
}
on *:dialog:theme_setup:sclick:100: hsave -o theme_hashtable $+(",$scriptdir,theme.hsh")
on *:dialog:theme_setup:sclick:101: {
  _set OnTextChan $did(3)
  _set OnTextQuery $did(6)
  _set OnTextPrivate $did(9)
}