This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Ban user

Help for those learning Tcl or writing their own scripts.
Post Reply
G
GeeX
Voice
Posts: 29
Joined: Mon Sep 19, 2005 4:29 am

Ban user

Post by GeeX »

Can you tell why it says: set protection(banuser) [lindex [split $arg] 0] ...": variable references require preceding $
when I use this proc?

Code: Select all

        proc protection:ban { nick host hand chan arg } {
            global protection
            if {![channel get $chan protection(flag)]} {
                putserv "NOTICE $nick :Error. Protection is disabled. Enable it by typing $protection(trigger)protection on in order to use ban."
                return
            } elseif {$arg == ""} {
                putserv "NOTICE $nick :Error. Wrong syntax. Use $protection(trigger)ban 'nick' 'duration' 'reason'."
            } elseif {
                set protection(banuser) [lindex [split $arg] 0]
                set protection(banhost) "*![getchanhost $protection(banuser) $chan]"
                set protection(duration) [lindex [split $arg] 1]
                set protection(reason) [join [lrange [split $arg] 2 end]]
                if {![isnumber $protection(duration)]} {
                    set protection(reason) [join [lrange [split $arg] 1 end]]
                    set protection(duration) "60"
                }
                if {![onchan $protection(banuser) $chan] && ![string match "*!*" $protection(banuser)} {
                    set protection(banhost) "$protection(banuser)*!*@"
                    putquick "MODE $chan +b $protection(banhost)"
                    putserv "NOTICE $nick :Done. $protection(banhost) successfully added."
                }
                if {[string match "*!*" $protection(banuser)] && [matchattr [nick2hand $nick] n|n $chan]} {
                    set protection(banhost) "$protection(banuser)"
                    if {$protection(banhost) == "*!*@*"} {
                        return
                    } else {
                        putquick "mode $chan +b $protection(banhost)"
                        putserv "NOTICE $nick :Done. $protection(banhist) successfully added."
                    }
                }
                if {[isbot $protection(banuser)]} {
                    putserv "NOTICE $nick :Error. You cannot ban the bot."
                    return
                }
                if {[matchattr [nick2hand $nick] o|o $chan] && [matchattr [nick2hand $protection(banuser)] mn|mn $chan]} {
                    putserv "NOTICE $nick :Error. You cannot ban $protection(banuser) from $chan (higher access level)."
                    return
                }
                if {[matchattr [nick2hand $nick] m|m $chan] && [matchattr [nick2hand $protection(banuser)] n|n $chan]} {
                    putserv "NOTICE $nick :Error. You cannot ban $protection(banuser) from $chan (higher access level)."
                    return
                }
                if {[isdynamicip $protection(banhost)]} {
                    set protection(banhost) "[maskhost $protection(banhost)]"
                }
                set protection(id) [channel get $chan "$protection(kickid)"]
                incr protection(id)
                channel set $chan protection(kickid) "$protection(id)"
                regsub -all -- {:reason:} $protection(kickmsg) $protection(reason) protection(kickmsg)
                regsub -all -- {:id:}     $protection(kickmsg) $protection(id) protection(kickmsg)
                newchanban $chan $protection(banhost) $handle "$protection(kickmsg)" $protection(duration)
                putquick "KICK $chan $protection(banuser) :$protection(kickmsg)"
            }
        }
User avatar
Sir_Fz
Revered One
Posts: 3793
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Show us the info from .set errorInfo.
G
GeeX
Voice
Posts: 29
Joined: Mon Sep 19, 2005 4:29 am

Post by GeeX »

Errorinfo:

Code: Select all

result: syntax error in expression " 
set protection(banuser) [lindex [split $arg...": variable references require preceding $  
("if" test expression)  
while compiling 
"if {![channel get $chan protection(flag)]} { 
putserv "NOTICE $nick :Error. Protection is disabled. Enable it by typing $protection(tri..." 
(compiling body of proc "protection:ban", line 3) 
invoked from within  
"protection:ban $_pub1 $_pub2 $_pub3 $_pub4 $_pub5" 
User avatar
Sir_Fz
Revered One
Posts: 3793
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Try changing

Code: Select all

if {![channel get $chan protection(flag)]} {
to

Code: Select all

if {![channel get $chan $protection(flag)]} {
G
GeeX
Voice
Posts: 29
Joined: Mon Sep 19, 2005 4:29 am

Post by GeeX »

Doens't work :(
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

This is a really stupid mistake. It took me looking 3 times at it to find it. And I only found it, because I recognized that this error can only occur within if expressions and the I noticed something:

Code: Select all

} elseif {
this is supposed to be just an "else", it tries to evaluate the whole body after elseif as an if expression. therefore the string "set" without an equalizer operator doesnt make any sense for if and returns an error for the whole line which starts with the first line.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
G
GeeX
Voice
Posts: 29
Joined: Mon Sep 19, 2005 4:29 am

Post by GeeX »

Thanks, i solved the problem ;)
Post Reply