• Welcome to Valhalla Legends Archive.
 

Running the commands function

Started by MichaeL, September 01, 2004, 11:56 AM

Previous topic - Next topic

MichaeL

Hey,

I've spent hours, adding a flagging system to my bot. I didn't code it all, I actually used User Bot by UserLoser for a reference.

Here are my flags

D - Designated
M - Master
O - Operator
S - Safelisted
T - Talk
B - Autobanned

Now I have a commands module, and to test it, i just copied the code right from the bot. I also copied the correct funtions, like, Getflags and stuff. I'm just not sure on how to run the command function



Public Function StartCommands(Username As String, Text As String, Optional IsWhispered As Boolean)
On Error Resume Next
Dim Command As String
Dim Flags As String
Dim User As String
Dim Access As String
Dim HasAccess As Boolean
Dim IsBanned As Boolean
Dim IsMaster As Boolean
Dim IsOperator As Boolean
Dim IsSafeListed As Boolean
Dim CanTalk As Boolean
Dim Blah() As String
  Blah = Split(Text, " ")
  Command = Blah(0)
 
  For i = 1 To FrmDatabase.Users.ListItems.Count
      If LCase(Username) = LCase(FrmDatabase.Users.ListItems(i).Text) Then HasAccess = True
  Next i

  If HasAccess = True Then
      Access = FrmDatabase.Users.FindItem(Username).Tag
  Else
      Exit Function
  End If
 
  If LCase(Username) = "Hunting" Then IsMaster = True
 
  If InStr(1, Access, "O") Then IsOperator = True
  If InStr(1, Access, "M") Then IsMaster = True
  If InStr(1, Access, "T") Then CanTalk = True
  If InStr(1, Access, "S") Then IsSafeListed = True
'T Flag
  If (CanTalk) Or (IsMaster) = True Then
      Select Case LCase(Command)
          Case "say"
              If Left(Trim(Mid(Text, 4)), 1) = "/" Then
                  SendStuff Mid(Text, 4)
              Else
                  SendStuff Trim(Mid(Text, 4))
              End If
          Case "version"
              SendStuff "/w " & Username & " UserBot " & App.Major & "." & App.Minor & "." & App.Revision & " by UserLoser. www.GosuGamers.com"
          Case "about"
              SendStuff "/w " & Username & " UserBot " & App.Major & "." & App.Minor & "." & App.Revision & " by UserLoser. www.GosuGamers.com"
          Case "vers"
              SendStuff "/w " & Username & " UserBot " & App.Major & "." & App.Minor & "." & App.Revision & " by UserLoser. www.GosuGamers.com"
          Case "whoami"
              For i = 1 To FrmDatabase.Users.ListItems.Count
                  If LCase(Username) = LCase(FrmDatabase.Users.ListItems(i).Text) Then Found = True: Exit For
              Next i
              If Found = True Then
                  SendStuff "/w " & Username & " " & Username & " => " & FrmDatabase.Users.FindItem(Username).Tag
              Else
                  SendStuff "/w " & Username & " You were not found in the database."
              End If
          Case "whois"
              If Len(Text) = 4 Then
                  SendStuff "/w " & Username & " " & Username & " => " & FrmDatabase.Users.FindItem(Username).Tag
              End If
             
              For i = 1 To FrmDatabase.Users.ListItems.Count
                  If LCase(Blah(1)) = LCase(FrmDatabase.Users.ListItems(i).Text) Then Found = True: Exit For
              Next i
                 
              If Found = True Then
                  SendStuff "/w " & Username & " " & FrmDatabase.Users.FindItem(Blah(1)).Text & " => " & UCase(GetFlags(Blah(1)))
              Else
                  SendStuff "/w " & Username & " User " & Blah(1) & " was not found in the database."
              End If
          Case "find"
              If Len(Text) = 4 Then
                  SendStuff "/w " & Username & " " & Username & " => " & FrmDatabase.Users.FindItem(Username).Tag
              End If
             
              For i = 1 To FrmDatabase.Users.ListItems.Count
                  If LCase(Blah(1)) = LCase(FrmDatabase.Users.ListItems(i).Text) Then Found = True: Exit For
              Next i
                 
              If Found = True Then
                  SendStuff "/w " & Username & " " & FrmDatabase.Users.FindItem(Blah(1)).Text & " => " & UCase(GetFlags(Blah(1)))
              Else
                  SendStuff "/w " & Username & " User " & Blah(1) & " was not found in the database."
              End If
      End Select
  End If
 
