on *:connect: {
; ######## SETUP START ########
; (re)join channels with a delay of (N in seconds):
var %delay = 10
; rejoin open channels in background ($true/$false):
var %bgjoin = $true
; ######## SETUP END #########
autojoin -s
var %t = $+(delayjoin.chans.,$cid)
; set channels to rejoin - loop open channels (if "rejoin on connect" was set in the options)
if ($hget(delayjoin.usedcids,$cid)) && ($gettok($readini($mircini,options,n2),27,44)) {
var %n = 1
while ($chan(%n)) {
hadd -m %t $v1 $iif(%bgjoin == $true,-n) $chan(%n)
inc %n
}
}
; set channels to join - loop favorites (if "enable join on connect" was set in the favorites' general options)
if ($gettok($readini($mircini,options,n4),37,44)) {
var %n = 1
while ($ini($mircini,chanfolder,%n)) {
tokenize 11 $ini.tokens(44,$!null,$readini($mircini,chanfolder,$v1))
if (!$hget(%t,$1)) && (($4 == $!null) || ($istok($noqt($4),$network,44))) && ($5 != $!null) && ($me !ison $1) {
hadd -m %t $1 $iif($6,-n) $1 $iif($3 != $!null,$3)
}
inc %n
}
}
; delayed join of all channels set - start timers
var %n = 1
while ($hget(%t,%n).data) {
$+(.timer,.delayjoin.chans.,$cid,.,%n) 1 $calc((%n -1) * %delay) JOIN $safe2u($v1)
inc %n
}
}
on *:disconnect: {
hadd -m delayjoin.usedcids $cid $true
if ($hget($+(delayjoin.chans.,$cid))) { hfree $v1 }
$+(.timer,.delayjoin.chans.,$cid,.*) off
}
alias -l ini.tokens {
var %c = $iif($1 isnum,$v1,$asc($v1)), %co = $base(%c,10,8), %null = $2
var %t = $regsubex($$3-,/(?<=^|\ $+ %co $+ )(".+?")(?=\ $+ %co $+ |$)/g,$replace(\t,$chr(%c),$chr(1)))
var %t = $regsubex(%t,/\ $+ %co $+ (?=\ $+ %co $+ )/g,$chr(%c) $+ %null )
return $replacexcs(%t,$chr(%c),$chr(11),$chr(1),$chr(%c))
}
alias safe2u { bunset &a | bset -t &a 1 $1 | return $!regsubex(safe2u, $bvar(&a,1-) ,/(\d+)(?: |$)/g,$chr(\1)) }