Since you're not looking for someone just writing code for you, I believe this thread rather belongs to the "Scripting Help" forum (I'll move it there once I'm done with this post)
As for the code, it's not that complex; I'll walk you through it..
Code: Select all
if {[catch {open "scripts/chanlist.txt" "RDONLY"} fd]} {
puthelp "PRIVMSG ###1 :Unable to open the channel-list"
putlog "Error during open: $fd"
return 0
}
This simply opens the file in a safe manner. "catch" simply catches any errors thrown by open, allowing us to send an error to the person using the command, and logging the actual error message for further investigation.
If the open-command succeeds, a file descriptor is stored in the variable fd instead...
Sets the file descriptor to "non-blocking" mode; which means that no operations on this descriptor may block (blocking == not returning / completing immediately). Usually not needed to be set explicitly with normal files, but it's a good practice in most cases (makes sure your code won't cause your eggie to stop responding in case of I/O issues)
Code: Select all
while {![eof $fd] && ![fblocked $fd]} {
...
}
Run a loop which checks the EOF (End of File) and fblocked (blocking operation, see above) status of the last operation (in this case; reading a line from the file). EOF will be true if we've reached the end of the file. Fblocked would be true if the last call to "gets" would not return a complete line - not likely to happen with files, but once again good practice (especially if you start reading sockets, serial ports, or pipes in the future).
Simply put, this will make sure we keep on reading the file until we've reached the end of it.
Code: Select all
..
if {[gets fd data] > 0 } {
...
}
Try to read one line from the file, and store it in the variable "data". Also check how many characters we actually read (0 means an empty line, anything less than 0 means there was an error, such as EOF). If we've read something, then we should write it to the channel..
Code: Select all
...
puthelp "PRIVMSG ###1 :$data"
...
Send the line of text we've read into the channel ###1.