'O Flag
  If (IsOperator) Or (IsMaster) = True Then
      Select Case LCase(Command)
          Case "kick"
              If Blah(1) = "*" Then
                  For i = 1 To FrmMain.listchannel.ListItems.Count
                      If GetSafeList(FrmMain.listchannel.ListItems(i).Text) = False Then
                          SendStuff "/kick " & FrmMain.listchannel.ListItems(i).Text
                      End If
                  Next i
              Else
                  SendStuff "/kick " & Mid(Text, 5)
              End If
          Case "ban"
              If Blah(1) = "*" Then
                  For i = 1 To FrmMain.listchannel.ListItems.Count
                      If GetSafeList(FrmMain.listchannel.ListItems(i).Text) = False Then
                          SendStuff "/ban " & FrmMain.listchannel.ListItems(i).Text
                      End If
                  Next i
              Else
                  SendStuff "/ban " & Mid(Text, 4)
              End If
          Case "designate"
              SendStuff "/designate " & Blah(1)
          Case "resign"
              SendStuff "/resign"
          Case "join"
              SendStuff "/join " & Mid(Text, 5)
          Case "unban"
              If Blah(1) = "*" Then
                  For i = 1 To FrmMain.Banned.ListItems.Count
                      SendStuff "/unban " & FrmMain.Banned.ListItems(i).Text
                  Next i
              Else
                  SendStuff "/unban " & Blah(1)
              End If
          Case "leaveban"
              Select Case LCase(Blah(1))
                  Case "on"
                      If LeaveBan = True Then
                          SendStuff "/w " & Username & " Leaveban is already enabled."
                          Exit Function
                      End If
                      LeaveBan = True
                      LeaveBanStart = GetTickCount()
                      SendStuff "Leaveban enabled by " & Username & "."
                      LeaveBanStatus = "Leaveban has been enabled by " & Username & ""
                  Case "off"
                      If LeaveBan = False Then
                          SendStuff "/w " & Username & " Leaveban is already disabled."
                          Exit Function
                      End If
                      LeaveBan = False
                      SendStuff "Leaveban disabled by " & Username & "."
                      LeaveBanStatus = "Leaveban is disabled."
                  Case "status"
                      If LeaveBan = True Then
                          SendStuff "/w " & Username & " Leaveban has been enabled by " & Username & ""
                      Else
                          SendStuff "/w " & Username & " Leaveban is disabled."
                      End If
                      'sendstuff "/w " & Username & " " & LeaveBanStatus
              End Select
          Case "protect"
              Select Case LCase(Blah(1))
                  Case "on"
                      If Protect = True Then
                          SendStuff "/w " & Username & " Protect is already enabled."
                          Exit Function
                      End If
                      Protect = True
                      ProtectStart = GetTickCount()
                      SendStuff "Protect enabled by " & Username & "."
                      ProtectStatus = "protect has been enabled by " & Username & ""
                  Case "off"
                      If Protect = False Then
                          SendStuff "/w " & Username & " Protect is already disabled."
                          Exit Function
                      End If
                      Protect = False
                      SendStuff "Protect disabled by " & Username & "."
                      ProtectStatus = "Protect is disabled."
                  Case "status"
                      If LeaveBan = True Then
                          SendStuff "/w " & Username & " Protect has been enabled by " & Username & ""
                      Else
                          SendStuff "/w " & Username & " Protect is disabled."
                      End If
              End Select
          Case "banned"
              SendStuff "/w " & Username & " " & FrmMain.Banned.ListItems.Count & " users are in the ban memory."
          'Case "banlookup"
          '    Dim BI As Integer
          '    Dim BU As String
          '    BI = frmMain.Banned.FindItem(Blah(1)).Index
          '    BU = frmMain.Banned.ListItems.Item(BI).Text
          '
          '    sendstuff "/w " & Username & " " & BU & " is banned user number " & Val(BI) + 1 & "."
      End Select
  End If
 
