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 

read txt file

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


Joined: 21 May 2006
Posts: 103

PostPosted: Thu May 25, 2006 10:35 pm    Post subject: read txt file Reply with quote

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


Joined: 24 Jan 2004
Posts: 711
Location: C'ville, Virginia, USA

PostPosted: Thu May 25, 2006 10:43 pm    Post subject: Reply with quote

Step one, have Wolfie smack you for not asking me first.
Step two, look here
Back to top
View user's profile Send private message
whittinghamj
Op


Joined: 21 May 2006
Posts: 103

PostPosted: Thu May 25, 2006 10:50 pm    Post subject: Reply with quote

no [censored] - lmfao hey man

hows it going fancy seeing you here.

cheers buddy.
Back to top
View user's profile Send private message
whittinghamj
Op


Joined: 21 May 2006
Posts: 103

PostPosted: Thu May 25, 2006 10:51 pm    Post subject: Reply with quote

drag - that just reads one file tho buddy. I need it to read / list all the lines Razz
Back to top
View user's profile Send private message
DragnLord
Owner


Joined: 24 Jan 2004
Posts: 711
Location: C'ville, Virginia, USA

PostPosted: Fri May 26, 2006 12:09 am    Post subject: Reply with quote

Code:
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"
  }
}
Back to top
View user's profile Send private message
whittinghamj
Op


Joined: 21 May 2006
Posts: 103

PostPosted: Fri May 26, 2006 12:53 am    Post subject: Reply with quote

thanks buddy - you star you Razz

god bless
Back to top
View user's profile Send private message
pstruh
Voice


Joined: 04 Mar 2005
Posts: 11

PostPosted: Tue Jun 06, 2006 3:58 pm    Post subject: Reply with quote

DragnLord wrote:
Code:
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.
Back to top
View user's profile Send private message
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Tue Jun 06, 2006 7:29 pm    Post subject: Reply with quote

what now? delay or faster?
using
Code:
  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...
Back to top
View user's profile Send private message MSN Messenger
pstruh
Voice


Joined: 04 Mar 2005
Posts: 11

PostPosted: Wed Jun 07, 2006 3:35 am    Post subject: Reply with quote

I modify the code like that:

Code:

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


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Wed Jun 07, 2006 3:56 am    Post subject: Reply with quote

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 Very Happy.
Code:
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 Very Happy. Less function calls and less memory copies Very Happy.
_________________
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...
Back to top
View user's profile Send private message MSN Messenger
Sir_Cedric_Lex2
Voice


Joined: 03 Jul 2006
Posts: 3

PostPosted: Mon Jul 03, 2006 9:19 am    Post subject: Reply with quote

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


Joined: 16 Jun 2004
Posts: 771

PostPosted: Wed Jul 05, 2006 1:24 am    Post subject: Reply with quote

posting your script might work? Rolling Eyes
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