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 

Reading file script

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
zielik
Voice


Joined: 21 Aug 2005
Posts: 18
Location: PL

PostPosted: Thu Oct 19, 2006 10:34 am    Post subject: Reading file script Reply with quote

I have a file called file.db, it contains:

1 ~/filesys/cfg/et/lock.rar cfg_locka.ET 16104
2 ~/filesys/cfg/et/snoop.rar cfg_snoopa.Q4 18028

--EOF--

The first column is serial number, next path to the file, third description and fourth the size.

I need a script which would read this file and privmsg it to the nick that requested it.
If somebody msg my channel with !cfg.et i want him to get the list of files with .ET on the end of the description. Similar with !cfg.q4 - Q4 and !cfg.q3 Q3 and others.

Please somebody, help me.
_________________
.z!3l!k?!
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Thu Oct 19, 2006 12:04 pm    Post subject: Reply with quote

Lots of examples of doing that around the forum..Try searching.
Back to top
View user's profile Send private message
zielik
Voice


Joined: 21 Aug 2005
Posts: 18
Location: PL

PostPosted: Fri Oct 20, 2006 1:57 pm    Post subject: Reply with quote

Yea, but I don't understand them too muchan and I need somebody who would write or explain how to read and split text from a file Sad.
Please help.
_________________
.z!3l!k?!
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Fri Oct 20, 2006 3:12 pm    Post subject: Reply with quote

Code:

#################################################################################################

# USAGE:  !cfg <cfgname>  where <cfgname> is one of ET Q3 Q4, etc.

set mycfgfile "/path/to/my/file.db"

# set this to the valid cfg names to make checking user's input easier
set validcfgnames "ET Q3 Q4"

bind pub - !cfg cfgproc

proc cfgproc {nick uhost hand chan text} {
      global mycfgfile validcfgnames
      set text [split [string toupper $text]]
      if {[lsearch -exact $validcfgnames $text] == -1} {
              puthelp "PRIVMSG $nick :Invalid config filename. Valid names are $validcfgnames"
              return
      }
      if {[file exists $mycfgfile]} {
              set input [open $mycfgfile r]
              set cfgdata "[split [read $input] \n]"
              catch {close $mycfgfile}
              foreach line $cfgdata {
                   if {[lindex [split $line /] 3] == "$text"} {
                        puthelp "PRIVMSG $nick :CFG Match $line"
                   }
              }
      } else {
               puthelp "PRIVMSG $nick :no cfg file found!"
               return
      }
}

Not sure if the

if {[lindex [split $line /] 3] == "$text"}

will work, it should =)
Back to top
View user's profile Send private message
zielik
Voice


Joined: 21 Aug 2005
Posts: 18
Location: PL

PostPosted: Fri Oct 20, 2006 3:55 pm    Post subject: Reply with quote

Hmmm it doesn't seems to work ok.
When i put !cfg on chan it gives me that its invalid - thats ok.
But when i put !cfg ET it gives nothing.
My file.db looks like this:

1 ~/filesys/cfg/et/lock.rar cfg_locka.ET 16104
2 ~/filesys/cfg/et/141.willstar.rar cfg_willstart.ET 4847
3 ~/filesys/cfg/et/cfg.d4rkman30.X.04.rar cfg_d4rkman.ET 15365
4 ~/filesys/cfg/et/Cahr_18-12-04.rar cfg_cahr.ET 16479
5 ~/filesys/cfg/et/config-16-Lun4t1C.rar cfg_lun4tic.ET 10025

Maybe it doesn't read the .ET on the endof the desc.
Rosc2112 please try again :/.
_________________
.z!3l!k?!
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sat Oct 21, 2006 4:26 am    Post subject: Reply with quote

Change this:
Code:

set text [split [string toupper $text]]

and

foreach line $cfgdata {
                   if {[lindex [split $line /] 3] == "$text"} {
                        puthelp "PRIVMSG $nick :CFG Match $line"
                   }
              }

to:
Code:

set text [string toupper $text]
set text [split $text]

and

