I've previously had a similar issue with someone writing in a color that made that user's text nearly unreadable to me.
There is a simple and a rather intricate method of resolution.
The simple one is something like that:
alias h_checkBackgroundColor {
return $replace($1-,$chr(3) $+ $color(background),$chr(3) $+ $color(normal).dd, $&
$chr(3) $+ $color(background).dd,$chr(3) $+ $color(normal).dd)
}
This just mulishly replaces everything and that's it.
The more detailed one is something like that:
alias h_checkBackgroundColor {
var %h_cBC_Text = $1-
var %h_cBC_num = 0123456789
;$color().dd equals $iif($len($color()) == 1,$chr(48),) $+ $color()
var %h_cBC_backgroundColor = $color(background).dd
var %h_cBC_normalColor = $color(normal).dd
;$chr(3) is the control character for ctrl+K
if ($chr(3) isin %h_cBC_Text) {
var %h_cBC_i = $count(%h_cBC_Text,$chr(3))
while (%h_cBC_i >= 1) {
var %h_cBC_pos $calc($pos(%h_cBC_Text,$chr(3),%h_cBC_i) + 1)
;checks if color code is followed by a number
if ($mid(%h_cBC_Text,%h_cBC_pos,1) isin %h_cBC_num) {
;the following is to separate that control code from the rest to make it unique,
;so that $replace only replaces this single code
;accounting for: color + , + 1-digit background (ignored then anyway)
var %h_cBC_scrap_head = $left(%h_cBC_Text,$calc(%h_cBC_pos - 1))
var %h_cBC_scrap_tail = $right(%h_cBC_Text,$calc($len(%h_cBC_Text) - (%h_cBC_pos + 3)))
var %h_cBC_scrap_in = $mid(%h_cBC_Text,%h_cBC_pos,4)
;the following is to account for single digit color codes.
var %h_cBC_scrap_first = $left(%h_cBC_scrap_in,1)
if ($mid(%h_cBC_scrap_in,2,1) !isin %h_cBC_num) {
;$chr(48) is the character also known as "0"
var %h_cBC_scrap_out = $chr(48) $+ $left(%h_cBC_scrap_in,1) $+ $right(%h_cBC_scrap_in,3)
}
else {
var %h_cBC_scrap_out = %h_cBC_scrap_in
}
;this is to check for existing background color code. else continues if there is none.
;$chr(44) is the character also known as ","
if ($mid(%h_cBC_scrap_out,3,1) == $chr(44)) && ($mid(%h_cBC_scrap_out,4,1) isin %h_cBC_num) { }
else {
;and the following is the actual text color check
if ($mid(%h_cBC_scrap_out,1,2) == %h_cBC_backgroundColor) {
set %h_cBC_scrap_out %h_cBC_normalColor $+ $right(%h_cBC_scrap_out,$calc($len(%h_cBC_scrap_out) - 2))
}
set %h_cBC_Text %h_cBC_scrap_head $+ %h_cBC_scrap_out $+ %h_cBC_scrap_tail
}
}
dec %h_cBC_i 1
}
}
return %h_cBC_Text
}
In addition to the simpler solution, this one checks for some background color codes and else does about the same thing, just a bit more manually.
One thing it does not is checking for consecutive background color codes like
While 0 may be the default background color, this would result in the third color code being replaced with the default text (aka normal) color despite the fact that it's inherited the background from the second one already. For this example, the simple and the detailed method both result in the same outcome. For a line like
their result would differ.
I know those are both pretty crude methods, basically it's just a drawn out $replace, but they should work in whatever "on TEXT/ACTION" event they're used, like
on ^*:text:*:#:{
if ($h_checkBackgroundColor($1-) !=== $1-) {
echo -t $chan < $+ $nick $+ > $h_checkBackgroundColor($1-)
haltdef
}
}
Feel free to mess with it.