Code: Select all
# June 9, 2012
# http://forum.egghelp.org/viewtopic.php?t=19001
#
# set how often file check runs - in minutes
set sched 1
# set path and filename of stats file
set statsfile "scripts/added/testing/Stats.txt"
# set channels in which to announce
set announcechans "#chan1 #chan2"
##
timer $sched readthefile
proc readthefile { } {
global sched statsfile announcechans
if {![file exists $statsfile]} {
timer $sched readthefile
return 0
}
# reference: http://forum.egghelp.org/viewtopic.php?t=6885
set fname $statsfile
set fp [open $fname "r"]
set data [read -nonewline $fp]
close $fp
set lines [split $data "\n"]
if {[lindex $lines 0] == ""} {
timer $sched readthefile
return 0
}
foreach channel $announcechans {
if {[botonchan $channel]} {
putserv "privmsg $channel :[lindex $lines 0]"
}
}
file delete $statsfile
timer $sched readthefile
}
bind evnt - prerehash cleartimers
proc cleartimers {prerehash} {
foreach timerlisted [timers] {
if {[lindex $timerlisted 1] == "readthefile" } {
killtimer [lindex $timerlisted 2]
}
}
}
Football wrote:Yeah you're right, I apologize, its my fault.. I was thinking about something and wrote something else...
The script is meant to read each X minutes the next line in the file. Each time it reads a line, it erases that line from the file..
Code: Select all
# June 10, 2012
# http://forum.egghelp.org/viewtopic.php?t=19001
#######
# Usage: To add a line, do: !addline <text of line here> in channel.
# To see all lines, do: !sayfile
# set how often file check runs - in minutes
set sched 1
# set path and filename of stats file
set statsfile "scripts/added/testing/Stats.txt"
# set channels in which to announce
set announcechans "#channel1 #channel2"
bind pub - "!addline" addline
bind evnt - prerehash cleartimers
bind pub - "!sayfile" sayfile
timer $sched readthefile
proc readthefile { } {
global sched statsfile announcechans
if {![file exists $statsfile]} {
timer $sched readthefile
return 0
}
# reference: http://forum.egghelp.org/viewtopic.php?t=6885
set fname $statsfile
set fp [open $fname "r"]
set data [read -nonewline $fp]
close $fp
set lines [split $data "\n"]
if {[lindex $lines 0] == ""} {
timer $sched readthefile
return 0
}
foreach channel $announcechans {
if {[botonchan $channel]} {
putserv "privmsg $channel :[lindex $lines 0]"
}
}
set fname $statsfile
set fp [open $fname "r"]
set data [read -nonewline $fp]
close $fp
set lines [split $data "\n"]
# reference: http://forum.egghelp.org/viewtopic.php?t=6885
set line_to_delete 0
set lines [lreplace $lines $line_to_delete $line_to_delete]
set fp [open $fname "w"]
puts $fp [join $lines "\n"]
close $fp
timer $sched readthefile
}
###
proc cleartimers {prerehash} {
foreach timerlisted [timers] {
if {[lindex $timerlisted 1] == "readthefile" } {
killtimer [lindex $timerlisted 2]
}
}
}
###
proc addline {nick uhost handle chan text} {
global statsfile
if {$text == ""} {
return 0
}
# reference: http://forum.egghelp.org/viewtopic.php?t=6885
set line_to_add $text
set fname $statsfile
set fp [open $fname "a"]
puts $fp $line_to_add
close $fp
}
###
proc sayfile {nick uhost handle chan text} {
global statsfile
if {![file exists $statsfile]} {
putserv "privmsg $chan :File does not exist"
return 0
}
set fname $statsfile
set fp [open $fname "r"]
set data [read -nonewline $fp]
close $fp
set lines [split $data "\n"]
putserv "privmsg $chan :$lines"
}