Valhalla Legends Archive

Programming => Battle.net Bot Development => Topic started by: DarkMod on April 07, 2003, 10:27 AM

Title: In Channel Commands help:
Post by: DarkMod on April 07, 2003, 10:27 AM
I am having trouble with in channel commands. For example saying in the channel ~kick soandso@useast. I got it to work partially. My problem is that for example if I have a few commands possible (kick, ban, unban, say, etc). It will reconize all of them when trying to use just one. I would say  ~kick soandso, and it would kick him, but i would also get a bunch of that user is not logged on messages, causing the bot to disconnect. Anyone have a way to fix this, or a working way to make in channel commands? Any help will be appreciated. BTW I am using VB
Title: Re:In Channel Commands help:
Post by: Banana fanna fo fanna on April 07, 2003, 12:16 PM
Post your code and I'll give it a look.
Title: Re:In Channel Commands help:
Post by: DarkMod on April 07, 2003, 02:08 PM
I know this code is crap, but i haven't really done in channel commands before, and don't know where to start  :-\ :

QuotePrivate Sub csb_UserTalk(ByVal username As String, ByVal Flags As Long, ByVal Message As String, ByVal Ping As Long, SimulatedEvent As Boolean)

Dim m As String
Dim m2 As String
Dim m3 As String
Dim m4 As String
Dim m5 As String
m = setup.m1.Text
m2 = setup.m2.Text
m3 = setup.m3.Text
m4 = setup.m4.Text
m5 = setup.m5.Text

rtbAdd username & ": " & Message & vbNewLine, &HC0C0C0


If username = m Or username = m2 Or username = m3 Or username = m4 Or username = m5 And Message = setup.trigger.Text & "say" Then
csb.Send username & " orders me to say: " & Right(Message, Len(Message) - 4)
End If
If username = m Or username = m2 Or username = m3 Or username = m4 Or username = m5 And Message = setup.trigger.Text & "kick" Then
csb.Send "/kick " & Right(Message, Len(Message) - 5)
End If
If username = m Or username = m2 Or username = m3 Or username = m4 Or username = m5 And Message = setup.trigger.Text & "ban" Then
csb.Send "/ban " & Right(Message, Len(Message) - 4)
End If
If username = m Or username = m2 Or username = m3 Or username = m4 Or username = m5 And Message = setup.trigger.Text & "unban" Then
csb.Send "/unban " & Right(Message, Len(Message) - 6)
End If

End Sub
Title: Re:In Channel Commands help:
Post by: Banana fanna fo fanna on April 07, 2003, 02:16 PM
Replace your End If's with ElseIf's.
Title: Re:In Channel Commands help:
Post by: DarkMod on April 07, 2003, 02:52 PM
I tried that, but it still does'nt work out for me
Title: Re:In Channel Commands help:
Post by: gorshing on April 07, 2003, 07:38 PM
I would have one if statement to test the usernames.  That way it is only there once and well also be easier to change/modify.  Then within that if statement, I would probably do a switch/case on the messages.

That would make the code look cleaner and also a lot easier to add to it.

I think the problem you are running into is a conflicting boolean tests in the conditional, getting the OR and ANDs mixed up.

I'm not a VB programmer, but in C++ I would group these better just to be safe.

Just my two cents.
Title: Re:In Channel Commands help:
Post by: tA-Kane on April 07, 2003, 11:15 PM
Quote from: gorshing on April 07, 2003, 07:38 PMI think the problem you are running into is a conflicting boolean tests in the conditional, getting the OR and ANDs mixed up.

I agree. You may think of your current code like this psuedocode

If User is UserName1 Then
 Do the command
End If
If User is UserName2 Then
 Do the command
End if
If User is UserName3 Then
 Do the command
End if
If User is UserName 4 Then
 Do the command
End if
If User is Username 5 And Message is Command Then
 Do the command
End if


Also, it does not look like you're getting the command correctly, but I may have missed it... (If message is trigger.text & "kick", then getting Right(Message,Len(Message)-5) should return an empty string, provided that trigger.text is a single-length string).

So, here's the fixed and cleaned up code:

Dim M1 As String
Dim M2 As String
Dim M3 As String
Dim M4 As String
Dim M5 As String
Dim Command As String
Dim ParameterStr As String
M1 = setup.m1.text
M2 = setup.m2.text
M3 = setup.m3.text
M4 = setup.m4.text
M5 = setup.m5.text
Command = NthField(Message," ",1)
ParameterStr = Mid(Message,Len(Command)+2)

rtbAdd username & ": " & Message & vbNewLine, &HC0C0C0

If username = M1 Or username = M2 Or username = M3 Or username = M4 Or username = M5 Then
 Select Case Command
 Case setup.trigger.text & "say"
   csb.Send username & " orders me to say: " & ParameterStr
 Case setup.trigger.text & "kick"
   csb.Send  "/kick " & ParameterStr
 Case setup.trigger.text & "ban"
   csb.Send "/ban " & ParameterStr
 Case setup.trigger.text & "unban"
   csb.Send "/unban " & ParameterStr
 Else
   'unimplemented command, do as you wish
 End Select
End If
Title: Re:In Channel Commands help:
Post by: Etheran on April 08, 2003, 02:38 AM
And soon he will discover arrays and loops..  ;D

But good job at being unique and writing your own code, that's a +1 :)
Title: Re:In Channel Commands help:
Post by: DarkMod on April 08, 2003, 01:35 PM
QuoteCommand = NthField(Message," ",1)...

What exactly is NthField? Sorry for asking, I am trying to do this with as little help as I can, but I am just stumped


Title: Re:In Channel Commands help:
Post by: Banana fanna fo fanna on April 08, 2003, 07:18 PM
Most likely Split(message,"")(1)
Title: Re:In Channel Commands help:
Post by: tA-Kane on April 09, 2003, 05:07 AM
Doesn't VB have a Language Reference document?
Quote from: DarkMod on April 08, 2003, 01:35 PMWhat exactly is NthField? Sorry for asking, I am trying to do this with as little help as I can, but I am just stumped

NthField takes an input string (in this case, the variable named Message), and returns the requested field number (in this case, the first), fields being separated by the separator (in this case, a space).

Split() is similar to NthField, in that it also takes an input string, and a field separator string. But, the difference is that Split() breaks up the input string into an array, each array index being a separate field from the input string.
Title: Re:In Channel Commands help:
Post by: MrRaza on April 09, 2003, 08:28 AM
try giving him an example.


myArray() = Split(string1, ",")