I hope the following working script gives you some useful ideas.
It is built on the premise that a single bind can be used to handle several/many commands by making use of the <text> argument that a PUB bind passes to the associated proc (everything that comes after the command).
For example, if the command is
!help then typing
!help me would pass
me to the proc as the <text> argument.
There are other features which I will try to explain after the pasted code :-
Code: Select all
# help.tcl
### ---------- CONFIGURATION -------------------------- ###
set vHelpTrigger !
set vHelpFlag -
### ---------- CODE ----------------------------------- ###
proc pHelpTrigger {} {
global vHelpTrigger
return $vHelpTrigger
}
setudef flag help
bind PUB $vHelpFlag [pHelpTrigger]help pHelpProc
proc pHelpProc {nick uhost hand chan text} {
if {[channel get $chan help]} {
set command [regsub -all -- {[\s]} $text {}]
if {[llength [split $command]] != 0} {
switch -- $command {
registerchannel {
set output(1) "ensure the channel is not already registered by typing \002/cs info #channelname\002"
set output(2) "register the channel by typing \002/cs register #channelname password description\002"
}
registernick {
set output(1) "change to the nick you wish to register"
set output(2) "register the nick by typing \002/ns register password email\002"
}
default {
set output(1) "\00304-error-\003 ($nick) unrecognised command \002$text\002"
}
}
} else {
set output(1) "\00304-error-\003 ($nick) correct syntax is \002[pHelpTrigger]help <command>\002"
}
foreach item [lsort -increasing [array names output]] {
putserv "PRIVMSG $chan :$output($item)"
}
}
return 0
}
putlog "help.tcl loaded"
A configuration section allows you to preset the command trigger (! for !help, . for .help, ^ for ^help etc etc) and also allows you to define which bot user flags are permitted to use the script (the default setting of - means literally anybody).
I have created a user defined flag
help in order to restrict which channels the script can be used in. To activate the script in any channel you would have to use partyline command
.chanset #channelname +help.
The regsub command inside the proc is used to remove all space characters from the <text> argument. That means
!help register channel would work equally as well as
!help registerchannel.
A switch command is used to define different outputs depending on what the user types with the command. Hence
!help register channel has a different output from
!help register nick. I have tried to maintain the script in a readable format such that you can simply add further options (as many as you like) to the switch command for different help items.
An array named
output is used for output lines which makes it easy to have as many lines as you need. They will be output one after the other in the order output(1), output(2), output(3) etc etc (up to 9 as it stands).
Finally, I have used the command source channel $chan as the destination for the output. This is because using $nick has the annoying impact of the bot opening a pm window. If you must have $nick as the destination, then I would suggest a NOTICE and not a PRIVMSG.