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.

extracting information from text to variables

Help for those learning Tcl or writing their own scripts.
Post Reply
e
err0r
Voice
Posts: 6
Joined: Sat Apr 21, 2012 9:00 pm

extracting information from text to variables

Post by err0r »

i have this text :
CONNECT Zet^ (~CHAT2ME.c@41-135-29-27.dsl.mweb.co.za, CHAT2ME.co.za) [41.135.29.27] has connected to the network

i would like to capture the nickname, in this case its zet^
also the ident which in this case is CHAT2ME.c
the isp which is 41-135-29-27.dsl.mweb.co.za in the example
and finally : 41.135.29.27 which is wrapped between [ ]

any help would be usefull, i understand i need lindex

thanks Err0r
w
willyw
Revered One
Posts: 1209
Joined: Thu Jan 15, 2009 12:55 am

Re: extracting information from text to variables

Post by willyw »

err0r wrote:i have this text :
CONNECT Zet^ (~CHAT2ME.c@41-135-29-27.dsl.mweb.co.za, CHAT2ME.co.za) [41.135.29.27] has connected to the network

i would like to capture the nickname, in this case its zet^
also the ident which in this case is CHAT2ME.c
the isp which is 41-135-29-27.dsl.mweb.co.za in the example
and finally : 41.135.29.27 which is wrapped between [ ]

any help would be usefull, i understand i need lindex

Code: Select all


bind pub - "!capture" captureit


proc captureit {nick uhost handle chan text} {

        set nname [lindex [split $text] 1]
        putserv "privmsg $chan :nname is: $nname"


        set temp [lindex [split $text] 2]
        set temp [string trimleft $temp ~(]

        set ident [lindex [split $temp @] 0]
        putserv "privmsg $chan :ident is: $ident"

        set isp [lindex [split $temp @] 1]
        set isp [string trimright $isp ,]
        putserv "privmsg $chan :isp is: $isp"

        set ip [lindex [split $text] 4]
        set ip [string trim $ip \[\]]
        putserv "privmsg $chan :ip is: $ip"
}
This could be condensed.

Do this in the channel with your bot:

Code: Select all

!capture CONNECT Zet^ (~CHAT2ME.c@41-135-29-27.dsl.mweb.co.za, CHAT2ME.co.za) [41.135.29.27] has connected to the network
and it will respond with the data in the manner you described.

I'm not sure what you are doing with it, but I hope this is enough of an example to get you going.

Reference :
http://www.tcl.tk/man/tcl8.5/TclCmd/contents.htm
e
err0r
Voice
Posts: 6
Joined: Sat Apr 21, 2012 9:00 pm

Re: extracting information from text to variables

Post by err0r »

Not what i really wanted, but it has given me all i needed to get it going, many thanks willyw
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Here is a simple method to get the same thing:

Code: Select all

set text [split $text]
set nickname [lindex $text 1]
scan [string trim [lindex $text 2] {(),}] {%[^@]@%s} ident isp
set ip [string trim [lindex $text 4] {[]}]
where $text is the:
CONNECT Zet^ (~CHAT2ME.c@41-135-29-27.dsl.mweb.co.za, CHAT2ME.co.za) [41.135.29.27] has connected to the network
Once the game is over, the king and the pawn go back in the same box.
Post Reply