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.

Reading file script

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
z
zielik
Voice
Posts: 18
Joined: Sun Aug 21, 2005 5:48 am
Location: PL

Reading file script

Post by zielik »

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?!
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Lots of examples of doing that around the forum..Try searching.
z
zielik
Voice
Posts: 18
Joined: Sun Aug 21, 2005 5:48 am
Location: PL

Post by zielik »

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 :(.
Please help.
.z!3l!k?!
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Code: Select all

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

# 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 =)
z
zielik
Voice
Posts: 18
Joined: Sun Aug 21, 2005 5:48 am
Location: PL

Post by zielik »

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?!
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Change this:

Code: Select all

set text [split [string toupper $text]] 

and 

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

Code: Select all

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"
                   }
              } 
z
zielik
Voice
Posts: 18
Joined: Sun Aug 21, 2005 5:48 am
Location: PL

Post by zielik »

Thank you it works well ;).
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?!
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

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: Select all

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"
z
zielik
Voice
Posts: 18
Joined: Sun Aug 21, 2005 5:48 am
Location: PL

Post by zielik »

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

Code: Select all

#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: Select all

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: Select all

set cfgtmp [split $line /];set cfgtmp [string toupper [lindex $cfgtmp 3]]
Please help again . :?
.z!3l!k?!
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

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]
Post Reply