Well for starters, you don't need two routines, which they're doing the same thing anyway, per ban and unban event. This will do the trick just dandy:
on *:BAN:#:banfinder
on *:UNBAN:#:banfinder
alias -l banfinder {
var %x = 1
var %nicks = $null
while ($nick($active,%x)) {
if ($banmask iswm $ial($banmask,%x)) {
set %nicks $addtok(%nicks,$ialchan($banmask,$chan,%x).nick,32)
inc %x
}
else {
inc %x
}
}
if (%nicks == $null) { halt }
var %nicks = $replace(%nicks,$chr(32),$chr(44) $+ $chr(32))
echo -t $chan $iif($event = ban,$+($chr(3),7,Ban),$+($chr(3),7,Unban)) $&
of14 $banmask 07by14 $nick $+ ( $+ $remove($address($nick,1),*!*) $+ ) 07affects:14 %nicks $+ 07.
}