I've used puts a fair amount of times, not once has it cause this.
I get no error at all; the file exists, all the variables it needs exist and contain the right contents; but the file just doesn't get written to.
proc spidey:settings:greet { nick host hand chan text } {
global nogreetpath
if { [lindex $text 0] == "off" } {
set nicklist [split [read -nonewline [open "$nogreetpath\\nogreet.txt" r]] "\n"]
if { [lsearch $nicklist $nick] == -1 } {
puts [open "$nogreetpath\\nogreet.txt" a] $nick
}
putnotc $nick "You will no longer be greeted when you enter a channel with me in it."
putnotc $nick "Type \002!setting greet on\002 to be greeted again."
} elseif { [lindex $text 0] == "on" } {
set foundnick 0
set nicklist [split [read -nonewline [open "$nogreetpath\\nogreet.txt" r]] "\n"]
while { [lsearch $nicklist $nick] != -1 } {
set index [lsearch $nicklist $nick]
set nicklist [lreplace $nicklist $index $index]
}
puts [open "$nogreetpath\\nogreet.txt" w] [join $nicklist "\n"]
putnotc $nick "You will be greeted every time you enter a channel with me in it."
putnotc $nick "Type \002!setting greet off\002 to stop being greeted."
} else {
putnotc $nick "Invalid setting. Must be \002on|off\002."
}
}
I put around some putlogs (removed from here) to see that the vars are all correct. They are, and the putlogs execute meaning it's not a conditions problem. The messages also get echoed correctly. Wth is this happening? The "on" setting also works; puts work fine there.
combining different things seem fine in order to shorten code and make it a bit faster, but definately hard to read - even if you are looking for an error.
my guess:
the channel which is being opened up with open isnt being closed, maybe you also would like to put in putlogs after each line to see where it stops working, explode the following part into different lines:
set filename "$nogreetpath/nogreet.txt"
set file [open $filename a]
puts $file $nick
close $file
Im kind of wondering why you are using \\ since I always used / to separate different directories from each other, works even on windows based systems. and $file (in my case) already exists I guess since you are reading from it as well?
Just to confirm raider2k's suspicions; since you don't close the file, the output will never be flushed to the file, as tcl buffers file operations by default.
Further, invoking this proc over and over will "leak" file handlers, up until the point (usually around 1023 file handlers) where you have exhausted the available resources, and your eggdrop will be unable to open any other files or network connections.
Tcl does not come with a garbage collector, so you'll have to take the effort of keeping track/cleaning up your resources such as file handles and sockets yourself. The only cleanup done is the anonymous namespace of the proc itself (local variables will be removed as the proc ends).
proc henasraf:satiel:add { nick host hand chan text } {
if { $text != "" } {
set fopen [open $::satielfile a]
puts $fopen $text
close $fopen
putmsg $chan "Added <$text> to Satiels database"
}
}
Sends the message to the channel but doesn't actually do anything to the file. $::satielfile refers to the right file path/name. Not a problem with the variable, it works fine for reading from the file. Iunno what to do |: