egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

string map help

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
r0t3n
Owner


Joined: 31 May 2005
Posts: 507
Location: UK

PostPosted: Sat Jun 23, 2007 1:03 pm    Post subject: string map help Reply with quote

I have:

Code:
        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:
set who [string map { \\{ \\\{ \\} \\\} \\[ \\\[ \\] \\\] \\\\ \\\\\\ } [lindex $text 0]]


Thanks in advance!
_________________
r0t3n @ #r0t3n @ Quakenet
Back to top
View user's profile Send private message MSN Messenger
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sat Jun 23, 2007 5:18 pm    Post subject: Reply with quote

Code:
set who [lindex [split $text] 0]

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
r0t3n
Owner


Joined: 31 May 2005
Posts: 507
Location: UK

PostPosted: Sun Jun 24, 2007 6:59 pm    Post subject: Reply with quote

I tried your fix but:

Code:
[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:
        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
Back to top
View user's profile Send private message MSN Messenger
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sun Jun 24, 2007 7:08 pm    Post subject: Reply with quote

[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]]').
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
r0t3n
Owner


Joined: 31 May 2005
Posts: 507
Location: UK

PostPosted: Mon Jun 25, 2007 10:40 am    Post subject: Reply with quote

Code:
[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:
set who [lindex [split $text] 0]


Code:
            "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
Back to top
View user's profile Send private message MSN Messenger
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Mon Jun 25, 2007 12:27 pm    Post subject: Reply with quote

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.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
r0t3n
Owner


Joined: 31 May 2005
Posts: 507
Location: UK

PostPosted: Mon Jun 25, 2007 2:18 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message MSN Messenger
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Mon Jun 25, 2007 5:14 pm    Post subject: Reply with quote

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>])

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
r0t3n
Owner


Joined: 31 May 2005
Posts: 507
Location: UK

PostPosted: Tue Jun 26, 2007 5:16 am    Post subject: Reply with quote

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:
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
Back to top
View user's profile Send private message MSN Messenger
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Tue Jun 26, 2007 6:44 am    Post subject: Reply with quote

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:
set text [lrange $text 2 end]

with
Code:
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.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
r0t3n
Owner


Joined: 31 May 2005
Posts: 507
Location: UK

PostPosted: Tue Jun 26, 2007 2:37 pm    Post subject: Reply with quote

Thanks Sir_Fz you have saved me alot of time. I was going to give up and recode but now you saved the day Smile it works 100% with \r0t3n and \\r0t3n now. Thanks again! Smile
_________________
r0t3n @ #r0t3n @ Quakenet
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber