Valhalla Legends Forums Archive | Battle.net Bot Development | [VB] Chanel Class

AuthorMessageTime
JoeTheOdd
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

[code]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
'https://davnit.net/bnet/vL/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
[/code]
November 20, 2005, 5:44 AM
Ringo
[quote author=Joe link=topic=13295.msg134757#msg134757 date=1132465445]
[code]
'Modified from Dragon's code
'https://davnit.net/bnet/vL/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
[/code]
[/quote]
Would it not be better do modify the icon like this?
(Just a quick browseing suggestion)
[code]
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
[/code]
November 20, 2005, 8:33 AM
FrOzeN
I wrote this code to remove a user about 15 months ago, I find it more efficient. :)
[code]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[/code]
November 20, 2005, 8:53 AM
JoeTheOdd
Yeah, probably would be Ringo.
November 20, 2005, 2:09 PM

Search