Author | Message | Time |
---|---|---|
DarkMod | 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 | April 7, 2003, 3:27 PM |
St0rm.iD | Post your code and I'll give it a look. | April 7, 2003, 5:16 PM |
DarkMod | I know this code is crap, but i haven't really done in channel commands before, and don't know where to start :-\ : [quote] Private 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[/quote] | April 7, 2003, 7:08 PM |
St0rm.iD | Replace your End If's with ElseIf's. | April 7, 2003, 7:16 PM |
DarkMod | I tried that, but it still does'nt work out for me | April 7, 2003, 7:52 PM |
gorshing | 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. | April 8, 2003, 12:38 AM |
tA-Kane | [quote author=gorshing link=board=17;threadid=979;start=0#msg7281 date=1049762320]I think the problem you are running into is a conflicting boolean tests in the conditional, getting the OR and ANDs mixed up.[/quote] I agree. You may think of your current code like this psuedocode [code] 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 [/code] 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: [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 [/code] | April 8, 2003, 4:15 AM |
Etheran | And soon he will discover arrays and loops.. ;D But good job at being unique and writing your own code, that's a +1 :) | April 8, 2003, 7:38 AM |
DarkMod | [quote] Command = NthField(Message," ",1)... [/quote] 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 | April 8, 2003, 6:35 PM |
St0rm.iD | Most likely Split(message,"")(1) | April 9, 2003, 12:18 AM |
tA-Kane | Doesn't VB have a Language Reference document? [quote author=DarkMod link=board=17;threadid=979;start=0#msg7324 date=1049826905]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[/quote] 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. | April 9, 2003, 10:07 AM |
MrRaza | try giving him an example. [code] myArray() = Split(string1, ",") [/code] | April 9, 2003, 1:28 PM |