I haven't looked at your whole code, but at first glance, you could've just used one alias like this:
on *:text:*:#:relay
on *:action:*:#:relay
on *:quit:relay
on !*:join:#:relay
on !*:part:#:relay
on *:kick:#:relay
on *:rawmode:#:relay
on *:topic:#:relay
alias -l relay {
var %tok = $findtok($relay.networks,$network,1,32)
if ($chan == $gettok($relay.channels,%tok,32)) {
var %lcv = 1
var %tot = $gettok($relay.networks,0,32)
while (%lcv <= %tot) {
var %cid = $cid
var %ncid = $getcidfromnet($gettok($relay.networks,%lcv,32))
if (%ncid != %cid) {
var %net = $network
scid %ncid
msg $gettok($relay.channels,%lcv,32) $relay.fmt.part($nick,$chan,%net,$1-)
scid %cid
}
inc %lcv
}
}
}
This saves you many bytes. Again, you may need to make some needed adjustment, as I only looked at your code briefly.