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.

read txt file

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
w
whittinghamj
Op
Posts: 103
Joined: Sun May 21, 2006 4:50 pm

read txt file

Post by whittinghamj »

Good evening yall.

I have been reading the forum's and not getting very fare. Its been one of those days. I know its on the board somewhere but I cannot find it.

I have a file which contains a user's nick and then a timestamp. We use it to keep track of when users where first seen on our channel.

The question I have is this. I want to be able to type !users and eggie goes off and lists every line in the text file eg

<User>!users
<bot>nick1 2006 05 05
<bot> nick2 2005 05 01

etc.

It does not need to re-order the lines or anything just read them out as they are shown in the txt file.

Here is an example of exactly how the text file looks.

Code: Select all

Quest 2006 05 21 19 27
Wolfie 2006 05 23 19 34
Ladybug 2006 05 23 19 38
NeXXtea 2006 05 23 19 39
Any help would be extremly helpful.

Kind Regards and god bless
User avatar
DragnLord
Owner
Posts: 711
Joined: Sat Jan 24, 2004 4:58 pm
Location: C'ville, Virginia, USA

Post by DragnLord »

Step one, have Wolfie smack you for not asking me first.
Step two, look here
w
whittinghamj
Op
Posts: 103
Joined: Sun May 21, 2006 4:50 pm

Post by whittinghamj »

no [censored] - lmfao hey man

hows it going fancy seeing you here.

cheers buddy.
w
whittinghamj
Op
Posts: 103
Joined: Sun May 21, 2006 4:50 pm

Post by whittinghamj »

drag - that just reads one file tho buddy. I need it to read / list all the lines :P
User avatar
DragnLord
Owner
Posts: 711
Joined: Sat Jan 24, 2004 4:58 pm
Location: C'ville, Virginia, USA

Post by DragnLord »

Code: Select all

set fileread "filetest"
bind pub - !users file:read

proc file:read {n u h c t} {
  set fl [open $::fileread]
  set data [read $fl]
  close $fl
  set lines [split $data \n]
  foreach x $lines {
    putserv "privmsg $c $x"
  }
}
w
whittinghamj
Op
Posts: 103
Joined: Sun May 21, 2006 4:50 pm

Post by whittinghamj »

thanks buddy - you star you :P

god bless
p
pstruh
Voice
Posts: 11
Joined: Fri Mar 04, 2005 6:34 am

Post by pstruh »

DragnLord wrote:

Code: Select all

set fileread "filetest"
bind pub - !users file:read

proc file:read {n u h c t} {
  set fl [open $::fileread]
  set data [read $fl]
  close $fl
  set lines [split $data \n]
  foreach x $lines {
    putserv "privmsg $c $x"
  }
}
Cau you help me how to read file with delay? I want to read file faster.
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

what now? delay or faster?
using

Code: Select all

  while {![eof $fl]} {
    lappend lines [gets $fi]
  }
  close $fl
would decrease memory usuage and therefore might speed up a little on really large files... but... no idea what could be faster, else you want to use some floody speed and use putquick or even putdccraw ^-^.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
p
pstruh
Voice
Posts: 11
Joined: Fri Mar 04, 2005 6:34 am

Post by pstruh »

I modify the code like that:

Code: Select all

proc file:read {n u h c t} {
  set fl [open $::fileread]
  set data [read $fl]
  set lines [split $data \n]
    while {![eof $fl]} {
        lappend lines [gets $fi]
                      }
  close $fl
  foreach x $lines {
    putquick "privmsg $c $x"
  }
}
but I cant see any different of speed reading file beetwen previous code and this code.

Is possible an error in script ....??
User avatar
De Kus
Revered One
Posts: 1361
Joined: Sun Dec 15, 2002 11:41 am
Location: Germany

Post by De Kus »

this is because the code does the same as DragnLord's code... you of course need to replace the previous reading and splitting with the new one :D.

Code: Select all

proc file:read {n u h c t} {
  set fl [open $::fileread]
  set lines [split [read $fl] \n]
  close $fl
  ...
}
But as said... due the lag from IRC you will most likely not notice anything. On small files (less than 1mb?) it is be even ~1ms slower (about half the time per iteration with time), since it has more function calls ^-^.
As mentioned... I dont know what kind of speed you except. Bots usual respond time is 1-2sec. You have to edit your source or use putdccraw to skip all queues which will get you flood kicked for sure, unless you have IRCOp control of the server the bot is connected to.

In case your bot really needs a few seconds to read the file, it must be your shells fault, since on shells I know it reads like a few lines within a few ms. So anything smal enough to be redirected to IRC should be read with both functions within a time you cannot notice as a human.

Edit: I noticed I could put together the befits of both :D. Less function calls and less memory copies :D.
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
S
Sir_Cedric_Lex2
Voice
Posts: 3
Joined: Mon Jul 03, 2006 8:30 am

Post by Sir_Cedric_Lex2 »

I have a problem with a similar tcl...
the programm reads the file, but if thers a "space" character the rest of the line ist missing

for example:

(Google) !google, !g, !search

draws only

(Google)

and the rest (!google, !g, !search) of the line is missing...

please help

greetz

Sir Cedric Lex
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

posting your script might work? :roll:
Post Reply