Attribute VB_Name = "modAlerts"
Option Explicit

'u, jlsw, clan=WaR name=username rank=Master, y, y
't, esw, Value = Message, y, y
'f, cdg, name=friend, y, y
'c, cdr, name=member rank=shaman, y, y
'b, f, mode=l|m|h, y, y

Private U() As objAlert

Public Sub AlertUser(Index As Integer, CE As objEvent, US As objUser)
On Error GoTo hErr
    Dim I As Integer
1   For I = 0 To UBound(U)
2       With U(I)
3           Dim ev As String, isev As Boolean
4           ev = LCase$(.EventType)
5           isev = (InStrB(ev, "j") And CE.EID = EID_JOIN) Or _
                   (InStrB(ev, "l") And CE.EID = EID_LEAVE) Or _
                   (InStrB(ev, "f") And CE.EID = EID_USERFLAGS) Or _
                   (InStrB(ev, "s") And CE.EID = EID_TALK) Or _
                   (InStrB(ev, "e") And CE.EID = EID_EMOTE) Or _
                   (InStrB(ev, "w") And CE.EID = EID_WHISPER)
  
12          If isev Then
13              Dim isnm As Boolean, ismg As Boolean, isra As Boolean, isct As Boolean, isrn As Boolean
14              If LenB(.Name) = 0 Then
15                  isnm = True
16              Else
17                  If InStrB(.Name, "*") Then
18                      isnm = Matches(US.Account, .Name)
19                  Else
20                      isnm = (LCase$(US.Account) = .Name)
21                  End If
22              End If
23
24              If LenB(.ClanRank) = 0 Then
25                  isra = True
26              Else
27                  Dim C As objMember
28                  Set C = frmBot.Bot(Index).Clan.GetByName(US.Account)
29                  If LCase$(ClanRankToString(C.Rank)) = LCase$(.ClanRank) Then isra = True
30                  Set C = Nothing
31              End If
32
33              If LenB(.Clan) = 0 Then
34                  isct = True
35              Else
36                  If LCase$(ExtractClanName(US.Statstring)) = LCase$(.Clan) Then isct = True
37              End If
38
39              If LenB(.Rank) = 0 Then
40                  isrn = True
41              Else
42                  Dim D As objDbUser
43                  Set D = frmBot.Bot(Index).Database.GetUser(US.Account)
44                  If LCase$(GetRankByID(D.RankID).RankName) = LCase$(.Rank) Then isrn = True
45                  Set D = Nothing
46              End If
47
48              'Check if all are valid
49              If isnm And isrn And isct And isra Then
                    Select Case CE.EID
                    Case EID_JOIN
52                      ShowAlert "[" & frmBot.Bot(Index).Profile & "] " & frmBot.Bot(Index).Self.Username & "@" & frmBot.Bot(Index).Config.ServerName, US.Account & " joined the channel!", .Sound, .Flash
                    Case EID_LEAVE
54                      ShowAlert "[" & frmBot.Bot(Index).Profile & "] " & frmBot.Bot(Index).Self.Username & "@" & frmBot.Bot(Index).Config.ServerName, US.Account & " left the channel!", .Sound, .Flash
                    Case EID_USERFLAGS
56                      ShowAlert "[" & frmBot.Bot(Index).Profile & "] " & frmBot.Bot(Index).Self.Username & "@" & frmBot.Bot(Index).Config.ServerName, US.Account & " flags changed to " & ByteToHex(CByte(US.Flags)) & "!", .Sound, .Flash
                    Case EID_EMOTE
58                      If LenB(.Message) = 0 Then
59                          ismg = True
60                      Else
61                          If InStrB(.Message, "*") Then
62                              ismg = Matches(CE.Message, .Message)
63                          Else
64                              ismg = (LCase$(CE.Message) = .Message)
65                          End If
66                      End If
67                      If ismg Then ShowAlert "[" & frmBot.Bot(Index).Profile & "] " & frmBot.Bot(Index).Self.Username & "@" & frmBot.Bot(Index).Config.ServerName, US.Account & " emoted: " & vbCrLf & CE.Message, .Sound, .Flash
                    Case EID_TALK