'M Flag
  If IsMaster = True Then
      Select Case LCase(Command)
          Case "settrigger"
             vTrigger = LCase(Left(Blah(1), 1))
             SaveINI
             LoadINI
              SendStuff "/w " & Username & " Set trigger to " & vTrigger
          Case "setuser"
              If Blah(1) = "" Then Exit Function
              If Blah(2) = "" Then Exit Function
              AddToDBC Blah(1), Blah(2)
              SendStuff "/w " & Username & " " & LCase(Blah(1)) & " => " & UCase(GetFlags(Blah(1)))
          Case "deluser"
              If Blah(1) = "" Then Exit Function
              FrmDatabase.Users.ListItems.Remove FrmDatabase.Users.FindItem(Blah(1)).Index
              SendStuff "/w " & Username & " Removed " & Blah(1) & " from the database"
          Case "quit"
              End
      End Select
  End If
End Function




Thats my commands module



Public Function GetFlags(Username As String) As String
  With FrmDatabase
      GetFlags = .Users.FindItem(Username).Tag
  End With
End Function




Get flags function^



Public Sub AddToDBC(Username As String, Flags As String)
Dim CFlags As String
Dim AFlags As String
Dim NFlags As String
  With FrmDatabase
      If Flags = "" Then Exit Sub
      Dim Found As Boolean
     
      For i = 1 To .Users.ListItems.Count
          If LCase(.Users.ListItems(i).Text) = LCase(Username) Then
              Found = True
              Exit For
          Else
              Found = False
          End If
      Next i
If Left(Flags, 1) = "+" Then
  CFlags = .Users.FindItem(Username).Tag
  AFlags = .GetDBFlagsC(CFlags & Flags)
  If Found = True Then
      .Users.ListItems.Remove (i)
      .Users.ListItems.Add , , Username
      .Users.FindItem(Username).ListSubItems.Add , , AFlags
      .Users.FindItem(Username).Tag = AFlags
      Exit Sub
  Else
      .Users.ListItems.Add , , Username
      .Users.FindItem(Username).ListSubItems.Add , , AFlags
      .Users.FindItem(Username).Tag = AFlags
  End If
  Exit Sub
ElseIf Left(Flags, 1) = "-" Then
  CFlags = .Users.FindItem(Username).Tag
  AFlags = .GetDBFlagsC(Flags)
  If InStr(1, CFlags, AFlags) Then NFlags = Replace(CFlags, AFlags, "")
  If Found = True Then
      .Users.ListItems.Remove (i)
      .Users.ListItems.Add , , Username
      .Users.FindItem(Username).ListSubItems.Add , , NFlags
      .Users.FindItem(Username).Tag = NFlags
      Exit Sub
  Else
      .Users.ListItems.Add , , Username
      .Users.FindItem(Username).ListSubItems.Add , , NFlags
      .Users.FindItem(Username).Tag = NFlags
  End If
