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 from textfile every 4 secs

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
o
onesikgypo
Voice
Posts: 4
Joined: Sat Jun 14, 2008 9:59 pm

Read from textfile every 4 secs

Post by onesikgypo »

Hi,

I was wondering if someone could write me a smallt tcl script that would do the following:

1) Every 4 secs "Text.txt" is read - and messaged into a channel
2) Once the text has been read, the contents are deleted
3) If there's no contents in the Text, then nothing happens.

Any help would be greatly appreciated.

Thanks.

Edit: This is for an eggdrop

Edit2:

i had a mini go at it, just from cutting other scripts - unsure though if its correct, or how to put it on a timer:

Code: Select all

#reading
set fname "yourfile.txt" 
set fp [open $fname "r"] 
set data [read -nonewline $fp] 
close $fp 
set lines [split $data "\n"] 

#messaging
set wchan #Chan
global wchan {
putserv $lines 
}

#deleting
set match *
while {[set i [lsearch -glob $lines $match]]>-1} { 
set lines [lreplace $lines $i $i] 
}

#writing file
set fp [open $fp "w"] 
puts $fp [join $lines "\n"] 
close $fp 
r
r0t3n
Owner
Posts: 507
Joined: Tue May 31, 2005 6:56 pm
Location: UK

Post by r0t3n »

Example: (untested)

Code: Select all

set file [open text.txt r]
set data [read -nonewline $file]
close $file
foreach line [split $data \n] {
    if {$line == ""} { continue }
    putserv "PRIVMSG #CHANNEL_HERE :$line"
}
set file [open text.txt w]
puts $file ""
close $file
r0t3n @ #r0t3n @ Quakenet
o
onesikgypo
Voice
Posts: 4
Joined: Sat Jun 14, 2008 9:59 pm

Post by onesikgypo »

thanks, im unable to test it right now, and am also completely new to tcl scripts - but i dont think what you posted contains the 4sec timer i need?

Thanks
r
r0t3n
Owner
Posts: 507
Joined: Tue May 31, 2005 6:56 pm
Location: UK

Post by r0t3n »

We expect users to help themselves here, you could of searched the forum for 'utimer' and created the timer yourself.

It should look something like:

Code: Select all

proc dumpfile {} {
  set file [open text.txt r]
  set data [read -nonewline $file]
  close $file
  foreach line [split $data \n] {
    if {$line == ""} { continue }
    putserv "PRIVMSG #CHANNEL_HERE :$line"
  }
  set file [open text.txt w]
  puts $file ""
  close $file
  utimer 4 [list dumpfile]
}

utimer 4 [list dumpfile]
r0t3n @ #r0t3n @ Quakenet
t
tsukeh
Voice
Posts: 31
Joined: Thu Jan 20, 2005 6:22 am

Post by tsukeh »

Tosser^^ wrote:We expect users to help themselves here, you could of searched the forum for 'utimer' and created the timer yourself.

It should look something like:

Code: Select all

proc dumpfile {} {
  set file [open text.txt r]
  set data [read -nonewline $file]
  close $file
  foreach line [split $data \n] {
    if {$line == ""} { continue }
    putserv "PRIVMSG #CHANNEL_HERE :$line"
  }
  set file [open text.txt w]
  puts $file ""
  close $file
  utimer 4 [list dumpfile]
}

utimer 4 [list dumpfile]

Code: Select all

 if {[lsearch [utimers] "* dumpfile *"] == -1} { utimer 4 [list dumpfile] }

Otherwise it starts a new timer always you .rehash..
Post Reply