VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Commands"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Public Sub Command(Username As String, message As String, BnetFlags As String, BnetPing As String, Whisper As Boolean)
On Error Resume Next
Dim CommandName As String, CommandText As String, UserAccess As String, Splt() As String, Temper As al, Found As Boolean, Continue As Boolean, bleh As Boolean
If Len(message) < 1 Then Exit Sub
CommandName = Split(message, " ")(0)
CommandText = Split(message, " ", 2)(1)
If GetAccessIndex(Username) <> -1 Then
    UserAccess = accesslist(GetAccessIndex(Username)).flags
Else
    UserAccess = "-1"
End If
If Whisper = False Then UserAccess = "ACDIJLMORTX"
If InStr(UserAccess, "A") <> 0 And InStr(UserAccess, "R") <> 0 Then UserAccess = Replace(UserAccess, "R", "")
    Select Case LCase(CommandName)
        Case "c", "clan"
            If InStr(UserAccess, "O") <> 0 Then
                Splt() = Split(message, " ")
                Select Case LCase(Splt(1))
                    Case "priv", "private"
                        Send1 "/c private"
                    Case "pub", "public"
                        Send1 "/c public"
                End Select
            End If
        Case "help"
            AllowedFlags = "ACDIJMORTX"
            For I = 1 To Len(UserAccess)
                If InStr(AllowedFlags, Mid(UserAccess, I, 1)) <> 0 Then Continue = True
            Next I
            If Continue = True Then
                Splt() = Split(message, " ")
                Help1 = LCase(Splt(1))
                    Select Case Help1
                        Case "attributes", "attr", "attrs"
                            Sendmsg Whisper, Username, "Attributes: A(Access control), B(Autoban), C(Function control), D(Designated), F(Friend), I(Information), J(Join), L(Locked), M(Master), O(Operator), R(Restricted access control), S(Safelist), T(Talk), X(Designate)"
                        Case "commands", "cmd", "cmds"
                            Sendmsg Whisper, Username, "Commands: ?trigger, add, ban, bancount, cleardb, cq, deletemail, designate, designated, find, findattr, help, helpattr, helpcmd, ignore, ipban, jfp, join, kick, kickcount, mail, mailread, outbox"
                            Sendmsg Whisper, Username, "Commands: phrasebans, protect, reconnect, remove, rejoin, resign, say, server, sethome, settrigger, shutdown, spamban, time, unban, unignore, uptime, userinfo, where, whoami, whois, ver"
                        Case Else
                            Sendmsg Whisper, Username, "For a list of attributes type help attributes. For a list of commands avaliable type help commands. For help on a specific command type helpcmd <command name>."
                            Sendmsg Whisper, Username, "For help on a specific attribute type helpattr <attribute>."
                    End Select
            End If
            
        Case "helpcmd", "helpcommand"
            AllowedFlags = "ACDIJMORTX"
            For I = 1 To Len(UserAccess)
                If InStr(AllowedFlags, Mid(UserAccess, I, 1)) <> 0 Then Continue = True
            Next I
            If Continue = True Then
                Splt() = Split(message, " ")
                Helpcmd = LCase(Splt(1))
                Select Case Helpcmd
                    Case "?trigger", "trigger"
                        Sendmsg Whisper, Username, "?trigger: used to find out the current trigger of the bot. One of the following flags is required to access that command: A, B, C, D, F, I, J, L, M, O, R, S, or T"
                    Case "add"
                        Sendmsg Whisper, Username, "add: used to add users to the database. One of the following flags is required: A, or R. Command alias: adduser"
                    Case "ban"
                        Sendmsg Whisper, Username, "ban: used to ban someone from the channel. Required flag: O"
                    Case "cq"
                        Sendmsg Whisper, Username, "cq: used to clear the bot's queuery. One of the following flags is required: A, C, I, J, M, O, R, or T"
                        Sendmsg Whisper, Username, "cq: command alias: clearqueue, delqueue, shutup, stfu, clearqueuery, deletequeuery"
                    Case "designate"
                        Sendmsg Whisper, Username, "designate: used to designate a user. Required flag: X. Command alias: des"
                    Case "designated"
                        Sendmsg Whisper, Username, "designated: used to check who is currently designated. One of the following flags is required: O, or I"
                        Sendmsg Whisper, Username, "designated: command alias: checkdesignate, checkdes"
                    Case Else
                        Sendmsg Whisper, Username, "Error: This feature is not yet finished and the command you have selected has not yet been entered or you have selected an invalid command"
                End Select
            End If
        Case "helpattr", "helpattribute"
            AllowedFlags = "ACDIJMORTX"
            For I = 1 To Len(UserAccess)
                If InStr(AllowedFlags, Mid(UserAccess, I, 1)) <> 0 Then Continue = True
            Next I
            If Continue = True Then
                Splt() = Split(message, " ")
                Helpattr = UCase(Splt(1))
                Select Case Helpattr
                    Case "A"
                        Sendmsg Whisper, Username, "A(Access): Gives a user the ability to add/remove any flag except 'L', and 'M'. Can not be removed by anyone with the 'R' flag."
                    Case "B"
                        Sendmsg Whisper, Username, "B(Autoban): Will ban anyone without the 'S' flag. Overrides the 'F' flag."
                    Case "C"
                        Sendmsg Whisper, Username, "C(Control): Controls the bot's functions (spamban, channel protection, ect.)."
                    Case "D"
                        Sendmsg Whisper, Username, "D(Designated): Will be auto-designated if a designated user is not present in the channel."
                    Case "F"
                        Sendmsg Whisper, Username, "F(Friend): Lower level safelist. No commands."
                    Case "I"
                        Sendmsg Whisper, Username, "I(Information): Can find information about any user in the database, check the bot's status, and can use the mail commands."
                    Case "J"
                        Sendmsg Whisper, Username, "J(Join): Can make the bot rejoin, resign, or join another channel."
                    Case "L"
                        Sendmsg Whisper, Username, "L(Lock): Locks a user so that only people with the 'M' flag can add/remove them."
                    Case "M"
                        Sendmsg Whisper, Username, "M(Master): Can add/remove any flag (Required flag to add: A). Can not be added/removed by anyone without the 'M' flag."
                    Case "O"
                        Sendmsg Whisper, Username, "O(Operator): Can use the 'ban', 'kick', 'ignore' and 'unignore' commands."
                    Case "R"
                        Sendmsg Whisper, Username, "R(Restricted access control): Can add/remove the flags: B, F, I, O, and S"
                    Case "S"
                        Sendmsg Whisper, Username, "S(Safelist): Can not be banned/kicked. Overrides all banning checks ie: spamban, jfp, ect. No commands."
                    Case "T"
                        Sendmsg Whisper, Username, "T(Talk): Can use the 'say' command."
                    Case "X"
                        Sendmsg Whisper, Username, "X(Designate): Can use the 'designate' command."
                    Case Else
                        Sendmsg Whisper, Username, "Error: Invalid attribute"
                End Select
            End If
        Case "where", "channel"
            AllowedFlags = "ACDIJMORTX"
            For I = 1 To Len(UserAccess)
                If InStr(AllowedFlags, Mid(UserAccess, I, 1)) <> 0 Then Continue = True
            Next I
            If Continue = True Or GetMailIndex(Username) <> -1 Then
                Sendmsg Whisper, Username, "I am currently in the channel: " & VarHome
            End If
        Case "deletemail", "erasemail", "delmail", "deletemessage", "delmsg", "deletemsg", "delmessage", "erasemsg", "clearmessage", "clearmsg", "clearmail", "deletemail", "clearoutbox", "deloutbox", "eraseoutbox"
            'ReDim Preserve maillist(0 To UBound(maillist) - 1)
            AllowedFlags = "I"
            For I = 1 To Len(UserAccess)
                If InStr(AllowedFlags, Mid(UserAccess, I, 1)) <> 0 Then Continue = True
            Next I
            If Continue = True Then
                Splt() = Split(message, " ", 2)
                If UBound(Splt) < 1 Then
                    Sendmsg Whisper, Username, "Error in argument(s)."
                    Exit Sub
                End If
                If LCase(Splt(1)) = "all" Then
                    Do Until GetMailIndex2(Username) = -1
                        RemoveMailNumber (GetMailIndex2(Username))
                    Loop
                    Sendmsg Whisper, Username, "All messages in your outbox have been deleted."
                    SaveMail
                Else
                    For I = 0 To UBound(maillist)
                        If LCase(maillist(I).From) = LCase(Username) Then Count = Count + 1
                        If Count = Splt(1) Then
                            RemoveMailNumber (I)
                            'maillist(I).Username = ""
                            'ReDim Preserve maillist(0 To UBound(maillist) - 1)
                            Sendmsg Whisper, Username, "Message " & Count & " deleted from your outbox."
                            SaveMail
                            Exit Sub
                        End If
                    Next I
                    Sendmsg Whisper, Username, "Error: Message not found"
                End If
            End If
        Case "mail", "botmail", "bm", "bmail"
            Dim MailTemp As ml, From As String, ToMessage As String
            AllowedFlags = "I"
            For I = 1 To Len(UserAccess)
                If InStr(AllowedFlags, Mid(UserAccess, I, 1)) <> 0 Then Continue = True
            Next I
            If Continue = True Then
                Splt() = Split(message, " ", 3)
                If UBound(Splt) < 2 Then
                    Sendmsg Whisper, Username, "Error in argument(s)."
                    Exit Sub
                End If
                From = Splt(1)
                ToMessage = Splt(2)
                If InStr(From, "*") = 0 And InStr(From, "?") = 0 Then
                    MailTemp.Username = From
                    MailTemp.message = ToMessage
                    MailTemp.Date = Date
                    MailTemp.Time = Time
                    MailTemp.From = Username
                    AddMail MailTemp
                    Sendmsg Whisper, Username, "Mail message added for " & From & "."
                    SaveMail
                Else
                    Count = 0
                    For I = 0 To UBound(accesslist)
                        If matches(accesslist(I).Username, From) = True Then
                            If LCase(accesslist(I).Username) <> LCase(Username) Then
                                If InStr(accesslist(I).Username, "*") = 0 And InStr(accesslist(I).Username, "?") = 0 Then
                                        Count = Count + 1
                                        MailTemp.Username = accesslist(I).Username
                                        MailTemp.message = ToMessage
                                        MailTemp.Date = Date
                                        MailTemp.Time = Time
                                        MailTemp.From = Username
                                        AddMail MailTemp
                                End If
                            End If
                        End If
                    Next I
                    SaveMail
                    If Count > 0 Then
                        Sendmsg Whisper, Username, "Mail message(s) added for " & Count & " users."
                        SaveMail
                    Else
                        Sendmsg Whisper, Username, "No users found matching your criteria."
                    End If
                End If
            End If
        Case "outbox"
            AllowedFlags = "I"
            For I = 1 To Len(UserAccess)
                If InStr(AllowedFlags, Mid(UserAccess, I, 1)) <> 0 Then Continue = True
            Next I
            If Continue = True Then
                Count = 0
                For I = 0 To UBound(maillist)
                    If LCase(maillist(I).From) = LCase(Username) Then Count = Count + 1
                Next I
                If Count > 0 Then
                    Send1 "/w " & Username & " You currently have " & Count & " message(s) in your outbox."
                    Count = 0
                    If Len(maillist(0).Username) > 0 Then
                        For I = 0 To UBound(maillist)
                            If LCase(maillist(I).From) = LCase(Username) Then
                                Count = Count + 1
                                Sendmsg Whisper, Username, "Message " & Count & ":" & " To: " & maillist(I).Username & " Date: " & maillist(I).Date & " Time: " & maillist(I).Time & " (" & Format(maillist(I).Time, "HH:MM:SS") & ") Message: " & maillist(I).message
                            End If
                        Next I
                    End If
                    Sendmsg Whisper, Username, "End of message(s)."
                Else
                    Sendmsg Whisper, Username, "Error: You do not have any messages in your outbox"
                End If
            End If
        Case "mailread", "inbox", "readmail", "rm", "readm", "rmail", "mread", "mailr"
            AllowedFlags = "ACDIJMORTX"
            For I = 1 To Len(UserAccess)
                If InStr(AllowedFlags, Mid(UserAccess, I, 1)) <> 0 Then Continue = True
            Next I
            If Continue = True Or GetMailIndex(Username) <> -1 Then
                If GetMailIndex(Username) <> -1 Then
                    For I = 0 To UBound(maillist)
                        If LCase(maillist(I).Username) = LCase(Username) Then Count = Count + 1
                    Next I
                    Send1 "/w " & Username & " You currently have " & Count & " unread message(s) in your inbox."
                    Count = 0
                    For I = 0 To UBound(maillist)
                        If LCase(maillist(I).Username) = LCase(Username) Then
                            Count = Count + 1
                            Sendmsg Whisper, Username, "Message " & Count & ":" & " From: " & maillist(I).From & " Date: " & maillist(I).Date & " Time: " & maillist(I).Time & " (" & Format(maillist(I).Time, "HH:MM:SS") & ") Message: " & maillist(I).message
                        End If
                    Next I
                    Sendmsg Whisper, Username, "End of message(s)."
                    RemoveMail (Username)
                    SaveMail
                Else
                    If UserAccess <> "-1" Then Sendmsg Whisper, Username, "Error: There are no new messages in your inbox"
                End If
            End If
        'Case "trigger"
            'AllowedFlags = "ACDIJMORTX"
            'For I = 1 To Len(UserAccess)
            '    If InStr(AllowedFlags, Mid(UserAccess, I, 1)) <> 0 Then Continue = True
            'Next I
            'If Continue = True Or GetMailIndex(Username) <> -1 Then
            '    If Len(varTrigger) = 1 Then
            '        Sendmsg Whisper, Username, "Trigger: " & varTrigger & " (ALT + 00" & Asc(varTrigger) & ")"
            '    Else
            '        Sendmsg Whisper, Username, "Trigger: " & varTrigger
            '    End If
            'End If
        Case "say", "talk", "speak", "shout"
            If InStr(UserAccess, "T") <> 0 Then
                text = Split(message, " ", 2)(1)
                If Len(text) > 0 Then
                    If Whisper = False Then LocalCommand = True
                    Send3 "" & text
                End If
            End If
        Case "whoami"
        AllowedFlags = "ACDIJMORTX"
        For I = 1 To Len(UserAccess)
            If InStr(AllowedFlags, Mid(UserAccess, I, 1)) <> 0 Then Continue = True
        Next I
        If Continue = True Or GetMailIndex(Username) <> -1 Then
            Count = 0
            For I = 0 To UBound(maillist)
                If LCase(maillist(I).Username) = LCase(Username) Then Count = Count + 1
            Next I
            InboxCount = Count
            Count = 0
            For I = 0 To UBound(maillist)
                If LCase(maillist(I).From) = LCase(Username) Then Count = Count + 1
            Next I
            OutboxCount = Count
            Count = 0
            If Whisper = True Or GetAccessIndex(Username) <> -1 Then
                If UserAccess <> "-1" Then
                    Sendmsg Whisper, Username, "" & accesslist(GetAccessIndex(Username)).Username & " => " & accesslist(GetAccessIndex(Username)).flags & " (Latency: " & BnetPing & "ms, Flags: " & BnetFlags & ") " & "[Mail: (Inbox: " & InboxCount & ") (Outbox: " & OutboxCount & ")]"
                Else
                    Sendmsg Whisper, Username, Username & " => Guest (Latency: " & BnetPing & "ms, Flags: " & BnetFlags & ") " & "[Mail: (Inbox: " & InboxCount & ") (Outbox: " & OutboxCount & ")]"
                End If
            ElseIf Whisper = False Then
                AddC True, Form1.TALK, vbRed, "Bot: " & Username & " => ACDIJLMORTX (Latency: " & BnetPing & "ms, Flags: " & BnetFlags & ") " & "[Mail: (Inbox: " & InboxCount & ") (Outbox: " & OutboxCount & ")]"
                LocalCommand = True
            End If
        End If
        Case "find", "seek", "finduser", "findusers"
            If InStr(UserAccess, "I") <> 0 Then
                NameToFind = Split(message, " ", 2)(1)
                If Len(NameToFind) < 1 Then
                    Sendmsg Whisper, Username, "Error in argument(s)."
                    Exit Sub
                End If
                If InStr(NameToFind, "*") <> 0 Or InStr(NameToFind, "?") <> 0 Then
                    For I = 0 To UBound(accesslist)
                        If matches(accesslist(I).Username, NameToFind) = True Then
                            NamesC = NamesC + 1
                            If Len(Names) < 101 Then
                                Names = Names & accesslist(I).Username & ":" & accesslist(I).flags & ", "
                            Else
                                Sendmsg Whisper, Username, "Found user(s): " & Mid(Names, 1, Len(Names) - 2)
                                Names = accesslist(I).Username & ":" & accesslist(I).flags & ", "
                            End If
                        End If
                    Next I
                    If Len(Names) > 0 Then
                        Sendmsg Whisper, Username, "Found user(s): " & Mid(Names, 1, Len(Names) - 2)
                        Names = accesslist(I).Username & ":" & accesslist(I).flags & ", "
                    End If
                    If NamesC < 1 Then
                        Sendmsg Whisper, Username, "No users found matching your search criteria."
                        Exit Sub
                    End If
                Else
                    If GetAccessIndex(NameToFind) <> -1 Then
                        Sendmsg Whisper, Username, "Found user(s): " & accesslist(GetAccessIndex(NameToFind)).Username & ":" & accesslist(GetAccessIndex(NameToFind)).flags
                    Else
                        Sendmsg Whisper, Username, "User " & NameToFind & " was not found in the database."
                    End If
                End If
            End If
        Case "findattr", "findattrs", "findattribute", "findattributes", "findflags", "findflag"
            If InStr(UserAccess, "I") = 0 Then Exit Sub
                Splt() = Split(message, " ", 3)
                NameToFind = UCase(Splt(1))
                If Len(NameToFind) < 1 Then
                    Sendmsg Whisper, Username, "Error in argument(s)."
                    Exit Sub
                End If
                AllowedFlags = "ABCDFIJLMORSTX"
                For I = 1 To Len(UserAccess)
                    If InStr(AllowedFlags, Mid(NameToFind, I, 1)) <> 0 Then
                        Continue = False
                    Else
                        Continue = True
                        Exit For
                    End If
                Next I
                If Continue = True Then
                    Sendmsg Whisper, Username, "Error: Invalid attribute(s)"
                    Exit Sub
                End If
                NameToFind = Alphabetize("" & NameToFind)
                For I = 0 To UBound(accesslist)
                    For P = 1 To Len(NameToFind)
                        If InStr(accesslist(I).flags, Mid(NameToFind, P, 1)) <> 0 And Found = False Then
                           Found = False
                        Else
                           Found = True
                        End If
                    Next P
                    If Found = False Then
                        NamesC = NamesC + 1
                        If Len(Names) < 101 Then
                            Names = Names & accesslist(I).Username & ":" & accesslist(I).flags & ", "
                        Else
                            Sendmsg Whisper, Username, "Found user(s): " & Mid(Names, 1, Len(Names) - 2)
                            Names = accesslist(I).Username & ":" & accesslist(I).flags & ", "
                        End If
                    Else
                        Found = False
                    End If
                Next I
                If Len(Names) > 0 Then
                    Sendmsg Whisper, Username, "Found user(s): " & Mid(Names, 1, Len(Names) - 2)
                    Names = ""
                End If
                If NamesC < 1 Then
                    Sendmsg Whisper, Username, "No users found matching your search criteria."
                    Exit Sub
                End If
        Case "whois", "info", "information"
        If InStr(UserAccess, "I") = 0 Then Exit Sub
            NameToFind = Split(message, " ", 2)(1)
            If Len(NameToFind) < 1 Then
                Sendmsg Whisper, Username, "Error in argument(s)."
                Exit Sub
            End If
        If GetAccessIndex(NameToFind) = -1 Then
            Sendmsg Whisper, Username, "User " & NameToFind & " was not found in the database."
        Else
            Sendmsg Whisper, Username, "" & accesslist(GetAccessIndex(NameToFind)).Username & " => " & accesslist(GetAccessIndex(NameToFind)).flags & " [(Added by: " & accesslist(GetAccessIndex(NameToFind)).AddedBy & " on " & accesslist(GetAccessIndex(NameToFind)).AddedDate & " at " & accesslist(GetAccessIndex(NameToFind)).AddedTime & ") (Last seen: " & accesslist(GetAccessIndex(NameToFind)).LastSeenDate & ", " & accesslist(GetAccessIndex(NameToFind)).LastSeenTime & ")]"
        End If
        Case "time", "date"
            If InStr(UserAccess, "I") <> 0 Then
                Sendmsg Whisper, Username, "Current Time: " & Time & " (" & Format(Time, "HH:MM:SS") & ") Current Date: " & Date
            End If
        Case "cq", "clearqueue", "delqueue", "shutup", "stfu", "clearqueuery", "deletequeuery"
        AllowedFlags = "ACIJMORT"
        For I = 1 To Len(UserAccess)
            If InStr(AllowedFlags, Mid(UserAccess, I, 1)) <> 0 Then Continue = True
        Next I
        If Continue = True Then
            pbuffer.Clear
            FastQueue = False
            Q.QClear
            If Whisper = False Then
                AddC True, Form1.TALK, vbRed, "Bot: Queuery cleared"
                LocalCommand = True
            End If
        End If
        Case "unban"
        If Whisper = False Then LocalCommand = True
        If userlist(GetlistIndex(MyName)).Operator = False Then Exit Sub
        NameToUnban = Mid(message, 7, Len(message))
        If InStr(UserAccess, "O") <> 0 Then
            If InStr(NameToUnban, "*") <> 0 Or InStr(NameToUnban, "?") <> 0 Then
                For I = 0 To UBound(banlist)
                    If matches(banlist(I).Username, NameToUnban) = True Then
                        Send1 "/unban " & banlist(I).Username
                    End If
                Next I
            Else
                Send1 "/unban " & NameToUnban
            End If
        End If
        Case "version", "about", "ver"
        If Whisper = False Then LocalCommand = True
        AllowedFlags = "ACDIJMORTX"
        For I = 1 To Len(UserAccess)
            If InStr(AllowedFlags, Mid(UserAccess, I, 1)) <> 0 Then Continue = True
        Next I
        If Continue = True Or GetMailIndex(Username) <> -1 Then
            If GetlistIndex(Username) <> -1 And Whisper = True Then
                Send1 "Unknown Bot v" & App.Major & "." & App.Minor & "." & App.Revision & " By LoRd]ZeR0[ (http://blizzside.com/lord/)"
            Else
                Sendmsg Whisper, Username, "Unknown Bot v" & App.Major & "." & App.Minor & "." & App.Revision & " By LoRd]ZeR0[ (http://blizzside.com/lord/)"
            End If
        End If
        Case "add", "adduser"
        Dim Tempz As al, flags As Boolean
        AllowedFlags = "ABCDFIJLMORSTX"
        If InStr(UserAccess, "A") <> 0 Or InStr(UserAccess, "R") <> 0 Then
            message = Mid(message, 5, Len(message))
            Splt() = Split(message, " ", 2)
            AddName = Splt(0)
            AddFlags = UCase(Splt(1))
            If Len(AddName) < 1 Then
                Sendmsg Whisper, Username, "Error: Invalid username"
                Exit Sub
            End If
            If Len(AddFlags) < 1 Then
                Sendmsg Whisper, Username, "Error: Invalid attribute(s)"
                Exit Sub
            End If
            For I = 1 To Len(AddFlags)
                If InStr(AddFlags1, Mid(AddFlags, I, 1)) = 0 Then
                    AddFlags1 = AddFlags1 & Mid(AddFlags, I, 1)
                End If
            Next I
            If InStr(AddName, "%") <> 0 Then
                Dim Spl() As String
                Spl() = Split(AddName, "%", 2)
                Select Case UCase(Spl(1))
                    Case "DRTL"
                    Case "SSHR"
                    Case "D2DV"
                    Case "D2XP"
                    Case "STAR"
                    Case "SEXP"
                    Case "JSTR"
                    Case "W2BN"
                    Case "WAR3"
                    Case "DSHR"
                    Case "W3XP"
                    Case "CHAT"
                    Case "GFOFFICIAL"
                    Case "GFPLAYER"
                    Case "PLUG"
                    Case "SPOOF0"
                    Case "SPOOF1"
                    Case Else
                        Sendmsg Whisper, Username, "Error: Invalid username"
                        Exit Sub
                End Select
                AllowedFlags2 = "BL"
                AddName = UCase(AddName)
                For I = 1 To Len(AddFlags1)
                    If Mid(AddFlags1, 1, 1) = "+" Then
                        AddFlags1 = Mid(AddFlags1, 2, Len(AddFlags1))
                    ElseIf Mid(AddFlags1, 1, 1) = "-" Then
                        AddFlags1 = Mid(AddFlags1, 2, Len(AddFlags1))
                    End If
                    If InStr(AllowedFlags2, Mid(AddFlags1, I, 1)) = 0 Then
                        Sendmsg Whisper, Username, "Error: Invalid attribute(s)"
                        Exit Sub
                    End If
                Next I
            End If
            AddFlags = AddFlags1
            AddFlags1 = AddFlags
            For I = 1 To Len(AddFlags1)
                If Mid(AddFlags1, 1, 1) = "+" Then
                    AddFlags1 = Mid(AddFlags1, 2, Len(AddFlags1))
                ElseIf Mid(AddFlags1, 1, 1) = "-" Then
                    AddFlags1 = Mid(AddFlags1, 2, Len(AddFlags1))
                End If
                If InStr(AllowedFlags, Mid(AddFlags1, I, 1)) = 0 Then
                    Sendmsg Whisper, Username, "Error: Invalid attribute(s)"
                    Exit Sub
                End If
            Next I
            If GetAccessIndex(AddName) <> -1 Then
                AddUserCurrent = accesslist(GetAccessIndex(AddName)).flags
                If InStr(AddUserCurrent, "L") <> 0 And InStr(UserAccess, "M") = 0 Then
                    Sendmsg Whisper, Username, "Error: You do not have sufficient access to do that"
                    Exit Sub
                End If
            Else
                AddUserCurrent = -1
            End If
                
                If InStr(AddFlags, "L") <> 0 And InStr(UserAccess, "M") = 0 Or InStr(AddFlags, "M") <> 0 And InStr(UserAccess, "M") = 0 Then
                    Sendmsg Whisper, Username, "Error: You do not have sufficient access to do that"
                    Exit Sub
                End If
                If InStr(AddFlags, "M") <> 0 And InStr(UserAccess, "M") = 0 Then
                    Sendmsg Whisper, Username, "Error: You do not have sufficient access to do that"
                    Exit Sub
                End If
                If InStr(UserAccess, "R") <> 0 Then
                    If InStr(AddFlags, "C") <> 0 Or InStr(AddFlags, "R") <> 0 Or InStr(AddFlags, "A") Or InStr(AddFlags, "J") Or InStr(AddFlags, "T") Or InStr(AddFlags, "D") Or InStr(AddFlags, "X") Then
                        Sendmsg Whisper, Username, "Error: You do not have sufficient access to do that"
                        Exit Sub
                    End If
                End If
                If Mid(AddFlags, 1, 1) = "+" Then
                AddFlags = Mid(AddFlags, 2, Len(AddFlags))
                If AddUserCurrent <> -1 Then
                    AddFlags = AddFlags & AddUserCurrent
                End If
                AddFlags = Alphabetize("" & AddFlags)
                If GetAccessIndex(AddName) <> -1 Then
                    AddC True, Form4.TALK, vbGreen, "Bot: " & Username & " has modified " & AddName & " (New flags: " & AddFlags & ")."
                    AddName = accesslist(GetAccessIndex(AddName)).Username
                    RemoveAccess (AddName)
                Else
                    AddC True, Form4.TALK, vbGreen, "Bot: " & Username & " has added " & AddName & " to the database with the flags of " & AddFlags & "."
                End If
                Tempz.Username = AddName
                Tempz.AddedBy = Username
                Tempz.flags = AddFlags
                Tempz.LastSeenTime = "00:00:00"
                Tempz.LastSeenDate = "0/0/0"
                Tempz.AddedTime = Format(Time, "HH:MM:SS")
                Tempz.AddedDate = Date
                AddAccess Tempz
                If InStr(accesslist(GetAccessIndex(AddName)).flags, "B") <> 0 Then AutoDesignate
                Sendmsg Whisper, Username, "" & accesslist(GetAccessIndex(AddName)).Username & " => " & accesslist(GetAccessIndex(AddName)).flags
                ElseIf Mid(AddFlags, 1, 1) = "-" Then
                AddFlags = Mid(AddFlags, 2, Len(AddFlags))
                If GetAccessIndex(AddName) = -1 Then
                    Sendmsg Whisper, Username, "Error: That user is not currently in the database"
                    Exit Sub
                End If
                For I = 1 To Len(AddFlags)
                    AddUserCurrent = Replace(AddUserCurrent, Mid(AddFlags, I, 1), "")
                Next I
                AddFlags = AddUserCurrent
                If Len(AddFlags) < 1 Then
                    Sendmsg Whisper, Username, "Removed user " & accesslist(GetAccessIndex(AddName)).Username & " from the database."
                    If GetAccessIndex(AddName) <> -1 Then RemoveAccess (AddName)
                    AddC True, Form4.TALK, vbGreen, "Bot: " & Username & " has removed user " & AddName & "from the database."
                    SaveDatabase
                    Exit Sub
                End If
                If GetAccessIndex(AddName) <> -1 Then
                    AddName = accesslist(GetAccessIndex(AddName)).Username
                    RemoveAccess (AddName)
                End If
                AddFlags = Alphabetize("" & AddFlags)
                Tempz.Username = AddName
                Tempz.AddedBy = Username
                Tempz.flags = AddFlags
                Tempz.LastSeenTime = "00:00:00"
                Tempz.LastSeenDate = "0/0/0"
                Tempz.AddedTime = Format(Time, "HH:MM:SS")
                Tempz.AddedDate = Date
                AddAccess Tempz
                AddC True, Form4.TALK, vbGreen, "Bot: " & Username & " has modified " & AddName & " (New flags: " & AddFlags & ")."
                If InStr(accesslist(GetAccessIndex(AddName)).flags, "B") <> 0 Then AutoDesignate
                Sendmsg Whisper, Username, "" & accesslist(GetAccessIndex(AddName)).Username & " => " & accesslist(GetAccessIndex(AddName)).flags
                Else
                AddFlags = Alphabetize("" & AddFlags)
                If GetAccessIndex(AddName) <> -1 Then
                    RemoveAccess (AddName)
                    AddC True, Form4.TALK, vbGreen, "Bot: " & Username & " has modified " & AddName & " (New flags: " & AddFlags & ")."
                Else
                    AddC True, Form4.TALK, vbGreen, "Bot: " & Username & " has added " & AddName & " to the database with the flags of " & AddFlags & "."
                End If
                Tempz.Username = AddName
                Tempz.AddedBy = Username
                Tempz.flags = AddFlags
                Tempz.LastSeenTime = "00:00:00"
                Tempz.LastSeenDate = "0/0/0"
                Tempz.AddedTime = Format(Time, "HH:MM:SS")
                Tempz.AddedDate = Date
                AddAccess Tempz
                If InStr(accesslist(GetAccessIndex(AddName)).flags, "B") <> 0 Then AutoDesignate
                Sendmsg Whisper, Username, "" & accesslist(GetAccessIndex(AddName)).Username & " => " & accesslist(GetAccessIndex(AddName)).flags
                End If
        End If
        SaveDatabase
        Case "settrigger", "changetrigger"
            If InStr(UserAccess, "M") <> 0 Then
                Splt() = Split(message, " ", 2)
                Trigger = Splt(1)
                varTrigger = Trigger
                SaveConfig
                If Len(varTrigger) = 1 Then
                    Sendmsg Whisper, Username, "Trigger set to: " & varTrigger & " (ALT + 00" & Asc(varTrigger) & ")"
                Else
                    Sendmsg Whisper, Username, "Trigger set to: " & varTrigger
                End If
            End If
        Case "sethome"
            If InStr(UserAccess, "M") <> 0 Then
                Splt() = Split(message, " ", 2)
                Channel = Splt(1)
                VarHome = Channel
                SaveConfig
                Sendmsg Whisper, Username, "Home channel set to: " & VarHome
            End If
        Case "ban"
        If Whisper = False Then LocalCommand = True
        If userlist(GetlistIndex(MyName)).Operator = False Then Exit Sub
        If InStr(UserAccess, "O") <> 0 Then
        Splt() = Split(message, " ", 3)
        UserNameToBan = Splt(1)
        If UBound(Splt) > 1 Then
            BanMessage = Splt(2)
            
        ElseIf UBound(Splt) < 1 Then
            Sendmsg Whisper, Username, "Error in argument(s)."
            Exit Sub
        End If
        UserNameToBan = ConvertBan("" & UserNameToBan)
            'If CheckClientSafe("" & userlist(I).Product, "" & userlist(I).Flags,  "" & userlist(I).latency) = False And  And SafeListCheck(userlist(I).Username) = False And FriendsListCheck(userlist(I).Username) = False Then
            If InStr(message, "*") <> 0 Or InStr(message, "?") <> 0 Then
                For I = 0 To UBound(userlist)
                    If matches(userlist(I).Username, UserNameToBan) = True Then
                        If userlist(GetlistIndex(userlist(I).Username)).Operator = False And LCase(GetlistIndex(userlist(I).Username)) <> LCase(MyName) Then
                            If SafeListCheck(userlist(I).Username) = False And FriendsListCheck(userlist(I).Username) = False Then
                                Send2 "/ban " & userlist(I).Username & " " & BanMessage
                            End If
                        End If
                    End If
                Next I
            Else
                If userlist(GetlistIndex(UserNameToBan)).Operator = False And LCase(UserNameToBan) <> LCase(MyName) Then
                    If Len(UserNameToBan) < 1 Then
                        Sendmsg Whisper, Username, "Error: Invalid username"
                        Exit Sub
                    End If
                    If SafeListCheck("" & UserNameToBan) = False Then
                        Send2 "/ban " & UserNameToBan & " " & BanMessage
                    Else
                        Sendmsg Whisper, Username, "Error: You do not have permission to do that"
                    End If
                End If
            End If
        End If
        Case "ping", "getinfo", "userinfo", "flags", "getlag", "idletime", "useridle", "idleinfo"
        If InStr(UserAccess, "I") = 0 Then Exit Sub
        Splt() = Split(message, " ")
        If UBound(Splt) < 1 Then
            Sendmsg Whisper, Username, "Error in argument(s)."
            Exit Sub
        End If
        UserToFind = Splt(1)
        UserToFind = userlist(GetlistIndex(UserToFind)).Username
        UserIndex = GetlistIndex(UserToFind)
        If GetlistIndex(UserToFind) = -1 Then
            Sendmsg Whisper, Username, "Error: That user in not currently in this channel"
        Else
            Sendmsg Whisper, Username, "" & UserToFind & " is here using " & MakeLongClientName(userlist(UserIndex).Product) & " with a " & userlist(UserIndex).Latency & "ms ping (Lag icon: " & GetLagIcon("" & userlist(UserIndex).Latency, "" & userlist(UserIndex).flags) & ") and flags of " & userlist(UserIndex).flags & " (" & CheckUserFlags("" & userlist(UserIndex).flags) & ")" & "; Join time: " & userlist(UserIndex).JoinDate & ", " & userlist(UserIndex).JoinTime & "; Idle for: " & FormatCount(GetTickCount - userlist(UserIndex).LastTick, All3) & "."
        End If
        Case "kick"
        If Whisper = False Then LocalCommand = True
        If userlist(GetlistIndex(MyName)).Operator = False Then Exit Sub
        If InStr(UserAccess, "O") <> 0 Then
        Splt() = Split(message, " ", 3)
        UserNameToBan = Splt(1)
        If UBound(Splt) > 1 Then
            BanMessage = Splt(2)
            
        ElseIf UBound(Splt) < 1 Then
            Sendmsg Whisper, Username, "Error in argument(s)."
            Exit Sub
        End If
        UserNameToBan = ConvertBan("" & UserNameToBan)
        
            If InStr(message, "*") <> 0 Or InStr(message, "?") <> 0 Then
                For I = 0 To UBound(userlist)
                    If matches(userlist(I).Username, UserNameToBan) = True Then
                        If userlist(GetlistIndex(userlist(I).Username)).Operator = False And LCase(GetlistIndex(userlist(I).Username)) <> LCase(MyName) Then
                            If SafeListCheck(userlist(I).Username) = False And FriendsListCheck(userlist(I).Username) = False Then
                                Send2 "/kick " & userlist(I).Username & " " & BanMessage
                            End If
                        End If
                    End If
                Next I
            Else
                If userlist(GetlistIndex(UserNameToBan)).Operator = False And LCase(UserNameToBan) <> LCase(MyName) Then
                    If Len(UserNameToBan) < 1 Then
                        Sendmsg Whisper, Username, "Error: Invalid username"
                        Exit Sub
                    End If
                    If SafeListCheck("" & UserNameToBan) = False Then
                        Send2 "/kick " & UserNameToBan & " " & BanMessage
                    Else
                        Sendmsg Whisper, Username, "Error: You do not have permission to do that"
                    End If
                End If
            End If
        End If
        Case "cleardb", "cleardatabase", "deletedb", "deletedatabase", "deldb", "deldatabase", "purgedb", "purgedatabase"
        If InStr(UserAccess, "M") = 0 Then Exit Sub
        For I = 0 To UBound(accesslist)
            If InStr(accesslist(I).flags, "M") = 0 Then
                Usernames = Usernames & accesslist(I).Username & ", "
            End If
        Next I
        Splt() = Split(Usernames, ", ")
        For I = 0 To UBound(Splt)
            RemoveAccess (Splt(I))
        Next I
        'For I = 0 To UBound(accesslist)
        '    If InStr(accesslist(I).Flags, "M") <> 0 Then
        '        Bleh = False
        '        Exit For
        '    End If
        '    Bleh = True
        'Next I
        'Loop
        Sendmsg Whisper, Username, "Erased all users without the 'M' flag from the database."
        Case "unignore"
        If InStr(UserAccess, "O") = 0 Then Exit Sub
        Splt() = Split(message, " ", 2)
        UserNameToBan = Splt(1)
        UserNameToBan = ConvertBan("" & UserNameToBan)
        Send1 "/unignore " & UserNameToBan
        Case "ignore"
        If Whisper = False Then LocalCommand = True
        If InStr(UserAccess, "O") <> 0 Then
        Splt() = Split(message, " ", 3)
        UserNameToBan = Splt(1)
        If UBound(Splt) > 1 Then
            BanMessage = Splt(2)
        ElseIf UBound(Splt) < 1 Then
            Sendmsg Whisper, Username, "Error in argument(s)."
            Exit Sub
        End If
        UserNameToBan = ConvertBan("" & UserNameToBan)
            If InStr(message, "*") <> 0 Or InStr(message, "?") <> 0 Then
                For I = 0 To UBound(userlist)
                    If matches(userlist(I).Username, UserNameToBan) = True Then
                        If userlist(GetlistIndex(userlist(I).Username)).Operator = False And LCase(GetlistIndex(userlist(I).Username)) <> LCase(MyName) Then
                            If SafeListCheck(userlist(I).Username) = False And FriendsListCheck(userlist(I).Username) = False Then
                                Send2 "/ignore " & userlist(I).Username & " " & BanMessage
                            End If
                        End If
                    End If
                Next I
            Else
                If userlist(GetlistIndex(UserNameToBan)).Operator = False And LCase(UserNameToBan) <> LCase(MyName) Then
                    If Len(UserNameToBan) < 1 Then
                        Sendmsg Whisper, Username, "Error: Invalid username"
                        Exit Sub
                    End If
                    If SafeListCheck("" & UserNameToBan) = False Then
                        Send2 "/ignore " & UserNameToBan & " " & BanMessage
                    Else
                        Sendmsg Whisper, Username, "Error: You do not have permission to do that"
                    End If
                End If
            End If
        End If
        Case "resign", "rs"
        If Whisper = False Then LocalCommand = True
        If userlist(GetlistIndex(MyName)).Operator = False Then Exit Sub
        If InStr(UserAccess, "J") <> 0 Then
            If userlist(GetlistIndex(MyName)).Operator = True Then
                Send1 "/resign"
            End If
        End If
        Case "rejoin", "rj"
        If Whisper = False Then LocalCommand = True
        If InStr(UserAccess, "J") <> 0 Then
            If userlist(GetlistIndex(MyName)).Operator = True Then
                Send1 "/resign"
            Else
                With pbuffer
                    .InsertDWORD 2
                    .InsertNTString "The Void"
                    .SendPacket &HC
                    .InsertDWORD 2
                    .InsertNTString "" & MyChannel
                    .SendPacket &HC
                End With
            End If
        End If
        Case "designate", "des", "op", "giveops"
        If Whisper = False Then LocalCommand = True
        If userlist(GetlistIndex(MyName)).Operator = False Then Exit Sub
        If InStr(UserAccess, "X") <> 0 Then
            Splt() = Split(message, " ")
            UserNameToDesignate = Splt(1)
            Send1 "/designate " & UserNameToDesignate
        End If
        Case "rem", "remove", "removeuser", "remuser", "del", "delete"
        If InStr(UserAccess, "A") <> 0 Or InStr(UserAccess, "R") <> 0 Then
            Splt() = Split(message, " ")
            UserNameToRemove = Splt(1)
            If GetAccessIndex(UserNameToRemove) <> -1 Then
                UserNameToRemove = accesslist(GetAccessIndex(UserNameToRemove)).Username
                AccessToRemove = accesslist(GetAccessIndex(UserNameToRemove)).flags
                If InStr(AccessToRemove, "L") <> 0 And InStr(UserAccess, "M") = 0 Then
                    Sendmsg Whisper, Username, "Error: You do not have sufficient access to do that"
                    Exit Sub
                End If
                If InStr(UserAccess, "R") <> 0 Then
                    If InStr(AccessToRemove, "C") <> 0 Or InStr(AccessToRemove, "R") <> 0 Or InStr(AccessToRemove, "A") Or InStr(AccessToRemove, "J") Or InStr(AccessToRemove, "T") Then
                        Sendmsg Whisper, Username, "Error: You do not have sufficient access to do that"
                        Exit Sub
                    End If
                End If
                RemoveAccess (UserNameToRemove)
                AutoDesignate
                Sendmsg Whisper, Username, "Removed user " & UserNameToRemove & " from the database."
                AddC True, Form4.TALK, vbGreen, "Bot: " & Username & " has removed user " & UserNameToRemove & " from the database."
                SaveDatabase
            Else
                Sendmsg Whisper, Username, "Error: That user is not in the database"
                Exit Sub
            End If
        End If
        Case "join"
        If InStr(UserAccess, "J") <> 0 Then
        Channel = Mid(message, 6, Len(message))
        If LCase(Channel) = LCase(MyChannel) Then
            Sendmsg Whisper, Username, "Error: I am already in that channel"
            Exit Sub
        End If
        If Left(Channel, 1) = " " Or Len(Channel) < 1 Or Len(Channel) > 31 Then
            Sendmsg Whisper, Username, "Error: Invalid channel name"
            Exit Sub
        End If
        MyChannel2 = Channel
            With pbuffer
                .InsertDWORD 2
                .InsertNTString "" & Channel
                .SendPacket &HC
            End With
        End If
        If Whisper = False Then LocalCommand = True
        Case "designated", "checkdesignate", "checkdes"
        If userlist(GetlistIndex(MyName)).Operator = False Then Exit Sub
        If InStr(UserAccess, "I") = 0 And InStr(UserAccess, "O") = 0 And InStr(UserAccess, "X") = 0 Then Exit Sub
            If Len(Designated) > 0 Then
                Sendmsg Whisper, Username, "Currently designated user: " & Designated
            ElseIf Len(Designated) < 1 Then
                Sendmsg Whisper, Username, "There is no currently designated user."
            End If
        Case "uptime", "botuptime", "systemuptime", "sysuptime", "connectionuptime", "conuptime", "chanuptime", "channeluptime"
            If InStr(UserAccess, "I") = 0 Then Exit Sub
            Sendmsg Whisper, Username, "System uptime: " & FormatCount(GetTickCount, All3) & " Bot uptime: " & FormatCount(GetTickCount - BotUptime, All3)
            Sendmsg Whisper, Username, "Connection uptime: " & FormatCount(GetTickCount - ConnectionUptime, All3) & " Channel uptime: " & FormatCount(GetTickCount - ChannelUptime, All3)
        Case "stats"
            If InStr(UserAccess, "I") = 0 Then Exit Sub
            Splt() = Split(message, " ")
            user = Splt(1)
            If GetlistIndex(user) = -1 Then
                Sendmsg Whisper, Username, "Error: That user in not currently in this channel"
            Else
                Sendmsg Whisper, Username, "" & userlist(GetlistIndex(user)).Username & " is here using " & MakeLongClientName(userlist(GetlistIndex(user)).Product) & ": " & userlist(GetlistIndex(user)).Stats
            End If
        Case "spamban", "spammingban", "spammingbanning", "spambanning"
            Splt() = Split(message, " ")
            Word = Splt(1)
            Select Case LCase(Word)
                Case "on"
                    If InStr(UserAccess, "C") = 0 Then Exit Sub
                    If Spamban = True Then
                        Sendmsg Whisper, Username, "Error: Spamban is already enabled"
                    Else
                        Spamban = True
                        Sendmsg Whisper, Username, "Spamban enabled."
                    End If
                Case "off"
                    If InStr(UserAccess, "C") = 0 Then Exit Sub
                    If Spamban = False Then
                        Sendmsg Whisper, Username, "Error: Spamban is already disabled"
                    Else
                        Spamban = False
                        Sendmsg Whisper, Username, "Spamban disabled."
                    End If
                Case "status", "stats"
                If InStr(UserAccess, "I") = 0 And InStr(UserAccess, "C") = 0 Then Exit Sub
                    If Spamban = False Then
                        Sendmsg Whisper, Username, "Spamban is currently disabled."
                    Else
                        Sendmsg Whisper, Username, "Spamban is currently enabled."
                    End If
                Case Else
                    Sendmsg Whisper, Username, "Error in argument(s)."
            End Select
        Case "phrases", "phrasebans", "pbs", "phraseban", "phrasebanning", "pb", "phrase"
            Splt() = Split(message, " ", 3)
            Word = Splt(1)
            Select Case LCase(Word)
                Case "add"
                    If InStr(UserAccess, "C") = 0 Then Exit Sub
                    If UBound(Splt) < 2 Then
                        Sendmsg Whisper, Username, "Error in argument(s)."
                        Exit Sub
                    End If
                    If GetAGroupIndex(Splt(2)) = -1 Then
                        Dim hrm As pbs
                        hrm.AddedBy = Username
                        hrm.Username = Splt(2)
                        hrm.AddedDate = Date
                        hrm.AddedTime = Time
                        AddAGroup hrm
                        Sendmsg Whisper, Username, "Added phrase: " & Splt(2)
                        SavePhrases
                    Else
                        Sendmsg Whisper, Username, "Error: Phrase already exists"
                    End If
                Case "rem"
                    If InStr(UserAccess, "C") = 0 Then Exit Sub
                    If UBound(Splt) < 2 Then
                        Sendmsg Whisper, Username, "Error in argument(s)."
                        Exit Sub
                    End If
                    If GetAGroupIndex(Splt(2)) <> -1 Then
                        RemoveAGroup (Splt(2))
                        Sendmsg Whisper, Username, "Removed phrase: " & Splt(2)
                        SavePhrases
                    Else
                        Sendmsg Whisper, Username, "Error: Phrase not found"
                    End If
                Case "list"
                    If InStr(UserAccess, "I") = 0 And InStr(UserAccess, "C") = 0 Then Exit Sub
                    For I = 0 To UBound(PhraseBans)
                        If Len(PhraseBans(I).Username) > 0 Then
                            NamesC = NamesC + 1
                            If Len(Names) < 101 Then
                                Names = Names & PhraseBans(I).Username & ", "
                            Else
                                Sendmsg Whisper, Username, "Found phrase(s): " & Mid(Names, 1, Len(Names) - 2)
                                Names = PhraseBans(I).Username & ", "
                            End If
                        End If
                    Next I
                    If Len(Names) > 0 Then
                        Sendmsg Whisper, Username, "Found phrase(s): " & Mid(Names, 1, Len(Names) - 2)
                        Names = PhraseBans(I).Username & ", "
                    End If
                    If NamesC < 1 Then
                        Sendmsg Whisper, Username, "No phrases found."
                        Exit Sub
                    End If
                Case "on"
                    If InStr(UserAccess, "C") = 0 Then Exit Sub
                    If PhraseBansToggle = True Then
                        Sendmsg Whisper, Username, "Error: Phraseban is already enabled"
                    Else
                        PhraseBansToggle = True
                        Sendmsg Whisper, Username, "Phraseban enabled."
                    End If
                Case "off"
                    If InStr(UserAccess, "C") = 0 Then Exit Sub
                    If PhraseBansToggle = False Then
                        Sendmsg Whisper, Username, "Error: Phraseban is already disabled"
                    Else
                        PhraseBansToggle = False
                        Sendmsg Whisper, Username, "Phraseban disabled."
                    End If
                Case "status", "stats"
                If InStr(UserAccess, "I") = 0 And InStr(UserAccess, "C") = 0 Then Exit Sub
                    If PhraseBansToggle = False Then
                        Sendmsg Whisper, Username, "Phraseban is currently disabled."
                    Else
                        Sendmsg Whisper, Username, "Phraseban is currently enabled."
                    End If
                Case Else
                    Sendmsg Whisper, Username, "Error in argument(s)."
            End Select
        
        Case "ipban", "ipbanning"
            Splt() = Split(message, " ")
            Word = Splt(1)
            Select Case LCase(Word)
                Case "on"
                    If InStr(UserAccess, "C") = 0 Then Exit Sub
                    If IPBanning = True Then
                        Sendmsg Whisper, Username, "Error: IPBanning is already enabled"
                    Else
                        IPBanning = True
                        Sendmsg Whisper, Username, "IPBanning enabled."
                    End If
                Case "off"
                    If InStr(UserAccess, "C") = 0 Then Exit Sub
                    If IPBanning = False Then
                        Sendmsg Whisper, Username, "Error: IPBanning is already disabled"
                    Else
                        IPBanning = False
                        Sendmsg Whisper, Username, "IPBanning disabled."
                    End If
                Case "status", "stats"
                If InStr(UserAccess, "I") = 0 And InStr(UserAccess, "C") = 0 Then Exit Sub
                    If IPBanning = False Then
                        Sendmsg Whisper, Username, "IPBanning is currently disabled."
                    Else
                        Sendmsg Whisper, Username, "IPBanning is currently enabled."
                    End If
                Case Else
                    Sendmsg Whisper, Username, "Error in argument(s)."
            End Select
        Case "jfp", "joinfprotect", "joinfprotection", "jfprotect", "jfprotection", "jfloodprotect", "jfloodprotection", "joinfloodprotection"
            Splt() = Split(message, " ")
            Word = Splt(1)
            Select Case LCase(Word)
                Case "on"
                    If InStr(UserAccess, "C") = 0 Then Exit Sub
                    If JoinFloodProtection = True Then
                        Sendmsg Whisper, Username, "Error: Join flood protection is already enabled"
                    Else
                        JoinFloodProtection = True
                        Sendmsg Whisper, Username, "Join flood protection enabled."
                    End If
                Case "off"
                    If InStr(UserAccess, "C") = 0 Then Exit Sub
                    If JoinFloodProtection = False Then
                        Sendmsg Whisper, Username, "Error: Join flood protection is already disabled"
                    Else
                        JoinFloodProtection = False
                        Sendmsg Whisper, Username, "Join flood protection disabled."
                    End If
                Case "status", "stats"
                If InStr(UserAccess, "I") = 0 And InStr(UserAccess, "C") = 0 Then Exit Sub
                    If JoinFloodProtection = False Then
                        Sendmsg Whisper, Username, "Join flood protection is currently disabled."
                    Else
                        Sendmsg Whisper, Username, "Join flood protection is currently enabled."
                    End If
                Case Else
                    Sendmsg Whisper, Username, "Error in argument(s)."
            End Select
            
        Case "protect", "lockdown"
            Splt() = Split(message, " ")
            Word = Splt(1)
            Select Case LCase(Word)
                Case "on"
                    If InStr(UserAccess, "C") = 0 Then Exit Sub
                    If ParseChat.ChannelProtection = False And ParseChat.ChannelProtection2 = False Then
                        ParseChat.ChannelProtection = True
                        ParseChat.ChannelProtection2 = False
                        AutoDesignate
                        Sendmsg Whisper, Username, "Channel protection enabled."
                    ElseIf ParseChat.ChannelProtection2 = True Then
                        Sendmsg Whisper, Username, "Error: Heightened channel protection is already enabled"
                    ElseIf ParseChat.ChannelProtection = True Then
                        Sendmsg Whisper, Username, "Error: Channel protection is already enabled"
                    End If
                Case "mode"
                    If InStr(UserAccess, "C") = 0 Then Exit Sub
                    Select Case LCase(Splt(2))
                        Case "1"
                            If ParseChat.ChannelProtection = True Then
                                Sendmsg Whisper, Username, "Error: Channel protection is already enabled"
                            ElseIf ParseChat.ChannelProtection2 = True Then
                                ParseChat.ChannelProtection = True
                                ParseChat.ChannelProtection2 = False
                                AutoDesignate
                                Sendmsg Whisper, Username, "Channel protection changed to mode 1 (Normal)."
                            Else
                                ParseChat.ChannelProtection = True
                                ParseChat.ChannelProtection2 = False
                                AutoDesignate
                                Sendmsg Whisper, Username, "Channel protection enabled."
                            End If
                        Case "2"
                        If InStr(UserAccess, "C") = 0 Then Exit Sub
                            If ParseChat.ChannelProtection2 = True Then
                                Sendmsg Whisper, Username, "Error: Heightened Channel protection is already enabled"
                            ElseIf ParseChat.ChannelProtection = True Then
                                ParseChat.ChannelProtection = False
                                ParseChat.ChannelProtection2 = True
                                AutoDesignate
                                Sendmsg Whisper, Username, "Channel protection changed to mode 2 (Heightened)."
                            Else
                                ParseChat.ChannelProtection = False
                                ParseChat.ChannelProtection2 = True
                                AutoDesignate
                                Sendmsg Whisper, Username, "Heightened channel protection enabled."
                            End If
                        Case Else
                            Sendmsg Whisper, Username, "Error in argument(s)."
                            Exit Sub
                    End Select
                Case "status", "stats"
                    If InStr(UserAccess, "I") = 0 And InStr(UserAccess, "C") = 0 Then Exit Sub
                    If ParseChat.ChannelProtection = True Then
                        Sendmsg Whisper, Username, "Channel protection is currently enabled."
                    ElseIf ParseChat.ChannelProtection2 = True Then
                        Sendmsg Whisper, Username, "Heightened channel protection is currently enabled."
                    ElseIf ParseChat.ChannelProtection = False And ParseChat.ChannelProtection2 = False Then
                        Sendmsg Whisper, Username, "Channel protection is currently disabled."
                    End If
                Case "off"
                    If InStr(UserAccess, "C") = 0 Then Exit Sub
                    If ParseChat.ChannelProtection = True Then
                        ParseChat.ChannelProtection = False
                        Sendmsg Whisper, Username, "Channel protection is disabled."
                    ElseIf ParseChat.ChannelProtection2 = True Then
                        ParseChat.ChannelProtection2 = False
                        Sendmsg Whisper, Username, "Heightened channel protection disabled."
                    ElseIf ParseChat.ChannelProtection = False And ParseChat.ChannelProtection2 = False Then
                        Sendmsg Whisper, Username, "Error: Channel protection is already disabled"
                    End If
                Case Else
                    Sendmsg Whisper, Username, "Error in argument(s)."
                    Exit Sub
            End Select
            Case "reconnect", "recon", "rec", "rc"
            If Whisper = False Then LocalCommand = True
                If InStr(UserAccess, "M") = 0 Then Exit Sub
                ConnectionUptime = 0
                PacketsReceived = 0
                BytesReceived = 0
                BytesSent = 0
                PacketsSent = 0
                ChannelUptime = 0
                Connected = False
                If BNLSLogin = True Then
                    On Error Resume Next
                    MDIForm1.winsock.Close
                    MDIForm1.BNLSSock.Close
                    MDIForm1.BNLSSock.Connect "BNLS.valhallalegends.com", 9367
                Else
                    On Error Resume Next
                    MDIForm1.winsock.Close
                    MDIForm1.winsock.Connect VarServer, VarPort
                End If
            Case "server"
                If InStr(UserAccess, "I") = 0 Then Exit Sub
                Sendmsg Whisper, Username, "Server currently connected to: " & MDIForm1.winsock.RemoteHostIP & ":" & MDIForm1.winsock.RemotePort
            
            Case "shutdown", "end", "close", "quit", "terminate", "exit"
                If InStr(UserAccess, "M") = 0 Then Exit Sub
                MDIForm1.winsock.Close
                End
            Case "bancount"
                If InStr(UserAccess, "I") = 0 And InStr(UserAccess, "O") = 0 Then Exit Sub
                Count = 0
                For I = 0 To UBound(userlist)
                    If userlist(I).Bancount > 0 Then Count = Count + userlist(I).Bancount
                Next I
                Sendmsg Whisper, Username, "This channel has banned a total of " & Count & " users (I have banned " & userlist(GetlistIndex(MyName)).Bancount & " of those users)."
            Case "kickcount"
                If InStr(UserAccess, "I") = 0 And InStr(UserAccess, "O") = 0 Then Exit Sub
                Count = 0
                For I = 0 To UBound(userlist)
                    If userlist(I).Kickcount > 0 Then Count = Count + userlist(I).Kickcount
                Next I
                Sendmsg Whisper, Username, "This channel has kicked a total of " & Count & " users (I have kicked " & userlist(GetlistIndex(MyName)).Kickcount & " of those users)."
        Case Else
            Exit Sub
    End Select
End Sub
Private Function ConvertBan(strText As String) As String
strText = Replace(LCase(strText), Chr(34), "")
strText = Replace(LCase(strText), ",", "")
strText = Replace(LCase(strText), "@uswest", "")
strText = Replace(LCase(strText), "@useast", "")
strText = Replace(LCase(strText), "@usasia", "")
strText = Replace(LCase(strText), "@europe", "")
ConvertBan = strText
End Function
Public Function Sendmsg(Whisper As Boolean, Username As String, message As String)
If Whisper Then
    Send1 "/w " & Username & " " & message
Else
    AddC True, Form1.TALK, vbRed, "Bot: " & message
    LocalCommand = True
    Exit Function
End If
End Function