69                      If LenB(.Message) = 0 Then
70                          ismg = True
71                      Else
72                          If InStrB(.Message, "*") Then
73                              ismg = Matches(CE.Message, .Message)
74                          Else
75                              ismg = (LCase$(CE.Message) = .Message)
76                          End If
77                      End If
78                      If ismg Then ShowAlert "[" & frmBot.Bot(Index).Profile & "] " & frmBot.Bot(Index).Self.Username & "@" & frmBot.Bot(Index).Config.ServerName, US.Account & " spoke: " & vbCrLf & CE.Message, .Sound, .Flash
                    Case EID_WHISPER
80                      If LenB(.Message) = 0 Then
81                          ismg = True
82                      Else
83                          If InStrB(.Message, "*") Then
84                              ismg = Matches(CE.Message, .Message)
85                          Else
86                              ismg = (LCase$(CE.Message) = .Message)
87                          End If
88                      End If
89                      If ismg Then ShowAlert "[" & frmBot.Bot(Index).Profile & "] " & frmBot.Bot(Index).Self.Username & "@" & frmBot.Bot(Index).Config.ServerName, US.Account & " whispered: " & vbCrLf & CE.Message, .Sound, .Flash
90                  End Select
91              End If
92          End If
93      End With
94  Next
    Exit Sub
hErr:
    ErrorHandler Err.Number, Err.Description, Erl, "Alerts", "AlertTalk"
End Sub

Public Sub ShowAlert(Title As String, Text As String, Sound As Boolean, Flash As Boolean)
    If options.AlertMin Then If frmBot.WindowState = vbNormal Or frmBot.WindowState = vbMaximized Then Exit Sub
    If Sound Then PlaySound App.Path & "\notify.wav"
    If Flash Then FlashWindow
    frmBot.tiMain.BalloonTip Text, btsInfo, Title, 15000
End Sub

Public Sub ShowExclamation(Title As String, Text As String, Optional Sound As Boolean = True)
    If Sound Then PlaySound App.Path & "\notify.wav"
    frmBot.tiMain.BalloonTip Text, btsWarning, Title, 15000
End Sub

Public Sub LoadAlerts()
On Error GoTo hErr
1   ReDim U(0)
    Set U(0) = New objAlert
2   Dim FS As New FileSystemObject, TS As TextStream
    Set TS = FS.OpenTextFile(AppData & "Data\Other\Alerts.ini", ForReading, True)
    Do Until TS.AtEndOfStream
5       Dim LN As String
6       LN = TS.ReadLine
7       If LenB(LN) Then
8           If InStrB(LN, ",") Then
9               Dim S() As String, A As New objAlert
10              S = Split(LN, ",")
11              Debug.Print "Line: " & LN
12              If UBound(S) = 2 Then
                    Set A = New objAlert
14                  A.EventType = Trim$(LCase$(S(0)))
16                  A.Sound = Trim$(LCase$(Left$(S(2), 1))) = "y"
17                  A.Flash = Trim$(LCase$(Right$(S(2), 1))) = "y"
19                      If InStrB(LCase$(S(1)), "name=") Then
20                          A.Name = LCase$(Mid$(S(1), InStr(S(1), "name=") + 5))
21                          A.Name = Split(A.Name, " ")(0)
22                      End If
23                      If InStrB(LCase$(S(1)), "message=") Then
24                          A.Message = LCase$(Mid$(S(1), InStr(S(1), "message=") + 8))
25                          A.Message = Split(A.Message, " ")(0)
26                      End If
27                      If InStrB(LCase$(S(1)), "rank=") Then
28                          A.Rank = LCase$(Mid$(S(1), InStr(S(1), "rank=") + 5))
29                          A.Rank = Split(A.Rank, " ")(0)
30                      End If
31                      If InStrB(LCase$(S(1)), "clan=") Then
32                          A.Clan = LCase$(Mid$(S(1), InStr(S(1), "clan=") + 5))
33                          A.Clan = Split(A.Clan, " ")(0)
34                      End If
35                      If InStrB(LCase$(S(1)), "clanrank=") Then
36                          A.ClanRank = LCase$(Mid$(S(1), InStr(S(1), "clanrank=") + 9))
37                          A.ClanRank = Split(A.ClanRank, " ")(0)
38                      End If
39                      If Len(U(0).EventType) <> 0 Then ReDim Preserve U(UBound(U) + 1)
40                      Set U(UBound(U)) = A
                End If
            End If
        End If
121 Loop
    Exit Sub
hErr:
    ErrorHandler Err.Number, Err.Description, Erl, "Alerts", "LoadAlerts"
End Sub
