Avoid using
args as it has a special meaning in TCL.
I would also replace this loop:
Code: Select all
foreach chan [channels] {
if {![onchan $nick $chan] || ![channel get $chan checkisauth] || [validuser [nick2hand $nick]] || [isop $nick $chan] || [isvoice $nick $chan]} {return}
putquick "MODE $chan +v $nick"
}
with something that would make sense. First don't use
return inside a loop, instead use
continue or a
break.
Since the
validuser check isn't tied to the list of channels you loop on it would be a good idea to take it outside the loop since the first result would be the same for every channel in the channels list.
I would put the check of
checkisauth channel flag first since that's the fist mandatory check, then continue with
onchan because if the given nick isn't on the channel the the other two (
isop and
isvoice) would fail anyway. I would also opt with a slower queue like
pushmode.
Code: Select all
if ([validuser [nick2hand $nick]]) return
foreach chan [channels] {
if (![channel get $chan checkisauth] || ![onchan $nick $chan] || [isop $nick $chan] || [isvoice $nick $chan]} continue
pushmode $chan +v $nick
}
Your
authcheck:pub is a mess as well. There's no need for
[nick2hand $nick] since you already got this information in
$hand in if {[matchattr [nick2hand $nick] $regsetflags $chan]} { line.
You execute
[lindex [split $arg] 0] 3 times when can set it to a variable and access that variable as many times you wish. Same goes with
[channel get $chan checkisauth] but is only called 2 times.
Code: Select all
if {[lindex [split $arg] 0] == "on"} {
will fail if the user input is ON, oN or On for instance. Either use a
string equal -nocase or go with a
string tolower.
There's no need for this:
Code: Select all
global regsetflags
if {[matchattr [nick2hand $nick] $regsetflags $chan]} {
When you can alter the bind line to make it trigger only for the
$regsetflags you set, so instead of:
Code: Select all
bind pub - ${checkisregtrig}checkisreg authcheck:pub
go with:
Code: Select all
bind pub $regsetflags ${checkisregtrig}checkisreg authcheck:pub
Here is how I would do this:
Code: Select all
proc authcheck:pub {nick uhost hand chan text} {
if {[scan $text {%s} mode] != 1} {
puthelp "PRIVMSG $chan :\037ERROR\037: Incorrect Parameters. \037SYNTAX\037: [isregTrigger]checkisreg on|off"
return
}
set status [channel get $chan checkisauth]
switch -- [string tolower $mode] {
"on" {
if {$status} {
puthelp "PRIVMSG $chan :\037ERROR\037: This setting is already enabled."
} else {
channel set $chan +checkisauth
puthelp "PRIVMSG $chan :Enabled Automatic Register Checking for $chan"
}
}
"off" {
if {!$status} {
puthelp "PRIVMSG $chan :\037ERROR\037: This setting is already disabled."
} else {
channel set $chan -checkisauth
puthelp "PRIVMSG $chan :Disabled Automatic Register Checking for $chan"
}
}
default {
puthelp "PRIVMSG $chan :\037ERROR\037: $mode is not an accepted parameter. \037SYNTAX\037: [isregTrigger]checkisreg on|off"
}
}
}
I opted for
switch as it gives me a default option where if any of the available isn't triggered will have the default one kick in.
Based on above code you can easily make the same adjustments for
authcheck:msg function with two changes:
Code: Select all
if {[scan $text {%s%s} mode channel] != 2} {
and instead of the silly:
where I take it you want to see if the given
$channel starts with a # then go with:
Code: Select all
if {![string first # $channel]} {
# all good, at least channel name starts with an #
} else {
# the result should be 0, but in our case is either -1 if not present or 1+ then alert or whatever you wish
}
and can also throw in a valid channel check:
Code: Select all
if {![validchan $chan]} {
# channel not valid
} else {
# channel is valid, all is ok proceed as you wish
}
Once the game is over, the king and the pawn go back in the same box.