# 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
}
This one is good ... only some small changes .. like ..
instead of !addline !readline !editline there must be
1. 2. 3. 4. 5. being the lines in the file .... the lines being small i figured that the eggdrop could put 3 or 4 lines in one sentence ... so if i type !readfile ... and there are 60 lines in the file ... the eggdrop would`t ping timeout ...
i suck at scripting .. that why i ask for so much help ...