• Welcome to Valhalla Legends Archive.
 

VB 6 :Reconizeing a string that varies

Started by Tontow, May 02, 2004, 10:12 PM

Previous topic - Next topic

Tontow

ok, frist the code;

   Select Case UCase(strText)
       Case "!SIGNUP"
           frmui.signup strUser, UCase(strText)
   End Select


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")

Grok

#1
I prefer a structure such as the following for parsing triggers:

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


(obviously missing security checks, thorough string parsing, etc)

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

effect

sCmd = Split(Mid(strLine, 2), " ")(0)
Quote from: Mangix on March 22, 2005, 03:03 AM
i am an expert Stealthbot VBScript. Recognize Bitch.

Stealth

#4
Quote from: effect on May 02, 2004, 11:54 PM
sCmd = Split(Mid(strLine, 2), " ")(0)

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.
- Stealth
Author of StealthBot

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.

Grok

#6
Quote from: Spht on May 03, 2004, 04:01 PM
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.

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.