| View previous topic :: View next topic |
| Author |
Message |
onesikgypo Voice
Joined: 14 Jun 2008 Posts: 4
|
Posted: Sat Jun 14, 2008 10:01 pm Post subject: Read from textfile every 4 secs |
|
|
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: |
#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
|
|
|
| Back to top |
|
 |
r0t3n Owner
Joined: 31 May 2005 Posts: 507 Location: UK
|
Posted: Sun Jun 15, 2008 8:53 am Post subject: |
|
|
Example: (untested)
| Code: | 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 |
|
| Back to top |
|
 |
onesikgypo Voice
Joined: 14 Jun 2008 Posts: 4
|
Posted: Sun Jun 15, 2008 2:29 pm Post subject: |
|
|
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 |
|
| Back to top |
|
 |
r0t3n Owner
Joined: 31 May 2005 Posts: 507 Location: UK
|
Posted: Sun Jun 15, 2008 5:22 pm Post subject: |
|
|
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: | 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 |
|
| Back to top |
|
 |
tsukeh Voice
Joined: 20 Jan 2005 Posts: 31
|
Posted: Mon Jun 16, 2008 9:30 am Post subject: |
|
|
| 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: | 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: |
if {[lsearch [utimers] "* dumpfile *"] == -1} { utimer 4 [list dumpfile] }
|
Otherwise it starts a new timer always you .rehash.. |
|
| Back to top |
|
 |
|