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.

string map help

Help for those learning Tcl or writing their own scripts.
Post Reply
r
r0t3n
Owner
Posts: 507
Joined: Tue May 31, 2005 6:56 pm
Location: UK

string map help

Post by r0t3n »

I have:

Code: Select all

        switch -exact -- $command {
            "adduser" - "add" {
                if {![matchattr $handle nm|nm $channel]} {
                    putserv "NOTICE $nickname :Error: Only channel owners/masters can add users to $channel."
                    return
                }
                set who [string map { \\{ \\\{ \\} \\\} \\[ \\\[ \\] \\\] \\\\ \\\\\\ } [lindex $text 0]]
                #set who [join $who]
                set hand [join [lindex [split $text] 1]]
                set lev [lindex [split $text] 2]
                if {$who == ""} {
                    putserv "NOTICE $nickname :SYNTAX: ${lastbind}$command <nickname> <handle> <level> (Levels: owner, master, op, voice, ban)."
                } elseif {$hand == ""} {
                    putserv "NOTICE $nickname :SYNTAX: ${lastbind}$command <nickname> <handle> <level> (Levels: owner, master, op, voice, ban)."
                } elseif {$lev == ""} {
                    putserv "NOTICE $nickname :SYNTAX: ${lastbind}$command <nickname> <handle> <level> (Levels: owner, master, op, voice, ban)."
                } elseif {![onchan $who $channel]} {
                    putserv "NOTICE $nickname :$who isn't on $channel."
                } elseif {[validuser [nick2hand $who]]} {
                    putserv "NOTICE $nickname :$who is already known as '[nick2hand $who]'. Please use ${lastbind}access $who \?level\? to modify $who's access on $channel (Levels: owner, master, op, voice, ban)."
                } elseif {[regexp {\!|\{|\}|\[|\]|\(|\)|\"|\$|\%|\||\&|\*|^[0-9]$} $hand]} {
                    putserv "NOTICE $nickname :The handle can't contain illegal characters (!|\{|\}|\[|\]|\(|\)|\"|\$|\%|\||\&|\*)."
                } elseif {[string length $hand] < 2 || [string length $hand] > 9} {
                    putserv "NOTICE $nickname :The handle length must be between 2-9 characters long."
                } elseif {[validuser $hand]} {
                    putserv "NOTICE $nickname :Handle '$hand' is already taken. Please try again with a different handle."
                } else {
                   # adduser code here
I works 100% fine with all nicks except a nickname with a \ in it.

\\r0t3n works fine, however when \r0t3n is used, it either ends up with r0t3n or 0t3n and says user is not found on channel.

I how i get the string map to work with \

Code: Select all

set who [string map { \\{ \\\{ \\} \\\} \\[ \\\[ \\] \\\] \\\\ \\\\\\ } [lindex $text 0]]
Thanks in advance!
r0t3n @ #r0t3n @ Quakenet
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Code: Select all

set who [lindex [split $text] 0]
r
r0t3n
Owner
Posts: 507
Joined: Tue May 31, 2005 6:56 pm
Location: UK

Post by r0t3n »

I tried your fix but:

Code: Select all

[23:57:41] <r0t3n> ?adduser
[23:57:42] -p-Trojan- SYNTAX: ?adduser <nickname> <handle> <level> (Levels: owner, master, op, voice, ban).
[23:57:50] <r0t3n> ?adduser \r0t3n r0t3nn owner
[23:57:51] -p-Trojan- { isn't on #trojan.test.
current code:

Code: Select all

        switch -exact -- $command {
            "adduser" - "add" {
                if {![matchattr $handle nm|nm $channel]} {
                    putserv "NOTICE $nickname :Error: Only channel owners/masters can add users to $channel."
                    return
                }
                set who [lindex [split $text] 0]
                #set who [string map { \\{ \\\{ \\} \\\} \\[ \\\[ \\] \\\] \\\\ \\\\\\ } [lindex $text 0]]
                #if {![string equal -nocase $who [set who2 [string map { \\ \\\\\ } $who]]]} {
                #  set who [string map { " " "" } $who2]
                #}
                #set who [join $who]
                set hand [join [lindex [split $text] 1]]
                set lev [lindex [split $text] 2]
r0t3n @ #r0t3n @ Quakenet
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

[join] is applied on a list to convert it into a string. So don't apply it on a string (i.e. don't use it in 'set hand [join [lindex [split $text] 1]]').
r
r0t3n
Owner
Posts: 507
Joined: Tue May 31, 2005 6:56 pm
Location: UK

Post by r0t3n »

Code: Select all

[15:38:35] <+r0t3n> ?whois \r0t3n
[15:38:35] -p-Trojan- { is not on #trojan.test.
[15:38:41] <+r0t3n> ?whois \\r0t3n
[15:38:42] -p-Trojan- {\r0t3n} is not on #trojan.test.
?whois just uses

Code: Select all

set who [lindex [split $text] 0]

Code: Select all

            "whois" {
                if {![matchattr $handle anmovf|anmovf $channel]} {
                    puthelp "NOTICE $nickname :You are not known to me globalally or channel-wise and so you can't whois my users."
                    return
                }
                set who [lindex [split $text] 0]
                if {$who == ""} {
                    putserv "NOTICE $nickname :SYNTAX: ${lastbind}$command nickname|#handle."
                    return
                }
                if {[string index $who 0] == "#"} {
                    set who [string trimleft $who #]
                    if {![validuser $who]} {
                        putserv "NOTICE $nickname :#$who is not a validuser."
                    } else {
                        putserv "NOTICE $nickname :Handle '#$who' is added with the hostmask(s) '[join [getuser $who HOSTS] ", "]'."
                        #putserv "NOTICE $nickname :User was added by '[getuser $who added_by]' on '[clock format [getuser $who added_seconds] -format "%A %d %B %Y at %I:%M:%S %p"]'."
                        if {[matchattr $handle nm]} {
                            putserv "NOTICE $nickname :User is known with global flags ([chattr $who]) and $channel flags ([lindex [split [chattr $who | $channel] |] 1])."
                        } else {
                            putserv "NOTICE $nickname :User is known with $channel flags ([lindex [split [chattr $who | $channel] |] 1])."
                        }
                    }
                } elseif {![onchan $who $channel]} {
                    putserv "NOTICE $nickname :$who is not on $channel."
                } elseif {![validuser [nick2hand $who]]} {
                    putserv "NOTICE $nickname :\002$who\002 is not known to my database."
                } else {
                    putserv "NOTICE $nickname :User '$who' is known as '[set hand [nick2hand $who]]' with the hostmask(s) '[join [getuser $hand HOSTS] ", "]'."
                    #putserv "NOTICE $nickname :User was added by '[getuser $hand added_by]' on '[clock format [getuser $hand added_seconds] -format "%A %d %B %Y at %I:%M:%S %p"]'."
                    if {[matchattr $handle nm]} {
                        putserv "NOTICE $nickname :User is known with global flags ([chattr $hand]) and $channel flags ([lindex [split [chattr $hand | $channel] |] 1])."
                    } else {
                        putserv "NOTICE $nickname :User is known with $channel flags ([lindex [split [chattr $hand | $channel] |] 1])."
                    }
                }
            }
r0t3n @ #r0t3n @ Quakenet
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Add some putlogs in the script so you would know the values of your variables (debug it) becauase I don't see why it's taking the second element of a string as '{' where it clearly should not.
r
r0t3n
Owner
Posts: 507
Joined: Tue May 31, 2005 6:56 pm
Location: UK

Post by r0t3n »

Can i pm you with a link to the script (its a massive script, so its impossible to post it all). It's for a botservice also, so i dont want to make it public.
r0t3n @ #r0t3n @ Quakenet
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

I can't help you with a massive script because I don't have much time. However I can give you a few tips:
  • Make sure $text is a string when you're applying [split] on it and don't use [lindex] or [lrange] with strings.
  • Add lines similar to 'putlog $who' for example to know what the variable who contains
  • Try normal inputs and see the results...etc
  • Make sure you're using the correct indexes, for example in a pubm bind 0 is the command while in pub 0 is the first word after the command (in terms of [lindex [split $text] <index>])
r
r0t3n
Owner
Posts: 507
Joined: Tue May 31, 2005 6:56 pm
Location: UK

Post by r0t3n »

Ok. If i get the adduser sorted, i can fix the other commands easy. Its mainly the adduser needed to be fixed. Maybe it is something to do with how i start the proc, with string index range etc.

its a bind pubm {*} bind.

Code: Select all

bind pubm - {*} [namespace current]::central

proc service::central {nickname hostname handle channel text} {
    global botnick
    if {[lsearch -exact "$service::triggers" [string index [set option [lindex [split $text] 0]] 0]] == "-1" && ![string match -nocase $botnick $option]} {
        if {[llength $text] >= 1} {
            service::spamscan $nickname $hostname $handle $channel $text
        }
    } else {
        set cont "0"
        if {[string match -nocase $botnick $option]} {
            set lastbind "$botnick "
            set command [lindex [split $text] 1]
            set text [lrange $text 2 end]
            set cont "1"
        } else {
            set lastbind "[string index $option 0]"
            set command "[string range $option 1 end]"
            set text [lrange $text 1 end]
            set mytrig [getuser $handle XTRA mytrigger]
            if {$lastbind == "$mytrig" || ($command == "mytrigger" || $command == "mytrig" || $command == "trig" || $command == "trigger")} {
                set cont "1"
            }
        }
        #putlog "Cont = $cont"
        if {!$cont} { return }
        #putlog "Continued - Lastbind = $lastbind Command = $command Text = $text"
        switch -exact -- $command {
            "adduser" - "add" {
                if {![matchattr $handle nm|nm $channel]} {
                    putserv "NOTICE $nickname :Error: Only channel owners/masters can add users to $channel."
                    return
                }
                set who [lindex [split $text] 0]
                #set who [string map { \\{ \\\{ \\} \\\} \\[ \\\[ \\] \\\] \\\\ \\\\\\ } [lindex $text 0]]
                #if {![string equal -nocase $who [set who2 [string map { \\ \\\\\ } $who]]]} {
                #  set who [string map { " " "" } $who2]
                #}
                #set who [join $who]
                set hand [join [lindex [split $text] 1]]
                set lev [lindex [split $text] 2]
                if {$who == ""} {
                    putserv "NOTICE $nickname :SYNTAX: ${lastbind}$command <nickname> <handle> <level> (Levels: owner, master, op, voice, ban)."
                } elseif {$hand == ""} {
                    putserv "NOTICE $nickname :SYNTAX: ${lastbind}$command <nickname> <handle> <level> (Levels: owner, master, op, voice, ban)."
                } elseif {$lev == ""} {
                    putserv "NOTICE $nickname :SYNTAX: ${lastbind}$command <nickname> <handle> <level> (Levels: owner, master, op, voice, ban)."
                } elseif {![onchan $who $channel]} {
                    putserv "NOTICE $nickname :$who isn't on $channel."
                } elseif {[validuser [nick2hand $who]]} {
                    putserv "NOTICE $nickname :$who is already known as '[nick2hand $who]'. Please use ${lastbind}access $who \?level\? to modify $who's access on $channel (Levels: owner, master, op, voice, ban)."
                } elseif {[regexp {\!|\{|\}|\[|\]|\(|\)|\"|\$|\%|\||\&|\*|^[0-9]$} $hand]} {
                    putserv "NOTICE $nickname :The handle can't contain illegal characters (!|\{|\}|\[|\]|\(|\)|\"|\$|\%|\||\&|\*)."
                } elseif {[string length $hand] < 2 || [string length $hand] > 9} {
                    putserv "NOTICE $nickname :The handle length must be between 2-9 characters long."
                } elseif {[validuser $hand]} {
                    putserv "NOTICE $nickname :Handle '$hand' is already taken. Please try again with a different handle."
                } else {
                    if {[string match -nocase *users.quakenet.org [set host *![getchanhost $who $channel]]]} {
                        set host *!*@[lindex [split $host @] 1]
                    }
                    switch -exact -- $lev {
                        "owner" {
                            if {![matchattr $handle nm|n $channel]} {
                                putserv "NOTICE $nickname :Only $channel owners can add/remove owners."
                            } else {
                                adduser $hand $host
                                setuser [nick2hand $who] XTRA mytrigger "$service::trigger"
                                chattr [nick2hand $who] |+amno $channel
                                putserv "NOTICE $nickname :\002$who\002 ([nick2hand $who]) added as \002$channel owner\002."
                                putserv "NOTICE $who :\002$nickname ($handle)\002 added you as \002$channel owner\002 with the handle \002[nick2hand $who]\002 and with hostmask \002$host\002."
                                putserv "NOTICE $who :For security reasons, please type: /msg $::botnick password <password>. Your default mytrigger is set to: $service::trigger. To find out my commands, please type ${service::trigger}commands or $::botnick commands."
                                if {![isop $who $channel] && [botisop $channel]} {
                                    putquick "MODE $channel +ov $who $who"
                                }
                            }
                        }
                        "master" {
                            if {![matchattr $handle nm|n $channel]} {
                                putserv "NOTICE $nickname :Only $channel owners can add/remove masters."
                            } else {
                                adduser $hand $host
                                setuser [nick2hand $who] XTRA mytrigger "$service::trigger"
                                chattr [nick2hand $who] |+amo $channel
                                putserv "NOTICE $nickname :\002$who\002 ([nick2hand $who]) added as \002$channel master\002."
                                putserv "NOTICE $who :\002$nickname ($handle)\002 added you as \002$channel master\002 with the handle \002[nick2hand $who]\002 and with hostmask \002$host\002."
                                putserv "NOTICE $who :For security reasons, please type: /msg $::botnick password <password>. Your default mytrigger is set to: $service::trigger. To find out my commands, please type ${service::trigger}commands or $::botnick commands."
                                if {![isop $who $channel] && [botisop $channel]} {
                                    putquick "MODE $channel +ov $who $who"
                                }
                            }
                        }
                        "operator" - "op" {
                            if {![matchattr $handle nm|nm $channel]} {
                                putserv "NOTICE $nickname :Only $channel owners/masters can add/remove operators."
                            } else {
                                adduser $hand $host
                                setuser [nick2hand $who] XTRA mytrigger "$service::trigger"
                                chattr [nick2hand $who] |+ao $channel
                                putserv "NOTICE $nickname :\002$who\002 ([nick2hand $who]) added as \002$channel operator\002."
                                putserv "NOTICE $who :\002$nickname ($handle)\002 added you as \002$channel operator\002 with the handle \002[nick2hand $who]\002 and with hostmask \002$host\002."
                                putserv "NOTICE $who :For security reasons, please type: /msg $::botnick password <password>. Your default mytrigger is set to: $service::trigger. To find out my commands, please type ${service::trigger}commands or $::botnick commands."
                                if {![isop $who $channel] && [botisop $channel]} {
                                    putquick "MODE $channel +o $who"
                                }
                            }
                        }
                        "voice" - "friend" {
                            if {![matchattr $handle nm|nmo $channel]} {
                                putserv "NOTICE $nickname :Only $channel owners/msters/operators can add/remove voiced users."
                            } else {
                                adduser $hand $host
                                setuser [nick2hand $who] XTRA mytrigger "$service::trigger"
                                chattr [nick2hand $who] |+av $channel
                                putserv "NOTICE $nickname :\002$who\002 ([nick2hand $who]) added as \002$channel voice\002."
                                putserv "NOTICE $who :\002$nickname ($handle)\002 added you as \002$channel voice\002 with the handle \002[nick2hand $who]\002 and with hostmask \002$host\002."
                                putserv "NOTICE $who :For security reasons, please type: /msg $::botnick password <password>. Your default mytrigger is set to: $service::trigger. To find out my commands, please type ${service::trigger}commands or $::botnick commands."
                                if {![isvoice $who $channel] && [botisop $channel]} {
                                    putquick "MODE $channel +v $who"
                                }
                            }
                        }
                        "ban" {
                            if {![matchattr $handle nm|nm $channel]} {
                                putserv "NOTICE $nickname :Only $channel owners/masters can add/remove user bans."
                            } else {
                                adduser $hand $host
                                setuser [nick2hand $who] XTRA mytrigger "$service::trigger"
                                chattr [nick2hand $who] |+B $channel
                                putserv "NOTICE $nickname :\002$who\002 ([nick2hand $who]) added as \002$channel ban\002."
                                putserv "NOTICE $who :\002$nickname ($handle)\002 added you as \002$channel ban\002."
                                putserv "NOTICE $who :For security reasons, please type: /msg $::botnick password <password>. Your default mytrigger is set to: $service::trigger. To find out my commands, please type ${service::trigger}commands or $::botnick commands."
                                if {[onchan $who $channel] && [botisop $channel]} {
                                    set kickmsg $service::kickmsg(defaultban)
                                    if {![ischanban $channel $host]} {
                                        putserv "MODE $channel +b $host"
                                        putserv "KICK $channel $who :$kickmsg"
                                    } else {
                                        putserv "KICK $channel $who :$kickmsg"
                                    }
                                }
                            }
                        }
                        "default" {
                            if {$lev != ""} {
                                putserv "NOTICE $nickname :Invalid level '$lev'. Valid levels are: owner/master/operator/voice/ban."
                            } else {
                                putserv "NOTICE $nickname :No level specified... Usage: ${lastbind}$command $who $hand owner/master/operator/voice/ban." 
                            }
                            #adduser $hand $host
                            #putserv "NOTICE $nickname :\002$who\002 ([nick2hand $who]) successfully added to userbase."
                            #putserv "NOTICE $who :\002$nickname ($handle)\002 added you to my userbase with the handle \002[nick2hand $who]\002 and with hostmask \002$host\002."
                            #putserv "NOTICE $who :For security reasons, please type: /msg $::botnick password <password>. Your default mytrigger is set to: $service::trigger. To find out my commands, please type ${service::trigger}commands or $::botnick commands."
                        }
                    }
                }
            }
r0t3n @ #r0t3n @ Quakenet
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

You're applying [lrange] over a string, also lrange returns a list so applying [split] over it is redundant and will lead to invalid outputs. So, you should replace

Code: Select all

set text [lrange $text 2 end]
with

Code: Select all

set text [join [lrange [split $text] 2 end]]
and same for the other [lrange] statements.

How to write eggdrop scripts that won't choke on special characters.
r
r0t3n
Owner
Posts: 507
Joined: Tue May 31, 2005 6:56 pm
Location: UK

Post by r0t3n »

Thanks Sir_Fz you have saved me alot of time. I was going to give up and recode but now you saved the day :) it works 100% with \r0t3n and \\r0t3n now. Thanks again! :)
r0t3n @ #r0t3n @ Quakenet
Post Reply