foreach line $cfgdata {
                   set cfgtmp [split $line /];set cfgtmp [string toupper [lindex $cfgtmp 3]]
                   if {$cgftmp == "$text"} {
                        puthelp "PRIVMSG $nick :CFG Match $line"
                   }
              }
Back to top
View user's profile Send private message
zielik
Voice


Joined: 21 Aug 2005
Posts: 18
Location: PL

PostPosted: Sat Oct 21, 2006 5:35 am    Post subject: Reply with quote

Thank you it works well Wink.
But how to make the bot only send to me:

#nr desc

not the whole line ?

f/e:
#1 cfg_locka.ET
_________________
.z!3l!k?!
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sat Oct 21, 2006 9:51 am    Post subject: Reply with quote

Use [split $line /] and the lindex number 4 to get just the filename, set that into a var and then use that var to show just the filename.

eg:
Code:

foreach line $cfgdata {
                   set cfgtmp [split $line /];set cfgtmp [string toupper [lindex $cfgtmp 3]]
                   set cfgnametmp [split $line /];set cfgnametmp [lindex $cfgnametmp 4]]

then puthelp $cfgnametmp instead of $line.

If you want a linecount then before the foreach put 'set lineno 0' and inside the foreach after the "if" test to see if the filename matches, put 'incr lineno' and then in the puthelp output, use puthelp "PRIVMSG $nick :$lineno $cfgnametmp"
Back to top
View user's profile Send private message
zielik
Voice


Joined: 21 Aug 2005
Posts: 18
Location: PL

PostPosted: Sun Oct 22, 2006 1:25 pm    Post subject: Reply with quote

Hmm after a few days of testing I've found another problem :/.
My scritpt looks like this right now:
Code:

#USAGE:  !cfg <cfgname>  where <cfgname> is one of ET Q3 Q4, etc.

set mycfgfile "/home/zielik/shared/filesrv/xdcc/xdcc.pack"

# set this to the valid cfg names to make checking user's input easier
set validcfgnames "ET Q3 Q4 CS CSS WSW"

bind pub - !cfg cfgproc

proc cfgproc {nick uhost hand chan text} {
      global mycfgfile validcfgnames
      set text [string toupper $text]
      set text [split $text]
      if {[lsearch -exact $validcfgnames $text] == -1} {
              puthelp "notice $nick :Invalid config filename. Valid names are $validcfgnames"
              return
      }
      if {[file exists $mycfgfile]} {
              set input [open $mycfgfile r]
              set cfgdata "[split [read $input] \n]"
              catch {close $mycfgfile}
              foreach line $cfgdata {
                   set cfgtmp [split $line /];set cfgtmp [string toupper [lindex $cfgtmp 3]]
                   if {$cfgtmp == $text} {
                        puthelp "PRIVMSG $nick :CFG Match $line"
                   } else {
         puthelp "notice $nick :no cfg file found!"
      }
              }
      }
}


And my xdcc.pack:
Code:

1 /home/zielik/filesys/cfg/et/lock.rar cfg_lock.ET 16104
2 /home/zielik/filesys/cfg/et/cfg.d4rkman30.X.04.rar cfg_d4rkman.ET 15365
3 /home/zielik/filesys/cfg/et/Sno0pCFG.rar cfg_sno0p.ET 10465
4 /home/zielik/filesys/cfg/et/nonix.rar cfg_nonix.Q4 5758


But now when I put: !cfg ET it gives me : no cfg found.
I've tried to comment some lines and I've found out that there's a problem in this line:
Code:

set cfgtmp [split $line /];set cfgtmp [string toupper [lindex $cfgtmp 3]]


Please help again . Confused
_________________
.z!3l!k?!
Back to top
View user's profile Send private message Yahoo Messenger MSN Messenger
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sun Oct 22, 2006 2:36 pm    Post subject: Reply with quote

It's just not recognizing it because of the upper/lower case, so you can either use lowercase, it use the [string toupper] command seperately to uppercase the 'ET' part of the filename, eg:

set cfgtmp [split $line /];set cfgtmp [lindex $cfgtmp 3];set cfgtmp [string toupper $cfgtmp]
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 -> Script Requests 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