• Welcome to Valhalla Legends Archive.
 

[VB] Chanel Class

Started by Joe[x86], November 19, 2005, 11:44 PM

Previous topic - Next topic

Joe[x86]

If you've ever written a bot, you know that channel-list operations are not the most fun/easy part. I wrote this class for JBBE to handle this for me. You can add a user (UserInChannel, UserJoins), modify as user (Stats Update), remove a user (UserLeaves), or totally clear the list (joined a new channel/logged off).

Thanks to |)ragon for his modify-user code, which I totally murdered. =p

Option Explicit

Private m_lvChannel As ListView

Public Usercount As Byte
Public ChannelName As String

Public Property Let lvChannel(p As ListView)
    Set m_lvChannel = p
End Property

Public Property Get lvChannel() As ListView
    Set lvChannel = m_lvChannel
End Property

Public Function GetIcon(Flags As Long, Ping As Long, Statstring As String) As Integer
    If Flags And 32 Then GetIcon = ICN_SQUELCH: Exit Function
    If Flags And 1 Then GetIcon = ICN_BLIZZREP: Exit Function
    If Flags And 2 Then GetIcon = ICN_CHANOP: Exit Function
    If Flags And 4 Then GetIcon = ICN_SPEAKER: Exit Function
    If Flags And 8 Then GetIcon = ICN_ADMIN: Exit Function
    Select Case StrReverse(Left(Statstring, 4))
        Case "D2DV": GetIcon = ICN_D2DV
        Case "D2XP": GetIcon = ICN_D2XP
        Case "DRTL": GetIcon = ICN_DRTL
        Case "DSHR": GetIcon = ICN_DSHR
        Case "SEXP": GetIcon = ICN_SEXP
        Case "SSHR": GetIcon = ICN_SSHR
        Case "STAR": GetIcon = ICN_STAR
        Case "W2BN": GetIcon = ICN_W2BN
        Case "WAR3": GetIcon = ICN_WAR3
    End Select
End Function

Public Sub AddUser(Username As String, Flags As Long, Ping As Long, Statstring As String)
    Usercount = Usercount + 1
    Call m_lvChannel.ListItems.Add(, , Username, , GetIcon(Flags, Ping, Statstring))
End Sub

'Modified from Dragon's code
'http://forum.valhallalegends.com/index.php?topic=7743.0
Public Sub ModifyUser(Username As String, Flags As Long, Ping As Long, Statstring As String)
    Dim usrIndex As Integer
    usrIndex = m_lvChannel.FindItem(Username).Index
    m_lvChannel.ListItems.Remove usrIndex
    Call m_lvChannel.ListItems.Add(usrIndex, , Username, , GetIcon(Flags, Ping, Statstring))
End Sub

Public Sub RemoveUser(Username As String)
    On Error Resume Next
    Usercount = Usercount - 1
    Call m_lvChannel.ListItems.Remove(CheckChannel(Username))
End Sub

Public Sub Clear()
    Usercount = 0
    m_lvChannel.ListItems.Clear
End Sub

Public Function CheckChannel(NameToFind As String) As Integer
    Dim itmFound As ListItem
    Set itmFound = m_lvChannel.FindItem(NameToFind)
    CheckChannel = IIf(itmFound Is Nothing, 0, itmFound.Index)
End Function
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

Ringo

Quote from: Joe on November 19, 2005, 11:44 PM

'Modified from Dragon's code
'http://forum.valhallalegends.com/index.php?topic=7743.0
Public Sub ModifyUser(Username As String, Flags As Long, Ping As Long, Statstring As String)
    Dim usrIndex As Integer
    usrIndex = m_lvChannel.FindItem(Username).Index
    m_lvChannel.ListItems.Remove usrIndex
    Call m_lvChannel.ListItems.Add(usrIndex, , Username, , GetIcon(Flags, Ping, Statstring))
End Sub

Would it not be better do modify the icon like this?
(Just a quick browseing suggestion)

Public Sub ModifyUser(Username As String, Flags As Long, Ping As Long, Statstring As String)
    On Error Resume Next
    m_lvChannel.FindItem(Username).SmallIcon = GetIcon(Flags, Ping, Statstring))
End Sub


FrOzeN

I wrote this code to remove a user about 15 months ago, I find it more efficient. :)
Username = Replace(Username, "*", vbNullString)
Dim ToFind As ListItem
  With lvChannel
    Set ToFind = .FindItem(Username)
    If Not (ToFind Is Nothing) Then
      .ListItems.Remove ToFind.Index
      Set ToFind = Nothing
    End If
  End With
~ FrOzeN

Joe[x86]

Yeah, probably would be Ringo.
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.