This is just a simple script I decided to share that parts all channels except the ones that you have listed. Put this in the remotes of your bot. in the owners alias, put all the hosts that are allowed to trigger the command, separated by spaces.
I appreciate any comments and feedback.
alias blockpart { /return }
;put the #channels that you don't want it to part separated by spaces after /return
alias owners { /return }
;dont forget to put the nicknames of the owners
alias partchans {
/set %x $ComChan($me,0)
while (%x) {
/set %y $comchan($me,%x)
if (!$istok($blockpart,%y,32)) { /part %y }
dec %x
}
}
on $*:TEXT:/^[.@!]partall/Si:#: {
if ( $istok($owners,$wildsite,32) ) { /partchans }
}
There are various ways to go about this:
(Tokenize method with regsubex loop)
alias example1 {
var %b #chan1 #chan2 #chan3 #chan4
tokenize 32 $regsubex($str(.,$chan(0)),/./g,$&
$iif(!$istok(%b,$chan(\n),32),$chan(\n)) $chr(32))
part $*
}
(WorldDMT's $addtok 44 suggestion)
alias example2 {
var %a 1, %b #chan1 #chan2 #chan3 #chan4
while $chan(%a) {
var %y $v1
if !$istok(%b,%y,32) {
var %c $addtok(%c,%y,44)
}
inc %a
}
tokenize 44 %c
part $*
}
(Multiple target method if your network supports it)
alias example3 {
var %a 1, %b #chan1 #chan2 #chan3 #chan4
while $chan(%a) {
var %y $v1
if !$istok(%b,%y,32) {
var %c $addtok(%c,%y,44)
}
inc %a
}
part %c
}
(Negative loop)
alias example4 {
var %x $chan(0), %b #chan1 #chan2 #chan3 #chan4
while %x {
var %y $chan(%x)
if !$istok(%b,%y,32) {
part %y
}
dec %x
}
}
(Positive loop)
alias example5 {
var %x 1, %b #chan1 #chan2 #chan3 #chan4
while $chan(%x) {
var %y $v1
if !$istok(%b,$v1,32) {
part %y
}
inc %x
}
}
You snippet is still at risk of being taken over. If I cloned an owner's nick successfully, I could command your bot to part all the channels.
if ($istok($owners,$wildsite,32)) { <- this is still recommended.
Then add all of their hosts in your owners alias.
Again, you don't need to use /set
Using global var will set the vars and leave them behind in your variables.
Use /var instead, so the variables will get themselves unset after they finish their routines.
var %x = $ComChan($me,0)
var %y = $ComChan($me,%x)
You can just use $chan(0)
Your regex is missing > /iS without it, it won't work:
alias partchans {
var %x = $chan(0)
while (%x) {
var %y = $chan(%x)
if (!$istok($blockpart,%y,32)) { part %y }
dec %x
}
}
on $*:text:/[!@.]partall/iS:#: {
if ($wildsite == *!*@YOURHOST) { partchans }
}
alias -l blockpart { return #chan #chan1 #chan2 }
And you can use the local var instead of the global ones.