I'm sure there are zillion of these, but I don't think I'm (directly) doing anyone harm by posting it. As with most little snippets like these, it's another whimsical product of my boredom.
The command is /massmode, and from the name it should be easy to guess what it does. You type in a channel status mode (voice, halfop, op, protect, owner), and it gives it to everyone on the channel who doesn't already have it, or take it from everyone who does. Valid arguments are: +v +h +o +a +q -v -h -o -a -q. You can also specify a channel if you want, but you don't have to if you use it in the same window as your desired target channel.
Update: a handful of minutes after posting. Changed the list reversal if giving modes to use a regex instead of a loop, and also excluded one's own nickname if removing modes.
Update: 7/23, added permission checking by popular request.
Update: 8/29, was reading through random old snippets and spotted a bug in this one when specifying a channel. Should be fine now.
alias massmode {
if ($istok(q a o h v,$right($$1,1),32)) && ($istok(+ -,$left($1,1),32)) var %m $right($1,1),%y $replacex(%m,q,~,a,&,o,@,h,%,v,+),%o $remove(~&@%+,%y)
else return
var %c $iif($me ison $2,$2,#),%d $replacex(%y,&,~,@,~&@,%,~&@,+,~&@%)
if (!$nick(%c,$me,%d)) {
echo -ac INFO * /massmode: You do not have the required permissions on %c
return
}
var %nicks $regsubex($str(.,$nick(%c,0)),/./g,$+($chr(32),$nick(%c,\n).pnick))
noop $regex(%nicks,/(^\ $+ %m $+ \S+|[ $+ %o ]\ $+ %y $+ \S+)/gi)
var %x 1,%s
while ($regml(%x)) {
var %s %s $remove($v1,~,&,@,%,+,$chr(32))
inc %x
}
if ($left($1,1) == +) {
var %nr $replace(%s,|,\|,[,\[,],\],\,\\,$chr(32),|),%r /^( $+ %nr $+ )(?=\s)|\s( $+ %nr $+ )(?=\s)|\s( $+ %nr $+ )$/gi
var %s $regsubex($remove(%nicks,~,&,@,%,+),%r,$null)
}
else var %s $remtok(%s,$me,32)
while ($gettok(%s,1- $+ $modespl,32)) {
mode %c $+($left($1,1),$str($right($1,1),$numtok($v1,32))) $v1
var %s $gettok(%s,$calc($modespl + 1) $+ -,32)
}
}
Alrighty, if you insist :)
I originally didn't want to because you'd need separate comparisons for each mode, and I wanted to keep it compact, so I found a more compact way to do it:
var %n $replacex($left($nick(%c,$me).pnick,1),~,4,&,3,@,3,%,2), %d $replacex(%y,~,3,&,3,@,2,%,2,+,1)
if (%n <= %d) {
echo -ac INFO * /massmode: You do not have the required permissions on %c
return
}
%c and %y of course already being set in the script. Editing the script with this addition.
Edit: made it even shorter. Not sure why I didn't use $nick before. >_>
var %d $replacex(%y,&,~,@,~&@,%,~&@,+,~&@%)
if (!$nick(%c,$me,%d)) {
echo -ac INFO * /massmode: You do not have the required permissions on %c
return
}
Normally I'd want a script like this to check that you have the correct requirements to do the command, but...
It doesn't check to see if you're an op because, quite frankly, if you're stupid enough to use it without being one after reading the description, you deserve the error messages.
I guess that makes it excusable.