VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsShareQueue"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Public Queue As Collection
Public QRunning As Boolean
Public QV As objQItem

Public Sub InitQueue()
    Set Queue = New Collection
End Sub

Public Function QCount(Optional Index As Integer = -1) As Integer
On Error Resume Next
    If Index = -1 Then
        QCount = Queue.Count
    Else
        Dim I As Integer, QI As objQItem, x As Integer
        For I = Queue.Count To 1 Step -1
            Set QI = Queue(I)
            If QI.Index = Index Then
                x = x + 1
            End If
        Next
        QCount = x
    End If
End Function

Public Sub QClear(Optional Index As Integer = -1)
On Error Resume Next
    If Index = -1 Then
        Set Queue = New Collection
    Else
        Dim I As Integer, QI As objQItem
        For I = Queue.Count To 1 Step -1
            Set QI = Queue(I)
            If QI.Index = Index Then
                Queue.Remove I
            End If
        Next
    End If
End Sub

Public Sub QAdd(Text As String, Share As Boolean, Index As Integer)
On Error GoTo hErr:
1   Dim High As Boolean
2   Set QV = New objQItem
3   QV.Text = Text
4   QV.Share = Share
5   QV.Index = Index
6   If Share Then
7       'High Priority (ban,kick,unban)
8       High = True
9   Else
10      'Determine High Priority Command
11      If InStrB(Text, " ") And Left$(Text, 1) = "/" Then
12          Dim Comm As String
13          Comm = LCase$(Split(Text, " ")(0))
            Select Case Comm
            Case "sweep", "ipsweep", "ignore", "unignore", "squelch", "unsquelch"
16              High = True
            End Select
18      End If
19  End If
20  If Queue.Count > 0 And High Then
21      Queue.Add QV, , 1
22  Else
23      Queue.Add QV
24  End If
25  QCleanup
    Exit Sub
hErr:
    ErrorHandler Err.Number, Err.Description, Erl, "ShareQ", "QAdd"
End Sub

Public Sub QDelete(Text As String, Index As Integer)
On Error Resume Next
    Dim QI As objQItem, I As Integer
    For I = Queue.Count To 1 Step -1
        Set QI = Queue(I)
        If LCase$(QI.Text) = LCase$(Text) And QI.Index = Index Then
            Queue.Remove I
        End If
    Next
End Sub

Public Sub QCleanup()
On Error GoTo hErr:
Top:
1   Dim Removed As Boolean
2   Removed = False
3   Dim QI As objQItem, I As Integer
4   For I = Queue.Count To 1 Step -1
5       Set QI = Queue(I)
6       'Check if Shared Item
7       If QI.Share Then
8           'Check if Command has Arguments
9           If InStr(QI.Text, " ") Then
10              'Seperate Command
11              Dim CommandI As String, UserI As String
12              CommandI = Split(QI.Text, " ")(0)
13              UserI = Split(QI.Text, " ")(1)
14              'Search for Command Matches
15              Dim QJ As objQItem, J As Integer
16              For J = Queue.Count To 1 Step -1
17                  'Check to make sure it is a different item
18                  If J <> I Then
19                      Set QJ = Queue(J)
20                      'Check if Shared Item
21                      If QJ.Share Then
22                          'Check if Command has Arguments
23                          If InStr(QJ.Text, " ") Then
24                              Dim CommandJ As String, UserJ As String
25                              CommandJ = Split(QJ.Text, " ")(0)
26                              UserJ = Split(QJ.Text, " ")(1)
27                              'Check if Same Command
28                              If LCase$(CommandJ) = LCase$(CommandI) Then
29                                  'Check if Same User
30                                  If LCase$(Suffix(UserJ)) = LCase$(Suffix(UserI)) Then
31                                      'Check if Same Server
32                                      If frmBot.Bot(QJ.Index).Config.ServerNameEx = frmBot.Bot(QI.Index).Config.ServerNameEx Then
33                                          'Check if Same Channel
34                                          If frmBot.Bot(QJ.Index).Self.Channel = frmBot.Bot(QI.Index).Self.Channel Then
35                                              'Remove Duplicate Item
36                                              Queue.Remove J
37                                              Removed = True
38                                          End If
39                                      End If
40                                  End If
41                              End If
42                          End If
43                      End If
44                  End If
45              Next J
46              'Item was found and removed
47              If Removed Then GoTo Top:
48          End If
49      End If
50  Next I
    Exit Sub
hErr:
    ErrorHandler Err.Number, Err.Description, Erl, "ShareQ", "QCleanup"
End Sub
