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 

Slowing down pasting of a txt file

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


Joined: 07 May 2012
Posts: 3
Location: Isle of Mann

PostPosted: Mon May 07, 2012 3:38 am    Post subject: Slowing down pasting of a txt file Reply with quote

Ok I am ok so far with this but would like to slow down the pasting of each line, what it does is read from a specific txt file and paste on line at a time but is doing so too fast, I would like say 3 or 4 seconds between lines also cant understand why it stops before the end of each file.
Code:

    set tracks [open $filename]
    set data [split [read -nonewline $tracks] \n]
    close $tracks
    foreach trance_line $data {
        putserv "PRIVMSG $nick :$trance_line"
    }
 }

proc Trance_Listing {nick uhost hand text} {
    set number "trancelist"
    set filename ${::trance_file}/${number}.txt
    set tracks [open $filename]
    set data [split [read -nonewline $tracks] \n]
    close $tracks
    foreach trance_line $data {
        putserv "PRIVMSG $nick :$trance_line "
    }
}
Back to top
View user's profile Send private message Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Mon May 07, 2012 1:07 pm    Post subject: Reply with quote

There's quite a few ways of doing this; I'd probably do it using a recursive timers, reading one line at a time from the file.

A short example on how you could do this:
Code:
proc tellNextLine {target fd} {
  if {[gets $fd line] >= 0} {
    puthelp "PRIVMSG $target :$line"
    utimer 4 [list tellNextLine $target $fd]
  } else {
    close $fd
  }
}

proc Trance_Listing {nick userhost handle text} {
  tellNextLine $nick [open "${::trance_file}/trancelist.txt" RDONLY]
}

_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
manxmistress
Voice


Joined: 07 May 2012
Posts: 3
Location: Isle of Mann

PostPosted: Mon May 07, 2012 1:25 pm    Post subject: Reply with quote

Ok i can see what you mean but i dont have a clue how to put that in what I have, that above the user picks the file name and it starts pasting. It would be helpful to know what to do with that in plain english or how it is in relationship to what I have cheers
Back to top
View user's profile Send private message Visit poster's website
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Mon May 07, 2012 1:35 pm    Post subject: Reply with quote

Sure,
What I do, is rather than having a foreach-loop iterate through all lines at once, I use timers to repeatedly call my proc named "tellNextLine". This proc then reads the next line from the (already opened) file and sends it to the target, and then starts a new timer (to call tellNextLine again), until there are no more lines remaining in the file ("gets" returns less than 0 bytes read). I then close the file to preserve file descriptors.

Also, rather than read the whole file into memory at once, I leave the file open and only read the one line I need at the moment. Since we're using such a slow pace for sending messages, there's no real benefit from caching the texts in memory.

Other than that, I skipped some temporary variables you've used. The code I wrote should be able to completely replace the code from your original post.
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
manxmistress
Voice


Joined: 07 May 2012
Posts: 3
Location: Isle of Mann

PostPosted: Wed May 23, 2012 4:21 am    Post subject: Reply with quote

Sorry I didn't get back my sub/hubby been ill after chemo so all is well now including what you did thank you so much, Very Happy
Back to top
View user's profile Send private message Visit poster's website
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