on *:TEXT:!faq *:#MY_CHAN:{
/*
Set %f to the location of the file, and %x to be the name of the topic in the ini file you want to read from.
If the requested topic is a number, it will read the Nth topic from the file.
0 is an invalid name for a topic, as $ini() will return the number of topics in the file if you use $ini(<file>,0) rather than the actual topic called 0.
*/
var %f = file.txt, %x = $iif($2 isnum 1-,$ini(%f,$2),$iif($2- == 0,$null,$replace($2-,$chr(32),_)))
; $ini(%f,%x,0) will check that the topic you want to read exists and also that some data exists under that topic before attempting to /play it.
if ($ini(%f,%x,0)) {
/*
This /play command will read the contents of the specified topic (%x) in the ini file (%f).
It will then send those contents as notices (the -n switch) to the channel (#) with a default delay of 1 second between each message.
*/
.play $+(-nt,%x) # %f
}
; else.. this code block will trigger if the requested topic does not exist or if there's no data under the topic.
else {
/*
This code block will prevent people from flooding you off the server by typing !faq <non_existent_topic> lots of times.
What it does is, if the variable %faq.flood does not exist, it sets this variable to "1" for 3 seconds and sends a notice telling the channel that the request topic doesn't exist.
Whilst this variable exists the code will not trigger. After 3 seconds the variable will unset and the code will trigger again.
*/
if (!%faq.flood) {
inc -u3 %faq.flood
.notice # No such FAQ topic: %x
}
}
}