End If
      If Found = True Then
          .Users.ListItems.Remove (i)
          .Users.ListItems.Add , , Username
          .Users.ListItems(.Users.ListItems.Count).ListSubItems.Add , , .GetDBFlagsC(UCase(Flags))
          .Users.ListItems(.Users.ListItems.Count).Tag = .GetDBFlagsC(UCase(Flags))
          Exit Sub
      Else
          .Users.ListItems.Add , , Username
          .Users.ListItems(.Users.ListItems.Count).ListSubItems.Add , , .GetDBFlagsC(UCase(Flags))
          .Users.ListItems(.Users.ListItems.Count).Tag = .GetDBFlagsC(UCase(Flags))
      End If
  End With
SaveDB
End Sub




That adds a user to the database

Now how can I just run the commands function, so i can i do...
<trigger>ban Username
<trigger>version

ect..

DeTaiLs




MichaeL


hismajesty


MichaeL


Soul Taker

So, you copy/pasted code from someone else's bot, and want us to tell you what to do with it?  I have a few ideas...

MichaeL

as i said, thats not what im using, and thats not the point, but thank you so much for your help!

Flame

#7
I find that it's usually easier to understand, debug, and improve code that you actually wrote.

If/When you write your own command function, you're going to want to call it from the part of the BNCS 0x0F Packet called EID_TALK.  If you don't know how to handle the 0x0F packet, refer to The Botdev Site, and search for an 0x0F documentation if it's still there.  I'm sure there's also some information about 0x0F in the Botdev Reference Forum.
The best idea would be to call the StartCommands function with the proper arguements... and if you can't figure those out then I suggest you hit the books.

MichaeL

Nevermind. I got it, when I actually took the time to look at some stuff. Now I'm going to code my own flagging system, and commands function, thank you.

Eli_1

#9
Quote from: MichaeL on September 02, 2004, 08:46 PM
Nevermind. I got it, when I actually took the time to look at some stuff. Now I'm going to code my own flagging system, and commands function, thank you.

Oh, oh!  Don't use InStr() when you do it!

UserLoser.

Please don't say it's by me, that's not my bot.  Although, in the past there was a time where i was helping someone with something, and my name was on it.  But the name UserBot doesn't seem to be right

Networks

Quote from: UserLoser. on September 03, 2004, 04:03 PM
Please don't say it's by me, that's not my bot.  Although, in the past there was a time where i was helping someone with something, and my name was on it.  But the name UserBot doesn't seem to be right

hm I always thought that was your bot..

UserLoser.

#12
Quote from: Networks on September 03, 2004, 05:52 PM
Quote from: UserLoser. on September 03, 2004, 04:03 PM
Please don't say it's by me, that's not my bot.  Although, in the past there was a time where i was helping someone with something, and my name was on it.  But the name UserBot doesn't seem to be right

hm I always thought that was your bot..

You'll know if it's mine if I sent it to you over MSN or AIM.  The story is something like: this kid annoyed me, so I finally helped him a lot.  He thought I 'worked' or 'developed' the whole bot with him, so my name was on there.  IIRC, I also wrote a readme which comes with it (wherever that may be at) since I used it, and other people at that time wanted to use it (for whatever reason).  I don't release source code to my projects at all (although a few times I tend to spam some functions here and there [people from what channels I hang out in may agree :p])

LivedKrad

Well at first you admitted to us that it was indeed not your function. Yet immediately after the posting of this function that you did not make, you said "That is my commands function." And to top it all off, you got sarcastic towards the person who pointed out that you did not code it believing that you were righteous in first saying the it wasn't yours but then going completely hypocritical? Hehe, I like your style.

Grok

I don't understand this snippet:

     Select Case LCase(Command)
         Case "say"
             If Left(Trim(Mid(Text, 4)), 1) = "/" Then
                 SendStuff Mid(Text, 4)
             Else
                 SendStuff Trim(Mid(Text, 4))
             End If


If the 4th character is a /, send the line starting at character 4, without trimming.
If not, trim the line starting at character 4, then send it.

Two things:
1.  What is the purpose?  It will say everything except the ending spaces.
2.  People are probably going to put a space after "say", so starting at character 5 is better.