Re-evaluate the process when the script is activated, such as parsing input from a channel. If there are any requirements that need to be met for the script to kick in, have those requirements checked near the beginning.
In event processing, try to narrow down the trigger as far as possible before getting into the body of the handler
;instead of this
on *:TEXT:*:#: if ($1 == !command) { stuff }
;do this:
on *:TEXT:!command:#:{ stuff }
Furthermore, its better to use multiple events with similar code for different commands than it is to use a single event to handle multiple things
;instead of this
on *:TEXT:*:#:{
if ($nick isop #) {
if ($1 == !command1) { stuff }
elseif ($1 == !command2) { stuff2 }
}
}
; use this:
on *:TEXT:!command1:#:{
if ($nick isop #) { stuff }
}
on *:TEXT:!command2:#:{
if ($nick isop #) { stuff }
}
Actually that's bad advice. Multiple event handlers means extra parsing and the idea is to reduce code as well.
ON *:TEXT:*:#:{
if ( !* iswm $strip($1-) || !$nick($chan,$nick,o) ) { return }
(cont)
This is better because you are checking one time if the person is an OP and ending the processing if it's not a !command (not to mention not additional event processing).
A method I use to replace if/then conditions for commands is to use a custom alias format to handle things. For example, !command1 !command2 and !command3 would be aliases like so:
alias op.!command1 { stuff }
alias op.!command2 { stuff }
alias op.!command3 { stuff }
Then in the ON TEXT trigger, check if the alias exists and if it does, call on it, like so...
(cont)
while ( $strip($1) != $1 ) { tokenize 32 $strip($1) $2- }
VAR %command = $+(op.,$1)
IF ( $isalias(%command) ) { %command $2- }
}
That little bit of code (connected by the 'cont' lines) is quite versatile and efficient.
If you still think doing multiple ON TEXT events is better, then consider this. Each ON TEXT event is comparing the actual text against the required text. If you have 20 events, that's 20 comparisons. By doing it in one event then checking if it would ever match (the "!* !iswm $strip($1-)" part), it's only doing one pass on it. Not only that but if someone's using a script that sends out color codes when they type, their attempts to use a !command would get ignored (thus the $strip identifier, so it doesn't get ignored). There's also one check to make sure it's an OP, so there isn't a need to make sure it's included with every command.
