Author | Message | Time |
---|---|---|
Tontow | ok, frist the code; [code] Select Case UCase(strText) Case "!SIGNUP" frmui.signup strUser, UCase(strText) End Select [/code] Problem; this is for a bot plugin, strUser = the current user talking and strText = what he typed. the problem is that the command !signup isnt alwasy an exact match because another word (an aka) sometimes follows it (ie: a person could type "!signup" or he could type "!signup tontow") | May 3, 2004, 3:12 AM |
Grok | I prefer a structure such as the following for parsing triggers: [code]Private Sub HandleTrigger(strLine As String) Dim sChar As String If Len(strLine) = 0 Then Exit Sub sChar = Left(strLine, 1) Select Case sChar Case "!" 'handle all ! triggers sCmd = Split(Mid(strLine, 2), " ")(0) Select Case True Case sCmd = "ban" Call BanUser(strLine) Case sCmd = "kick" Call KickUser(strLine) Case sCmd = "adduser" Call AddUser(strLine) End Select Case "#" 'handle all # triggers sCmd = Split(Mid(strLine, 2), " ")(0) Select Case True Case sCmd = "time" Call CheckCurrentTime Case sCmd = "temperature" Call CheckCurrentTemperature End Select End Select End Sub[/code] (obviously missing security checks, thorough string parsing, etc) | May 3, 2004, 3:23 AM |
Tontow | thx that helped some :) , but how would i grab the username? (ie: !signup tontow or !signup nova1313 ) strLine is returing the whole thing; "!signup tontow" returns "!signup tontow" and i just want the second word | May 3, 2004, 4:48 AM |
Null | [code] sCmd = Split(Mid(strLine, 2), " ")(0) [/code] | May 3, 2004, 4:54 AM |
Stealth | [quote author=effect link=board=31;threadid=6632;start=0#msg58228 date=1083560065] [code] sCmd = Split(Mid(strLine, 2), " ")(0) [/code] [/quote] Example: sIn = "!signup bob" Mid$(sIn, 2) = "signup bob" Split(Mid$(sIn, 2), " ")(0) = "signup" Split(Mid$(sIn, 2), " ")(1) = "bob" Specifying the split index calling it is the same as Split()ting into an array and retrieving that index thereof. | May 3, 2004, 7:27 PM |
Spht | The method I use feeds each spaced variable into p(), and variable and followed text into p_(). So with the command botnetmessage [vL] Spht[vL] protect on, for example, p(0) is botnetmessage, p(1) is [vL], p(2) is Spht[vL], and p_(3) is protect on. | May 3, 2004, 9:01 PM |
Grok | [quote author=Spht link=board=31;threadid=6632;start=0#msg58289 date=1083618061] The method I use feeds each spaced variable into p(), and variable and followed text into p_(). So with the command botnetmessage [vL] Spht[vL] protect on, for example, p(0) is botnetmessage, p(1) is [vL], p(2) is Spht[vL], and p_(3) is protect on. [/quote] Sure that's what we all do in our full fledged bots, it's the easiest way VB allows. This guy is just getting started though, so my goal was to educate him on a code structure that first parses the trigger, then parses a command and does something with it. When he gets the hang of it, he can get into command recognition and parsing parameters. For example, each different command will have its own unique number of parameters. Some 2, 3, or even 4 or 5 parameters. The third argument of your Split() function will vary depending on which command is called. | May 3, 2004, 11:04 PM |