I am having a problem with the following code:
Right(message, Len(message) - 4)
For instance, (im using this code for commands) when i do something like:
If LCase(username) = Master And LCase(Message) = Trigger & "say" Then
Send Right(message, Len(message) - 4)
End If
Of course i want the bot to send what the user says after Trigger & "say"
Im not sur y, but with this code, the bot wont do ne thing at all. Can ne1 help me?
If LCase(Message) = Trigger & "say" Then
Message = ".say Hi!!!!!"
Trigger = '.'
<You> .say Hi!!!11
LCase(Message) = Trigger & "say"
False.
Solution? Check to see if the first four characters == Trigger + "say"
Could u hav made that ne more confusing?
Your code:
If LCase(Message) = Trigger & "say" Then
Let's use . as our trigger...
Your code will only work if a user types ".say" -- If someone types ".say Hello", well guess what, ".say Hello" is not equal to ".say". Becuase you're only checking for <trigger>say, nobody will ever be able to say anything from your bot. So, what you should be doing is checking for something like:
If (Left$(LCase(Message), 4) = (Trigger & "say")) Then
Quote from: Yegg on October 30, 2004, 03:24 PM
Of course i want the bot to send what the user says after Trigger & "say"
Im not sur y, but with this code, the bot wont do ne thing at all. Can ne1 help me?
Public Sub ProcessTalk(ByVal UserName As String, ByVal Msg As String)
'check if message is a command (look for trigger)
If Left(Msg,1) = "." And Instr(Msg, " ") > 1 Then
bCmd = True
End If
'figure out which command it is ...
If bCmd Then
sCmd = Split(Msg," ")(0)
If Len(sCmd) > 1 Then
sCmd = UCase(Mid(sCmd,2))
Select Case sCmd
Case "SAY"
eCmd = E_SAY
sParms = Mid(Msg, 6) 'everything starting with 6th char are parameters
Case "BAN"
eCmd = E_BAN
sParms = Mid(Msg, 6) 'everything starting with 6th char are parameters
Case "KICK"
eCmd = E_KICK
sParms = Mid(Msg, 7) 'everything starting with 7th char are parameters
Case Else 'etc
End Select
End If
see how you incrementally break apart the message, first deciding if its a trigger, then if its a command, then what the parameters are? it keeps it really simple to manage that way. i'm sure there are other ways, but this is pretty easy to understand and code.
Quote from: Yegg on October 30, 2004, 03:24 PM
I am having a problem with the following code:
Right(message, Len(message) - 4)
Mid$(Message,4)
I now have:
If LCase(username) = Master And(Left$(LCase(Message), 4) = (Trigger & "say")) Then
Send (im not sure wut goes here)
End If
and as u can see in the code, im not sure wut im supposed 2 send now.
If LCase(username) = Master And(Left$(LCase(Message), 4) = (Trigger & "say")) Then
Send (im not sure wut goes here)
End If
Lets see if I can help you with this.
I LCase(UserName) = Master And Left(Lcase(Message), 4) = Trigger & "say" then
Send Mid(Message, 5) 'Length of ".say" + 1 for the fallowing space
end if
This IS NOT a good way to do this if you trying to make a commands parsing sub, but if its just one Thing then your fine i guess.
~-~(HDX)~-~
Quote from: Yegg on October 30, 2004, 04:54 PM
I now have:
If LCase(username) = Master And(Left$(LCase(Message), 4) = (Trigger & "say")) Then
Send (im not sure wut goes here)
End If
and as u can see in the code, im not sure wut im supposed 2 send now.
You were partially correct in what you were sending in the first post.
Send (Right$(Message, Len(Message) - 5))
Quote from: Yegg on October 30, 2004, 04:54 PM
I now have:
If LCase(username) = Master And(Left$(LCase(Message), 4) = (Trigger & "say")) Then
Send (im not sure wut goes here)
End If
and as u can see in the code, im not sure wut im supposed 2 send now.
Hmm, LCase(username) = Master? That will make Visual Basic treat it first as a String value, and then something
other than a string. (I would just say a Variant). That shouldn't work at all for (I'm assuming) checking whether or not your user has the access of "Master". Try creating some function to check on a user's access, and then having it return a string with said access type.
Public Function chkAccess(username as String) As String
'perform some sort of check comparison to a user ("username") and their 'respective access, then..
If (access of)username = "Master" Then
chkAccess = "Master"
End Function
'after "TALK" event is fired...
Sub chkCommand(message as String, username as String)
If Left$(message, 1) = (Trigger var, in quotes) Then
Select Case chkAccess(username)
Case "Master"
Select Case Mid$(message, 2, 3)
Case "say " ' remember to include the space
Dim toSay as String
toSay = Mid$(message, 6)
'Additional 3 letter command conditionals for rank of "Master"
Select Case 'additional n letter commands for "Master"
Select Case 'Additional commands for rank of x
GoTo processor
End If
Else 'not a command!
Exit Sub
End if
processor:
'Do operations
End Sub
It should also be pretty fast considering it really doesn't do any Variant conversions and it does not continuing checking the entire statement for each message once a command is found.
Edit: BTW, I just wrote that as I did this post, so let me know if there are inconsistencies/errors.
Ok no offence to be ment but, wouldn't it be easer to just check Mid(Split(Message & Space(1), Space(1))(0), 2) the 1st word subtract the 1st chr (the trigger) of the message.
And then check the access in each case? (it would only end up checking the access once cuz its only gona fit 1 case)
Insted of checking the access, the making a hell of a lot of select cases?
Also I beleace the LCase(Username) = Master means that he has a string Var nasmed Master witch is a username that has complet access to the bot (maby he hasnt made an access/ranks system yet?)
Just an idea..
~-~(HDX)~-~
Quote from: HdxBmx27 on October 30, 2004, 11:36 PM
Ok no offence to be ment but wouldnt it be easer to jsut check Mid(Split(Message &Space(1), Space(1))(0), 2) the 1st word subtract the 1st chr (the trigger)
And then check the access in each case? (it would only end up checkinbg the access once cuz its only gona fit 1 case)
Insted of checking the access, the making a a hell aot of select cases?
Also I beleace the LCase(Username) = Master means that he has a string Var nasmed Master witch is a username that has complet access to the bot (maby he hasnt made an access/ranks system yet?)
Just an idea..
~-~(HDX)~-~
My entire reasoning for using Select Case was so that it would end the comparisons immediately when a truth statement was found. Would I not then, be processing commands by only rank? Notice that my first Select Case is to check for Master, if something other than Master is returned by chkAccess, it skips the entire collection of Case clauses underneath it. How would this be "a hell of a lot of select cases"? Secondly, I am aware that he was "attempting" to check access of "Master". But, I see no implication that he meant Master was a variable referring to some other string that had access of "Master". It would not only be redundant, but bad policy. And, even if he has not made alternate ranks/access values, my method shows easily how to impliment other ranks into the chkCommand sub.
Space() is not an array, it is a function that returns a string of spaces equal to the integer past to it.
Notice, I modified my post. Somehow I misread it.
Private Type UserList
UserName As String
Access As Integer
Flags As String
End Type
Private UL() As UserList
Private Sub LoadUsers()
Dim Splt() As String, sInput As String, File As String, pfNum As Integer, I As Integer
ReDim UL(0)
pfNum = FreeFile
File = App.Path & "\Users.txt"
I = 0
If Dir$(File) = vbNullString Then
MsgBox "UserList could not be found!", vbCritical, "Error!"
Exit Sub
End If
Open (File) For Input As #pfNum
Do Until EOF(pfNum)
Input #pfNum, sInput
If sInput = vbNullString Then
ReDim Preserve UL(0 To UBound(UL) - 1)
Exit Sub
End If
Splt() = Split(sInput, ":", 2) '// Userlist syntax is "Username:Access:Flags"
UL(I).UserName = Splt(0)
UL(I).Access = CInt(Splt(1))
UL(I).Flags = Splt(2)
I = I + 1
ReDim Preserve UL(0 To UBound(UL) + 1)
Loop
Close #pfNum
End Sub
Private Function GetAccess(ReqAccess As Integer, ReqFlag As String, UserName As String) As Boolean
For I = 0 To UBound(UL)
If LCase$(UserName) = LCase$(UL(I).UserName) Then
Select Case True
Case ReqAccess >= UL(I).Access
GetAccess = True
Case InStr(UL(I).Flags, ReqFlag)
GetAccess = True
Case InStr(UL(I).Flags, "M")
GetAccess = True
Case Else
GetAccess = False
End Select
End If
Next I
End Function
Public Sub CommandRecognition(UserName As String, Message As String)
Dim Tmp As String
Tmp = UserName
UserName = Replace$(UserName, "*", vbNullString)
If LCase$(varProduct) = "px2d" Or LCase$(varProduct) = "vd2d" Then
If InStr(Tmp, "*") = 0 Then Tmp = "*" & UserName
End If
Dim tChar As String
tChar = Left$(Message, 1)
If Not tChar = varTrigger Then Exit Sub
Dim CommandName As String
Dim CommandCount() As String
Dim Text() As String
CommandCount() = Split(Message, "; ")
For I = 0 To UBound(CommandCount)
If CommandCount(I) = vbNullString Then GoTo ErrCommand
CommandName = Split(CommandCount(I), vbNullString)(0)
If CommandName = vbNullString Then GoTo ErrCommand
If InStr(CommandName, varTrigger) <> 0 Then CommandName = Replace$(CommandName, varTrigger, vbNullString)
Text() = Split(CommandCount(I), vbNullString, 2)
Select Case LCase$(CommandName)
Case "ver"
If Not GetAccess(10, "I", UserName) = True Then GoTo ErrCommand
AddQ "I'm a KickAssBot v1.0 Biatch!"
End Select
ErrCommand:
Next I
End Sub
1337! I was bored.
I was trying to suggest just one Select case.
My main reasoning is just that its alot cleaner to read and what if you want more then one access level to be able to use the same command? Making a select case of all your commands, and then haveing one "If MyAccess < ReqAccess then Exit Sub" Line for each command would be easier, but thats just my opinion, and I don't want to get into anything about it.
~-~(HDX)~-~
I would think it would be rather impossible to incorporate all possible ranks into one If/Then or one Select Case/Case structure. Unless of course, you want each rank to have all of the same commands. You would have to direct flow to differing parts of the sub to test whether or not this access can use this command or this command or the next two, etc. How would you set up multiple flows without , incidentally, setting up multiple flows?
:o, um i have my own way in which my bot reads a users access level. all i wanted to know wus a simple way in the bot reading wut is said after a certain message, like in my first post.
Dim Master As String
Master = Form2.txtMaster.text
If LCase(username) = Master And LCase(Message) = Trigger & "say" Then
Send Right(message, Len(message) - 4)
End If
by using that exact code, it used 2 work for me. but for some odd reason 1 day it just stopped. I figured i must have done something wrong with it. i dont need a ton of help on check access or a million other things.
Edit:
........cant belive it wus so obvious, but i figured out wut i did wrong it works now, but ty for the help guys.