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 

extracting information from text to variables

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


Joined: 21 Apr 2012
Posts: 6

PostPosted: Sat Apr 21, 2012 9:06 pm    Post subject: extracting information from text to variables Reply with quote

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


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Sun Apr 22, 2012 2:44 am    Post subject: Re: extracting information from text to variables Reply with quote

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:


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:

!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
Back to top
View user's profile Send private message
err0r
Voice


Joined: 21 Apr 2012
Posts: 6

PostPosted: Mon Apr 30, 2012 7:43 pm    Post subject: Re: extracting information from text to variables Reply with quote

Not what i really wanted, but it has given me all i needed to get it going, many thanks willyw
Back to top
View user's profile Send private message
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Tue May 01, 2012 1:08 am    Post subject: Reply with quote

Here is a simple method to get the same thing:
Code:

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:
Quote:

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.
Back to top
View user's profile Send private message
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