If you're designing a really long plugin, that's intended to have a lot of commands, you may have a rudimentary command processor like the following:
Sub example_Event_UserTalk(Username, Flags, Message, Ping)
GetDBEntry Username, myAccess, myFlags
If Left(Message, Len(BotVars.Trogger + 11)) = BotVars.Trigger & "eatmyshorts" Then
If myAccess > 30 Then
AddQ "blahhh!!!"
End If
End If
If Left(Message, Len(BotVars.Trogger + 7)) = BotVars.Trigger & "dothis " Then
If myAccess > 50 Then
doThis = Right(Message, Len(Message) - (Len(BotVars.Trigger) + 8))
Command Username, BotVars.Trigger & doThis, False
End If
End If
End Sub
Followed by other commands.
Well, it's much more simpler, and does not require a lot of text, if you simple convert it to a much simpler method. Using this method, you use a minimal amount of code, and yet are still able to use your commands with no real overhead.
The preceeding example can be re-coded in a much simpler form such as the following:
Sub example_Event_UserTalk(Username, Flags, Message, Ping)
'// Make sure they did not use a trigger
If Not Left(Message, Len(BotVars.Trigger)) = BotVars.Trigger Then Exit Sub
GetDBEntry Username, myAccess, myFlags
'// Split the message up, first removing spaces at either end
cmd = Split(Mid(Lcase(Trim(Message)), Len(BotVars.Trigger) + 1), " ")
'// Allows us to handle multiple commands!
Select Case
Case "eatmyshortts"
'// If your access is less than 30, then you can't do this command
If myAccess < 30 Then Exit Sub
AddQ "blahhh!"
Case "dothis"
'// If your access is less than 50, then you can't do this command
If myAccess < 50 Then Exit Sub
doThis = Split(cmd(0) & " ")(1)
Command Username, BotVars.Trigger & doThis, False
End Select
End Sub
Now, say you want to include whispering, and the pressed enter event to the already existing code. You would set it up in the following way:
Sub example_Event_UserTalk(Username, Flags, Message, Ping)
Call test_processInput(Username, Message, 1)
End Sub
Sub example_Event_WhisperFromUser(Username, Flags, Message)
Call test_processInput(Username, Message, 2)
End Sub
Sub example_Event_pressedEnter(text)
Call test_processInput(BotVars.Username, text, 4)
End Sub
Sub example_processInput(Username, Message, Origin)
'// Make sure they did not use a trigger
If Not Left(Message, Len(BotVars.Trigger)) = BotVars.Trigger And Not Left(Message, 1) = "/" Then Exit Sub
GetDBEntry Username, myAccess, myFlags
'// Split the message up, first removing spaces at either end
cmd = Split(Mid(Lcase(Trim(Message)), Len(BotVars.Trigger) + 1), " ")
'// Allows us to handle multiple commands!
Select Case
Case "eatmyshortts"
'// If your access is less than 30, then you can't do this command
If myAccess < 30 Then Exit Sub
DSP Origin, "blahhh!", Username, vbWhite
Case "dothis"
'// If your access is less than 50, then you can't do this command
If myAccess < 50 Then Exit Sub
doThis = Split(cmd(0) & " ")(1)
Command Username, BotVars.Trigger & doThis, False
End Select
End Sub
So as you can see, this makes commands a lot easier to implement. This is efficient if you have a lot of commands, like more than 4 or 5.