Code: Select all
# EditTextFile Version 0.3 #
# author: SpiKe^^ #
# e-mail: spike<at>mytclscripts<dot>com #
# webpage: http://mytclscripts.com/ #
# This file is Copyrighted under the GNU Public License. #
# http://www.gnu.org/copyleft/gpl.html #
########### Begin Settings ###########
# set the full route & file name of the file to edit #
set eTxFile(file) {/usr/home/spike/eggdrop/scripts/filename.txt}
# set the channel for this script to run in #
set eTxFile(chan) {#yourchannel}
# set the public trigger for the add line command #
set eTxFile(add) {!addline}
# set the public trigger for the read line command #
set eTxFile(read) {!readline}
# set the public trigger for the edit line command #
set eTxFile(edit) {!editline}
# set the access flags to use the above public commands #
set eTxFile(flags) {o|o}
############ End Settings ############
bind pub $eTxFile(flags) $eTxFile(add) etfProcAdd
bind pub $eTxFile(flags) $eTxFile(read) etfProcRead
bind pub $eTxFile(flags) $eTxFile(edit) etfProcEdit
proc etfProcAdd {nk uh hn ch tx} {
if {[string tolower $ch] ne [string tolower $::eTxFile(chan)]} { return }
set tf $::eTxFile(file)
if {![file exists $tf]} {
puthelp "PRIVMSG $ch :Text file does not exist: $tf"
return
}
set tx [string trim $tx]
if {$tx eq ""} {
puthelp "PRIVMSG $ch :Correct syntax is: $::eTxFile(add) text to add to the end of the file."
return
}
puthelp "PRIVMSG $ch :Adding: $tx :to file: [file tail $tf]"
set id [open $tf a]
puts $id $tx
close $id
return
}
proc etfProcRead {nk uh hn ch tx} {
if {[string tolower $ch] ne [string tolower $::eTxFile(chan)]} { return }
set tf $::eTxFile(file)
if {![file exists $tf]} {
puthelp "PRIVMSG $ch :Text file does not exist: $tf"
return
}
set tx [string trim $tx]
if {![string is digit -strict $tx]} {
puthelp "PRIVMSG $ch :Correct syntax is: $::eTxFile(read) line#"
return
}
set tid [open $tf]
set lnum 0
while {![eof $tid]} {
set line [gets $tid]
if {$line ne ""} { incr lnum
if {$lnum==$tx} {
puthelp "PRIVMSG $ch :Existing line $lnum text: $line"
break
}
}
}
close $tid
if {$tx>$lnum} {
puthelp "PRIVMSG $ch :File line $tx doesn't exist ($lnum lines in the file)"
}
return
}
proc etfProcEdit {nk uh hn ch tx} {
if {[string tolower $ch] ne [string tolower $::eTxFile(chan)]} { return }
set tf $::eTxFile(file)
if {![file exists $tf]} {
puthelp "PRIVMSG $ch :Text file does not exist: $tf"
return
}
set tx [split [string trim $tx]]
if {[llength $tx]<"2" || ![string is digit -strict [lindex $tx 0]]} {
puthelp "PRIVMSG $ch :Correct syntax is: $::eTxFile(edit) line# text to replace original line."
return
}
set find [lindex $tx 0]
set tx [string trim [join [lrange $tx 1 end]]]
set new [file dirname $tf]/newfile.tmp
set nid [open $new w]
set tid [open $tf]
set lnum 0
while {![eof $tid]} {
set line [gets $tid]
if {$line ne ""} { incr lnum
if {$lnum==$find} {
puthelp "PRIVMSG $ch :Replacing existing line $lnum text: $line"
puthelp "PRIVMSG $ch :with the new text line: $tx"
puts $nid $tx
} else { puts $nid $line }
}
}
close $nid ; close $tid
if {$find>$lnum} {
puthelp "PRIVMSG $ch :File line $find doesn't exist ($lnum lines in the file)"
file delete $new
} else { file rename -force $new $tf }
return
}
Code: Select all
# EditTextFile+TimedReadLine Version 0.4 #
# author: SpiKe^^ #
# e-mail: spike<at>mytclscripts<dot>com #
# webpage: http://mytclscripts.com/ #
# This file is Copyrighted under the GNU Public License. #
# http://www.gnu.org/copyleft/gpl.html #
########### General Script Settings ###########
# Set the full route & file name of the file to edit #
set eTxFile(file) {/usr/home/spike/eggdrop/scripts/filename.txt}
# Set the channel(s) for this script to run in #
set eTxFile(chan) {#yourchannel #anotherchannel #someotherchan}
########### Public Command Settings ###########
# Set the public trigger for the add line command #
# to add a line at the end of the file:
# example: !addline end The text to add at file end.
# example: !addline The text to add at file end.
# to add a line at a specific line position in the file:
# example: !addline 4 The text to add at file line 4.
# note: this will renumber the original line 4 & all lines after it!
set eTxFile(add) {!addline}
# Set the public trigger for the read line command #
# to read a specific line (by line number) from the text file
# example: !readline 4
# note: use to check for correct line before doing !editline or !delline
set eTxFile(read) {!readline}
# Set the public trigger for the delete line command #
# to delete a specific line (by line number) from the text file
# example: !delline 4
# note: this will renumber all lines after line 4!
set eTxFile(del) {!delline}
# Set the public trigger for the edit line command #
# to edit a specific line (by line number) in the text file
# example: !editline 4 New text to replace file line 4.
set eTxFile(edit) {!editline}
# Set the public trigger for the read file command #
# to read all lines from the text file
# example: !readfile
set eTxFile(readf) {!readfile}
# Set the access flags to use the above public commands #
set eTxFile(flags) {o|o}
########### Timed Public Read Setting ###########
# Set number of minutes between each timed public read line #
# Set this to "0" to disable all timed public read lines
# Note: file errors will be sent to the first channel in eTxFile(chan)
set eTxFile(timed) "5"
################ End Settings ################
bind pub $eTxFile(flags) $eTxFile(add) etfProcAdd
bind pub $eTxFile(flags) $eTxFile(del) etfProcDel
bind pub $eTxFile(flags) $eTxFile(read) etfProcRead
bind pub $eTxFile(flags) $eTxFile(edit) etfProcEdit
bind pub $eTxFile(flags) $eTxFile(readf) etfProcReadF
set eTxFile(chan) [split $eTxFile(chan)]
if {$eTxFile(timed)>"0" && ![info exists eTxFile(tnxread)]} {
if {$eTxFile(timed)>"3"} { timer 3 [list etfProcTimed]
} else { timer $eTxFile(timed) [list etfProcTimed] }
set eTxFile(tnxread) 1
}
proc etfProcAdd {nk uh hn ch tx} {
if {[lsearch -nocase $::eTxFile(chan) $ch]=="-1"} { return }
set tf $::eTxFile(file)
if {![file exists $tf]} {
puthelp "PRIVMSG $ch :Text file does not exist: $tf" ; return
}
set tx [split [string trim $tx]]
if {[lindex $tx 0] eq "end" || [string is digit -strict [lindex $tx 0]]} {
set addat [lindex $tx 0] ; set tx [string trim [join [lrange $tx 1 end]]]
} else { set addat end ; set tx [join $tx] }
if {$tx eq ""} { set add $::eTxFile(add)
puthelp "PRIVMSG $ch :Correct syntax is: $add \[position\] <text to add>"
puthelp "PRIVMSG $ch :Example: $add end Text to add at end of the file."
puthelp "PRIVMSG $ch :Example: $add 4 Text to add at file line 4."
puthelp "PRIVMSG $ch :Example: $add Text to add at end of the file."
return
}
if {$addat ne "end"} { set tx "$addat $tx"
etfProcEdit $nk $uh $hn $ch $tx add ; return
}
puthelp "PRIVMSG $ch :Adding line at end of file: $tx"
set id [open $tf a] ; puts $id $tx ; close $id ; return
}
proc etfProcReadF {nk uh hn ch tx} {
etfProcRead $nk $uh $hn $ch $tx file ; return
}
proc etfProcTimed {} {
if {$::eTxFile(timed)=="0"} { unset ::eTxFile(tnxread) ; return }
set chan [lindex $::eTxFile(chan) 0]
etfProcRead $::botnick Timed Line $chan $::eTxFile(tnxread)
timer $::eTxFile(timed) [list etfProcTimed]
}
proc etfProcRead {nk uh hn ch tx {do line} } {
if {[lsearch -nocase $::eTxFile(chan) $ch]=="-1"} { return }
set tf $::eTxFile(file)
if {![file exists $tf]} {
puthelp "PRIVMSG $ch :Text file does not exist: $tf" ; return
}
set tx [string trim $tx]
if {$do eq "line" && ![string is digit -strict $tx]} {
puthelp "PRIVMSG $ch :Correct syntax is: $::eTxFile(read) <line#>"
puthelp "PRIVMSG $ch :Example: $::eTxFile(read) 4"
return
}
set tid [open $tf] ; set lnum 0
while {![eof $tid]} { set line [gets $tid]
if {$line ne ""} { incr lnum
if {$uh eq "Timed" && $lnum=="1"} { set ln1 $line }
if {$do eq "file"} { puthelp "PRIVMSG $ch :\[$lnum\] $line"
} elseif {$lnum==$tx} {
if {$uh ne "Timed"} { puthelp "PRIVMSG $ch :\[$lnum\] $line" }
break
}
}
}
close $tid
if {$lnum=="0"} { puthelp "PRIVMSG $ch :Text file is empty: $tf" ; return }
if {$uh eq "Timed"} {
if {$lnum==$tx} { incr ::eTxFile(tnxread)
} else { set line $ln1 ; set lnum 1 ; set ::eTxFile(tnxread) 2 }
foreach ch $::eTxFile(chan) { puthelp "PRIVMSG $ch :\[$lnum\] $line" }
} elseif {$do eq "line" && $tx>$lnum} {
puthelp "PRIVMSG $ch :File line $tx doesn't exist ($lnum lines in the file)"
}
return
}
proc etfProcDel {nk uh hn ch tx} {
etfProcEdit $nk $uh $hn $ch $tx del ; return
}
proc etfProcEdit {nk uh hn ch tx {do edit} } {
if {[lsearch -nocase $::eTxFile(chan) $ch]=="-1"} { return }
set tf $::eTxFile(file)
if {![file exists $tf]} {
puthelp "PRIVMSG $ch :Text file does not exist: $tf" ; return
}
set tx [split [string trim $tx]]
if {$do eq "edit"} {
if {[llength $tx]<"2" || ![string is digit -strict [lindex $tx 0]]} {
set edit $::eTxFile(edit)
puthelp "PRIVMSG $ch :Correct syntax is: $edit <line#> <new edited text>"
puthelp "PRIVMSG $ch :Example: $edit 4 New text to replace file line 4."
return
}
} elseif {$do eq "del" && ![string is digit -strict [lindex $tx 0]]} {
puthelp "PRIVMSG $ch :Correct syntax is: $::eTxFile(del) <line#>"
puthelp "PRIVMSG $ch :Example: $::eTxFile(del) 4"
return
}
set find [lindex $tx 0] ; set tx [string trim [join [lrange $tx 1 end]]]
set new [file dirname $tf]/newfile.tmp ; set nid [open $new w]
set tid [open $tf] ; set lnum 0
while {![eof $tid]} { set line [gets $tid]
if {$line ne ""} { incr lnum
if {$lnum==$find} {
if {$do eq "edit"} {
puthelp "PRIVMSG $ch :Replacing line $lnum text: $line"
puthelp "PRIVMSG $ch :with the new text line: $tx"
puts $nid $tx
} elseif {$do eq "del"} {
puthelp "PRIVMSG $ch :Deleting line $lnum text: $line"
} elseif {$do eq "add"} {
puthelp "PRIVMSG $ch :Adding new line $lnum text: $tx"
puts $nid $tx
puts $nid $line
}
} else { puts $nid $line }
}
}
close $tid
if {$find>$lnum} {
if {$do eq "add"} { incr lnum
puthelp "PRIVMSG $ch :Adding new line $lnum text: $tx"
puts $nid $tx ; close $nid ; file rename -force $new $tf
} else {
puthelp "PRIVMSG $ch :File line $find doesn't exist ($lnum lines in the file)"
close $nid ; file delete $new
}
} else { close $nid ; file rename -force $new $tf }
return
}
putlog "EditTextFile+TimedReadLine Ver. 0.4 by SpiKe^^ loaded."
Code: Select all
[09:27:01] Tcl error in script for 'timer752':
[09:27:01] bad option "-nocase": must be -all, -ascii, -decreasing, -dictionary, -exact, -glob, -increasing, -inline, -integer, -not, -real, -regexp, -sorted, or -start
Code: Select all
# EditTextFile+TimedReadLine Version 0.5 #
# author: SpiKe^^ #
# e-mail: spike<at>mytclscripts<dot>com #
# webpage: http://mytclscripts.com/ #
# This file is Copyrighted under the GNU Public License. #
# http://www.gnu.org/copyleft/gpl.html #
########### General Script Settings ###########
# Set the full route & file name of the file to edit #
set eTxFile(file) {/usr/home/spike/eggdrop/scripts/filename.txt}
# Set the channel(s) for this script to run in #
set eTxFile(chan) {#yourchannel #anotherchannel #someotherchan}
########### Public Command Settings ###########
# Set the public trigger for the add line command #
# to add a line at the end of the file:
# example: !addline end The text to add at file end.
# example: !addline The text to add at file end.
# to add a line at a specific line position in the file:
# example: !addline 4 The text to add at file line 4.
# note: this will renumber the original line 4 & all lines after it!
set eTxFile(add) {!addline}
# Set the public trigger for the read line command #
# to read a specific line (by line number) from the text file
# example: !readline 4
# note: use to check for correct line before doing !editline or !delline
set eTxFile(read) {!readline}
# Set the public trigger for the delete line command #
# to delete a specific line (by line number) from the text file
# example: !delline 4
# note: this will renumber all lines after line 4!
set eTxFile(del) {!delline}
# Set the public trigger for the edit line command #
# to edit a specific line (by line number) in the text file
# example: !editline 4 New text to replace file line 4.
set eTxFile(edit) {!editline}
# Set the public trigger for the read file command #
# to read all lines from the text file
# example: !readfile
set eTxFile(readf) {!readfile}
# Set the access flags to use the above public commands #
set eTxFile(flags) {o|o}
########### Timed Public Read Setting ###########
# Set number of minutes between each timed public read line #
# Set this to "0" to disable all timed public read lines
# Note: file errors will be sent to the first channel in eTxFile(chan)
set eTxFile(timed) "5"
################ End Settings ################
bind pub $eTxFile(flags) $eTxFile(add) etfProcAdd
bind pub $eTxFile(flags) $eTxFile(del) etfProcDel
bind pub $eTxFile(flags) $eTxFile(read) etfProcRead
bind pub $eTxFile(flags) $eTxFile(edit) etfProcEdit
bind pub $eTxFile(flags) $eTxFile(readf) etfProcReadF
set eTxFile(chan) [split [string tolower $eTxFile(chan)]]
if {$eTxFile(timed)>"0" && ![info exists eTxFile(tnxread)]} {
if {$eTxFile(timed)>"3"} { timer 3 [list etfProcTimed]
} else { timer $eTxFile(timed) [list etfProcTimed] }
set eTxFile(tnxread) 1
}
proc etfProcAdd {nk uh hn ch tx} {
set ch [string tolower $ch]
if {[lsearch -exact $::eTxFile(chan) $ch]=="-1"} { return }
set tf $::eTxFile(file)
if {![file exists $tf]} {
puthelp "PRIVMSG $ch :Text file does not exist: $tf" ; return
}
set tx [split [string trim $tx]]
if {[lindex $tx 0] eq "end" || [string is digit -strict [lindex $tx 0]]} {
set addat [lindex $tx 0] ; set tx [string trim [join [lrange $tx 1 end]]]
} else { set addat end ; set tx [join $tx] }
if {$tx eq ""} { set add $::eTxFile(add)
puthelp "PRIVMSG $ch :Correct syntax is: $add \[position\] <text to add>"
puthelp "PRIVMSG $ch :Example: $add end Text to add at end of the file."
puthelp "PRIVMSG $ch :Example: $add 4 Text to add at file line 4."
puthelp "PRIVMSG $ch :Example: $add Text to add at end of the file."
return
}
if {$addat ne "end"} { set tx "$addat $tx"
etfProcEdit $nk $uh $hn $ch $tx add ; return
}
puthelp "PRIVMSG $ch :Adding line at end of file: $tx"
set id [open $tf a] ; puts $id $tx ; close $id ; return
}
proc etfProcReadF {nk uh hn ch tx} {
etfProcRead $nk $uh $hn $ch $tx file ; return
}
proc etfProcTimed {} {
if {$::eTxFile(timed)=="0"} { unset ::eTxFile(tnxread) ; return }
set chan [lindex $::eTxFile(chan) 0]
etfProcRead $::botnick Timed Line $chan $::eTxFile(tnxread)
timer $::eTxFile(timed) [list etfProcTimed] ; return
}
proc etfProcRead {nk uh hn ch tx {do line} } {
set ch [string tolower $ch]
if {[lsearch -exact $::eTxFile(chan) $ch]=="-1"} { return }
set tf $::eTxFile(file)
if {![file exists $tf]} {
puthelp "PRIVMSG $ch :Text file does not exist: $tf" ; return
}
set tx [string trim $tx]
if {$do eq "line" && ![string is digit -strict $tx]} {
puthelp "PRIVMSG $ch :Correct syntax is: $::eTxFile(read) <line#>"
puthelp "PRIVMSG $ch :Example: $::eTxFile(read) 4"
return
}
set tid [open $tf] ; set lnum 0
while {![eof $tid]} { set line [gets $tid]
if {$line ne ""} { incr lnum
if {$uh eq "Timed" && $lnum=="1"} { set ln1 $line }
if {$do eq "file"} { puthelp "PRIVMSG $ch :\[$lnum\] $line"
} elseif {$lnum==$tx} {
if {$uh ne "Timed"} { puthelp "PRIVMSG $ch :\[$lnum\] $line" }
break
}
}
}
close $tid
if {$lnum=="0"} {
if {[info exists ::eTxFile(tnxread)]} { set ::eTxFile(tnxread) 1 }
puthelp "PRIVMSG $ch :Text file is empty: $tf" ; return
}
if {$uh eq "Timed"} {
if {$lnum==$tx} { incr ::eTxFile(tnxread)
} else { set line $ln1 ; set lnum 1 ; set ::eTxFile(tnxread) 2 }
foreach ch $::eTxFile(chan) { puthelp "PRIVMSG $ch :\[$lnum\] $line" }
} elseif {$do eq "line" && $tx>$lnum} { set tl line
if {$lnum>"1"} { set tl lines }
puthelp "PRIVMSG $ch :File line $tx doesn't exist ($lnum $tl in the file)"
}
return
}
proc etfProcDel {nk uh hn ch tx} {
etfProcEdit $nk $uh $hn $ch $tx del ; return
}
proc etfProcEdit {nk uh hn ch tx {do edit} } {
set ch [string tolower $ch]
if {[lsearch -exact $::eTxFile(chan) $ch]=="-1"} { return }
set tf $::eTxFile(file)
if {![file exists $tf]} {
puthelp "PRIVMSG $ch :Text file does not exist: $tf" ; return
}
set tx [split [string trim $tx]]
if {$do eq "edit"} {
if {[llength $tx]<"2" || ![string is digit -strict [lindex $tx 0]]} {
set edit $::eTxFile(edit)
puthelp "PRIVMSG $ch :Correct syntax is: $edit <line#> <new edited text>"
puthelp "PRIVMSG $ch :Example: $edit 4 New text to replace file line 4."
return
}
} elseif {$do eq "del" && ![string is digit -strict [lindex $tx 0]]} {
puthelp "PRIVMSG $ch :Correct syntax is: $::eTxFile(del) <line#>"
puthelp "PRIVMSG $ch :Example: $::eTxFile(del) 4"
return
}
set find [lindex $tx 0] ; set tx [string trim [join [lrange $tx 1 end]]]
set new [file dirname $tf]/newfile.tmp ; set nid [open $new w]
set tid [open $tf] ; set lnum 0
while {![eof $tid]} { set line [gets $tid]
if {$line ne ""} { incr lnum
if {$lnum==$find} {
if {$do eq "edit"} {
puthelp "PRIVMSG $ch :Replacing line $lnum text: $line"
puthelp "PRIVMSG $ch :with the new text line: $tx"
puts $nid $tx
} elseif {$do eq "del"} {
puthelp "PRIVMSG $ch :Deleting line $lnum text: $line"
} elseif {$do eq "add"} {
puthelp "PRIVMSG $ch :Adding new line $lnum text: $tx"
puts $nid $tx ; puts $nid $line
}
} else { puts $nid $line }
}
}
close $tid
if {$find>$lnum} {
if {$do eq "add"} { incr lnum
puthelp "PRIVMSG $ch :Adding new line $lnum text: $tx"
puts $nid $tx ; close $nid ; file rename -force $new $tf
} else {
if {$lnum>"0"} { set tl line
if {$lnum>"1"} { set tl lines }
puthelp "PRIVMSG $ch :File line $find doesn't exist ($lnum $tl in the file)"
} else { puthelp "PRIVMSG $ch :Text file is empty: $tf" }
close $nid ; file delete $new
}
} else { close $nid ; file rename -force $new $tf }
return
}
putlog "EditTextFile+TimedReadLine Ver. 0.5 by SpiKe^^ loaded."
Code: Select all
# EditTextFile+TimedReadLine Version 1.0 #
# author: SpiKe^^ #
# e-mail: spike<at>mytclscripts<dot>com #
# webpage: http://mytclscripts.com/ #
# This file is Copyrighted under the GNU Public License. #
# http://www.gnu.org/copyleft/gpl.html #
########### General Text File Settings ###########
# Set the full route & file name of the file to edit #
# Note: The !addline command will attempt to make this file if needed.
set eTxFile(file) {/usr/home/spike/eggdrop/scripts/filename.txt}
########### Public 'Line' Command Settings ###########
## settings for: !addline !readline !delline & !editline ##
# Set the listen channel(s) for all public Line commands #
set eTxFile(lchan) {#yourchannel #anotherchannel #someotherchan}
# Set the access flags to use the public Line commands #
set eTxFile(lflags) {o|o}
# Set the public trigger for the add line command #
# to add a line at the end of the file:
# example: !addline end The text to add at file end.
# example: !addline The text to add at file end.
# to add a line at a specific line position in the file:
# example: !addline 4 The text to add at file line 4.
# note: this will renumber the original line 4 & all lines after it!
set eTxFile(add) {!addline}
# Set the public trigger for the read line command #
# to read a specific line (by line number) from the text file
# example: !readline 4
# note: use to check for correct line before doing !editline or !delline
set eTxFile(read) {!readline}
# Set the public trigger for the delete line command #
# to delete a specific line (by line number) from the text file
# example: !delline 4
# note: this will renumber all lines after line 4!
set eTxFile(del) {!delline}
# Set the public trigger for the edit line command #
# to edit a specific line (by line number) in the text file
# example: !editline 4 New text to replace file line 4.
set eTxFile(edit) {!editline}
########### Public 'ReadFile' Command Settings ###########
## settings for the public !readfile command ##
# Set the listen channel(s) for the public !readfile command #
set eTxFile(rchan) {#yourchannel #anotherchannel #someotherchan}
# Set the access flags to use the public read file command #
set eTxFile(rflags) {o|o}
# Set the public trigger for the read file command #
# to read all lines from the text file
# example: !readfile
set eTxFile(readf) {!readfile}
########### Timed Public Read Setting ###########
# Set the channel(s) for the timed public read line #
set eTxFile(tchan) {#yourchannel #anotherchannel #someotherchan}
# Set number of minutes between each timed public read line #
# Set this to "0" to disable all timed public read lines
# Note: file errors will be sent to the first channel in eTxFile(tchan)
set eTxFile(timed) "5"
# show file line number before each timed public read line? (0=no | 1=yes) #
set eTxFile(tnum) "1"
################ End Settings ################
bind pub $eTxFile(lflags) $eTxFile(add) etfProcAdd
bind pub $eTxFile(lflags) $eTxFile(del) etfProcDel
bind pub $eTxFile(lflags) $eTxFile(read) etfProcRead
bind pub $eTxFile(lflags) $eTxFile(edit) etfProcEdit
bind pub $eTxFile(rflags) $eTxFile(readf) etfProcReadF
set eTxFile(lchan) [split [string tolower $eTxFile(lchan)]]
set eTxFile(rchan) [split [string tolower $eTxFile(rchan)]]
set eTxFile(tchan) [split [string tolower $eTxFile(tchan)]]
if {$eTxFile(timed)>"0" && ![info exists eTxFile(tnxread)]} {
if {$eTxFile(timed)>"3"} { timer 3 [list etfProcTimed]
} else { timer $eTxFile(timed) [list etfProcTimed] }
set eTxFile(tnxread) 1
}
proc etfProcAdd {nk uh hn ch tx} {
set ch [string tolower $ch]
if {[lsearch -exact $::eTxFile(lchan) $ch]=="-1"} { return }
set tx [split [string trim $tx]]
if {[lindex $tx 0] eq "end" || [string is digit -strict [lindex $tx 0]]} {
set addat [lindex $tx 0] ; set tx [string trim [join [lrange $tx 1 end]]]
} else { set addat end ; set tx [join $tx] }
if {$tx eq ""} { set add $::eTxFile(add)
puthelp "PRIVMSG $ch :Correct syntax is: $add \[position\] <text to add>"
puthelp "PRIVMSG $ch :Example: $add end Text to add at end of the file."
puthelp "PRIVMSG $ch :Example: $add 4 Text to add at file line 4."
puthelp "PRIVMSG $ch :Example: $add Text to add at end of the file."
return
}
set tf $::eTxFile(file)
if {![file exists $tf]} { set addat end ; set nofile 1 }
if {$addat ne "end"} { set tx "$addat $tx"
etfProcEdit $nk $uh $hn $ch $tx add ; return
}
set id [open $tf a] ; puts $id $tx ; close $id
if {![file exists $tf]} {
puthelp "PRIVMSG $ch :Unable to find or make text file: $tf"
} elseif {[info exists nofile]} {
puthelp "PRIVMSG $ch :Added line to new text file: $tx"
} else {
puthelp "PRIVMSG $ch :Added line at end of text file: $tx"
}
return
}
proc etfProcReadF {nk uh hn ch tx} {
etfProcRead $nk $uh $hn $ch $tx file ; return
}
proc etfProcTimed {} {
if {$::eTxFile(timed)=="0"} { unset ::eTxFile(tnxread) ; return }
timer $::eTxFile(timed) [list etfProcTimed]
set chan [lindex $::eTxFile(tchan) 0]
etfProcRead $::botnick Timed Line $chan $::eTxFile(tnxread) ; return
}
proc etfProcRead {nk uh hn ch tx {do line} } {
set ch [string tolower $ch]
if {$do eq "file"} {
if {[lsearch -exact $::eTxFile(rchan) $ch]=="-1"} { return }
} elseif {$uh eq "Timed"} {
if {[lsearch -exact $::eTxFile(tchan) $ch]=="-1"} { return }
} else {
if {[lsearch -exact $::eTxFile(lchan) $ch]=="-1"} { return }
}
set tf $::eTxFile(file)
if {![file exists $tf]} {
puthelp "PRIVMSG $ch :Text file does not exist: $tf" ; return
}
set tx [string trim $tx]
if {$do eq "line" && ![string is digit -strict $tx]} {
puthelp "PRIVMSG $ch :Correct syntax is: $::eTxFile(read) <line#>"
puthelp "PRIVMSG $ch :Example: $::eTxFile(read) 4" ; return
}
set tid [open $tf] ; set lnum 0
while {![eof $tid]} { set line [gets $tid]
if {$line ne ""} { incr lnum
if {$uh eq "Timed" && $lnum=="1"} { set ln1 $line }
if {$do eq "file"} { puthelp "PRIVMSG $ch :\[$lnum\] $line"
} elseif {$lnum==$tx} {
if {$uh ne "Timed"} { puthelp "PRIVMSG $ch :\[$lnum\] $line" }
break
}
}
}
close $tid
if {$lnum=="0"} {
if {[info exists ::eTxFile(tnxread)]} { set ::eTxFile(tnxread) 1 }
puthelp "PRIVMSG $ch :Text file is empty: $tf" ; return
}
if {$uh eq "Timed"} { set pre ""
if {$lnum==$tx} { incr ::eTxFile(tnxread)
} else { set line $ln1 ; set lnum 1 ; set ::eTxFile(tnxread) 2 }
if {$::eTxFile(tnum)!="0"} { set pre "\[$lnum\] " }
foreach ch $::eTxFile(tchan) { puthelp "PRIVMSG $ch :$pre$line" }
} elseif {$do eq "line" && $tx>$lnum} { set tl line
if {$lnum>"1"} { set tl lines }
puthelp "PRIVMSG $ch :File line $tx doesn't exist ($lnum $tl in the file)"
}
return
}
proc etfProcDel {nk uh hn ch tx} {
etfProcEdit $nk $uh $hn $ch $tx del ; return
}
proc etfProcEdit {nk uh hn ch tx {do edit} } {
set ch [string tolower $ch]
if {[lsearch -exact $::eTxFile(lchan) $ch]=="-1"} { return }
set tf $::eTxFile(file)
if {![file exists $tf]} {
puthelp "PRIVMSG $ch :Text file does not exist: $tf" ; return
}
set tx [split [string trim $tx]]
if {$do eq "edit"} {
if {[llength $tx]<"2" || ![string is digit -strict [lindex $tx 0]]} {
set edit $::eTxFile(edit)
puthelp "PRIVMSG $ch :Correct syntax is: $edit <line#> <new edited text>"
puthelp "PRIVMSG $ch :Example: $edit 4 New text to replace file line 4."
return
}
} elseif {$do eq "del" && ![string is digit -strict [lindex $tx 0]]} {
puthelp "PRIVMSG $ch :Correct syntax is: $::eTxFile(del) <line#>"
puthelp "PRIVMSG $ch :Example: $::eTxFile(del) 4" ; return
}
set find [lindex $tx 0] ; set tx [string trim [join [lrange $tx 1 end]]]
set new [file dirname $tf]/newfile.tmp ; set nid [open $new w]
set tid [open $tf] ; set lnum 0
while {![eof $tid]} { set line [gets $tid]
if {$line ne ""} { incr lnum
if {$lnum==$find} {
if {$do eq "edit"} {
puthelp "PRIVMSG $ch :Replaced line $lnum text: $line"
puthelp "PRIVMSG $ch :with the new text line: $tx"
puts $nid $tx
} elseif {$do eq "del"} {
puthelp "PRIVMSG $ch :Deleted line $lnum text: $line"
} elseif {$do eq "add"} {
puthelp "PRIVMSG $ch :Added new line $lnum text: $tx"
puts $nid $tx ; puts $nid $line
}
} else { puts $nid $line }
}
}
close $tid
if {$find>$lnum} {
if {$do eq "add"} { incr lnum
puthelp "PRIVMSG $ch :Added new line $lnum text: $tx"
puts $nid $tx ; close $nid ; file rename -force $new $tf
} else {
if {$lnum>"0"} { set tl line
if {$lnum>"1"} { set tl lines }
puthelp "PRIVMSG $ch :File line $find doesn't exist ($lnum $tl in the file)"
} else { puthelp "PRIVMSG $ch :Text file is empty: $tf" }
close $nid ; file delete $new
}
} else { close $nid ; file rename -force $new $tf }
return
}
putlog "EditTextFile+TimedReadLine Ver. 1.0 by SpiKe^^ loaded."