Untested, but this should do what you need. As mentioned by RussellB, this has the potential for abuse. This is why I put a level 500 requirement on it. You can really just use whatever level you want and/or have it check to make sure the nick's host is "allowed". You *really* don't want to let just anyone add commands or people can make your bot do just about anything... including format your hard drive. To add someone as level 500 user, you'll want to use:
/auser 500 nick!ident@host.com . Keep in mind that you can use wildcards in the address mask if you want to make it more general (such as
/auser 500 *!ident@host.com or whatever).
on *:start: { HashCommands }
on 500:text:!add *:*: {
if ($3) {
if (!$hget(Commands)) { HashCommands }
hadd Commands $2 $3-
hsave Commands Commands.hsh
}
}
on *:text:*:#: {
if ($hget(Commands,$1)) { msg $chan $v1 }
}
alias HashCommands {
hmake Commands 100
if ($exists(Commands.hsh)) { hload Commands Commands.hsh }
}
To RussellB, you should avoid saving the hash table on exit. It's better to save it every time a change is made (except if you're changing it constantly and then you should use a timer). If you save only on exit, it won't be saved if you crash. There's also no reason to silence a command that only has output if there's an error (which you usually *want* to see in those cases). Also, just having the bot do "$v1" won't work unless you add actual commands when using !add... it won't send any text by just doing $v1.