VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "clsPlugin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True


Option Base 0
Option Explicit
Option Compare Text
Private BotIndex As Integer
Private MainForm As Object
Private hTimer As Long

Private Sub Class_Terminate()
    Set Bot = Nothing
    Set MainForm = Nothing
End Sub

Public Sub RunPlugin(ByVal frmMain As Object, ByRef Info() As String)
    Set MainForm = frmMain
    ReDim Info(8)
    Info(0) = "Author: l2k-Shadow"
    Info(1) = "Plugin: Trivia v1.01"
    Info(2) = "Trivia Bot for l2uthless Chat"
    Info(3) = "Trivia files go into folder " & App.Path & "\Trivia\ and they are loaded using /trivia file (you have to download your own files)"
    Info(4) = "Trivia files are to have the question and answer seperated by the | character (like station 55)"
    Info(5) = "You can find some trivia files for download here: http://www.bnetaddict.com/shadow/trivia/"
    Info(6) = "Ex: /trivia starcraft.dat"
    Info(7) = "Use /trivia off to stop trivia"
    Info(8) = "OK, I received reports of trivia dropping when ran for a good amount of time. In this version, I shortened the answer recognition message, as well as made the timer 10 seconds before next message is sent. Let's see if it helps it out."
End Sub

Public Sub AddToUserMenu(ByRef ChildMenus() As String)
'
End Sub

Public Sub AddToPluginsMenu(ByRef ChildMenus() As String)
'
End Sub

Public Sub ProfileSwitch(ByVal objBot As Object, ByVal Index As Integer)
    Set Bot = objBot
    BotIndex = Index
    MainForm.DontSwitchProfiles App.EXEName, True
End Sub

Public Sub MenuClicked(ByVal MenuName As String, Optional ByVal UserClicked As String)
'
End Sub

Public Function MessageSend(ByVal Index As Integer, ByVal Message As String, Optional ByRef ReturnMessage As String) As Boolean
'Public Function MessageSend(ByVal Message As String) As Boolean
Dim splt() As String, i As Long, FF As Integer, b As String
    If BotIndex <> Index Then Exit Function
    splt = Split(Message, Space(1))
    If UBound(splt) > 0 Then
        If LCase$(splt(0)) = "/trivia" Then
            Select Case LCase$(splt(1))
                Case "off"
                    Erase modTrivia.Trivia
                    TimerI = 0
                    sAnswer = vbNullString
                    KillTimer MainForm.hWnd, hTimer
                    Bot.AddChat vbRed, "Trivia has been disabled!"
                Case Else
                    If Dir(App.Path & "\Trivia\" & splt(1)) <> vbNullString Then
                        If FileLen(App.Path & "\Trivia\" & splt(1)) > 0 Then
                            FF = FreeFile
                            Erase modTrivia.Trivia
                            Open App.Path & "\Trivia\" & splt(1) For Input As #FF
                                Do Until EOF(FF)
                                Line Input #FF, b
                                    If b <> vbNullString Then
                                        ReDim Preserve modTrivia.Trivia(i)
                                        modTrivia.Trivia(i) = b
                                        i = i + 1
                                    End If
                                Loop
                            Close #FF
                            Bot.AddChat vbGreen, "Trivia file " & splt(1) & " has been loaded!"
                            hTimer = SetTimer(MainForm.hWnd, 8000)
                        Else
                            Bot.AddChat vbRed, "Trivia file " & splt(1) & " is empty!"
                        End If
                    Else
                        Bot.AddChat vbRed, "Trivia file " & splt(1) & " does not exist!"
                    End If
            End Select
            MessageSend = True
        End If
    End If
End Function

Public Sub MessageReceive(ByVal Index As Integer, ByVal EventID As Long, Optional ByVal Username As String, Optional ByVal Message As String, Optional ByVal Ping As Long, Optional ByVal Flags As Long, Optional ByVal Statstring As String)
' This event will be called when something happens on battle.net
' Possible EventIDs are the same as Battle.net's 0x0F IDs
' 0x01 - Users that are in channel when you enter
' 0x02 - When user joins the channel
' 0x03 - When user leaves the channel
' 0x04 - When user whispers you
' 0x05 - When user talks
' 0x07 - When you enter a channel
' 0x09 - When flags are updated for a user
' 0x0A - When you whisper someone
' 0x12 - Information from Battle.net server
' 0x13 - Error from Battle.net server
' 0x17 - When user does /emote
' 0x18 - When user talks with encrypted message (this ID is unique to l2uthless Chat)
Dim Rank As Long, Score As Long
    If BotIndex <> Index Then Exit Sub
    If EventID = &H5 Then
        If LCase$(Message) = LCase$(sAnswer) Then
            AddScore Username
            GetScore Username, Score, Rank
            Bot.Send "Congratulations " & Username & "! Answer: " & sAnswer & ". Score: " & Score & " Rank: " & Rank
            TimerI = 0
            sAnswer = vbNullString
            KillTimer MainForm.hWnd, hTimer
            hTimer = SetTimer(MainForm.hWnd, 10000)
        End If
    End If
End Sub

