Blacklist

Leandro Silva [09-24-18 - 17:46]
Blacklist
Filename
LeoGuildManager.lua
LeoGuildManager.txt
LeoGuildManager.xml
LeoGuildManagerUI.lua
diff --git a/LeoGuildManager.lua b/LeoGuildManager.lua
index fd58026..e1aec01 100644
--- a/LeoGuildManager.lua
+++ b/LeoGuildManager.lua
@@ -2,7 +2,7 @@
 LeoGM = {}
 LeoGM.name = "LeoGuildManager"
 LeoGM.displayName = "Leo's Guild Manager"
-LeoGM.version = "0.9.7"
+LeoGM.version = "0.9.8"
 LeoGM.chatPrefix = "|c39B027" .. LeoGM.name .. "|r: "
 LeoGM.panelList = { "Rules", "Purge" }
 LeoGM.members = {}
@@ -44,6 +44,9 @@ function LeoGM.GetGuildMembers(guildId)
     local numGuildMembers = GetNumGuildMembers(guildId)
     for guildMemberIndex = 1, numGuildMembers do
         local displayName, note, rankIndex, status, secsSinceLogoff = GetGuildMemberInfo(guildId, guildMemberIndex)
+        if status ~= PLAYER_STATUS_OFFLINE then
+            secsSinceLogoff = 0
+        end
         local rankId = GetGuildRankId(guildId, rankIndex)
         local rankName = GetGuildRankCustomName(guildId, rankIndex)
         table.insert(LeoGM.members, {
@@ -51,7 +54,7 @@ function LeoGM.GetGuildMembers(guildId)
             rankIndex = rankIndex,
             rankId = rankId,
             rankName = rankName,
-            online = secsSinceLogoff,
+            secsSinceLogoff = secsSinceLogoff,
             deposits = 0,
             taxes = 0,
             sales = 0
@@ -230,16 +233,16 @@ function LeoGM.BuildDepositsHistory(guildId, scanSince)
     LeoGMWindowPurgePanelLoadingIcon:SetHidden(false)
     LeoGMWindowPurgePanelLoadingIcon.animation:PlayForward()

-    if #LeoGM.depositsEvents == 0 then
-        LeoGM.requestTimestamp = GetTimeStamp()
-        RequestGuildHistoryCategoryNewest(guildId, GUILD_HISTORY_BANK)
-        zo_callLater(function() LeoGM.ScanOlderDeposits(guildId, scanSince) end, 2000)
-    else
+    --if #LeoGM.depositsEvents == 0 then
+    LeoGM.requestTimestamp = GetTimeStamp()
+    RequestGuildHistoryCategoryNewest(guildId, GUILD_HISTORY_BANK)
+    zo_callLater(function() LeoGM.ScanOlderDeposits(guildId, scanSince) end, 2000)
+    --[[else
         LeoGM:PostScan()
         LeoGMWindowPurgePanelListButton:SetEnabled(true)
         LeoGMWindowPurgePanelLoadingIcon:SetHidden(true)
         LeoGMWindowPurgePanelLoadingIcon.animation:Stop()
-    end
+    end]]
 end

 function LeoGM.ProcessDeposits(guildNum, lastSaleTime, startIndex, endIndex, loopIncrement)
@@ -424,6 +427,27 @@ function LeoGM.Initialize()
     end
 end

+function LeoGM:OnUpdate()
+
+    for _, guildName in pairs(LeoGM.guilds) do
+        local guildId = LeoGM.GetGuilds(guildName)
+        if DoesPlayerHaveGuildPermission(guildId, GUILD_PERMISSION_REMOVE) and LeoGM.savedVariables.rules[guildName].blacklist ~= nil then
+            for _, userId in pairs(LeoGM.savedVariables.rules[guildName].blacklist) do
+                local numGuildMembers = GetNumGuildMembers(guildId)
+                for guildMemberIndex = 1, numGuildMembers do
+                    local displayName = GetGuildMemberInfo(guildId, guildMemberIndex)
+                    if string.lower(displayName) == string.lower(userId) then
+                        d("Found " .. userId .." on " .. guildName)
+                        --d("Found " .. userId .." on " .. guildName .. ". Kicking ...")
+                        --GuildRemove(guildId, userId)
+                        break
+                    end
+                end
+            end
+        end
+    end
+end
+
 function LeoGM.OnAddOnLoaded(event, addonName)
     if addonName == LeoGM.name then
         EVENT_MANAGER:UnregisterForEvent(LeoGM.Name, EVENT_ADD_ON_LOADED)
@@ -433,3 +457,4 @@ function LeoGM.OnAddOnLoaded(event, addonName)
 end

 EVENT_MANAGER:RegisterForEvent(LeoGM.name, EVENT_ADD_ON_LOADED, LeoGM.OnAddOnLoaded)
+EVENT_MANAGER:RegisterForUpdate(LeoGM.name, 60000, function() LeoGM.OnUpdate() end)
diff --git a/LeoGuildManager.txt b/LeoGuildManager.txt
index 05cc3ff..9206703 100644
--- a/LeoGuildManager.txt
+++ b/LeoGuildManager.txt
@@ -1,6 +1,6 @@
 ## Title: Leo's Guild Manager
 ## APIVersion: 100024
-## Version: 0.9.7
+## Version: 0.9.8
 ## Author: |c39B027@LeandroSilva|r
 ## SavedVariables: LeoGMSavedVariables
 ## DependsOn: LibStub LibFeedback MasterMerchant
diff --git a/LeoGuildManager.xml b/LeoGuildManager.xml
index edda413..efb7a64 100644
--- a/LeoGuildManager.xml
+++ b/LeoGuildManager.xml
@@ -201,6 +201,35 @@
                             <Anchor point="TOPLEFT" relativeTo="$(parent)" relativePoint="TOPLEFT" offsetX="20" offsetY="160" />
                         </Label>

+                        <Texture name="$(parent)Divider" textureFile="EsoUI/Art/Miscellaneous/centerscreen_topDivider.dds">
+                            <Dimensions x="900" y="5" />
+                            <Anchor point="TOP" relativeTo="$(parent)" relativePoint="TOP" offsetX="0" offsetY="220" />
+                        </Texture>
+
+
+                        <Label name="$(parent)BlacklistLabel" text="Blacklist" font="ZoFontWinH2" wrapMode="ELLIPSIS"
+                               color="E8DFAF" verticalAlignment="CENTER" horizontalAlignment="CENTER" mouseEnabled="false">
+                            <Dimensions x="900" y="35"/>
+                            <Anchor point="TOPLEFT" relativeTo="$(parent)" relativePoint="TOPLEFT" offsetX="20" offsetY="240" />
+                        </Label>
+                        <Label name="$(parent)BlacklistDesc" text="UserIDs that will be kicked |cFF2222automatically|r: " font="ZoFontGame" wrapMode="ELLIPSIS"
+                               color="FFFFFF" verticalAlignment="TOP" horizontalAlignment="LEFT" mouseEnabled="false">
+                            <Dimensions x="320" y="35"/>
+                            <Anchor point="TOPLEFT" relativeTo="$(parent)BlacklistLabel" relativePoint="TOPLEFT" offsetX="0" offsetY="40" />
+                        </Label>
+                        <Label name="$(parent)BlacklistList" text="" font="ZoFontGame" wrapMode="ELLIPSIS"
+                               color="FFFFFF" verticalAlignment="TOP" horizontalAlignment="LEFT" mouseEnabled="false">
+                            <Dimensions x="500" y="90"/>
+                            <Anchor point="TOPLEFT" relativeTo="$(parent)BlacklistDesc" relativePoint="TOPRIGHT" offsetX="0" offsetY="0" />
+                        </Label>
+                        <Button name="$(parent)Save" inherits="ZO_DefaultButton" font="ZoFontWinH4" text="Change">
+                            <Dimensions x="200" y="30" />
+                            <Anchor point="TOPLEFT" relativeTo="$(parent)BlacklistDesc" relativePoint="BOTTOMLEFT" offsetX="2" offsetY="16"/>
+                            <OnClicked>
+                                LeoGMWindow.OnBlackListClick()
+                            </OnClicked>
+                        </Button>
+
                     </Controls>
                 </Backdrop>

diff --git a/LeoGuildManagerUI.lua b/LeoGuildManagerUI.lua
index d316056..8123968 100644
--- a/LeoGuildManagerUI.lua
+++ b/LeoGuildManagerUI.lua
@@ -64,7 +64,7 @@ function LeoGMMemberList:SetupEntry(control, data)
     control.sales:SetText(LeoGM.formatNumber(data.sales))

     control.online = GetControl(control, "Online")
-    control.online:SetText(LeoGM.GetTime(data.online))
+    control.online:SetText(LeoGM.GetTime(data.secsSinceLogoff))

     local guildId = LeoGM.GetGuilds(LeoGM.savedVariables.selectedGuild)
     local rankName = GetGuildRankCustomName(guildId, data.rankIndex)
@@ -112,9 +112,12 @@ function LeoGMMemberList:FilterScrollList()
         elseif ticketsThreshold > 0 and data.deposits >= ticketsThreshold then
             canAdd = false
         end
-        if not canAdd and offlineThreshold > 0 and data.online > offlineThreshold then
+        if not canAdd and offlineThreshold > 0 and data.secsSinceLogoff > offlineThreshold then
             canAdd = true
         end
+        if canAdd and offlineThreshold > 0 and data.secsSinceLogoff <= offlineThreshold then
+            canAdd = false
+        end
         if canAdd and LeoGM.selectedRank and data.rankIndex <= LeoGM.selectedRank then
             canAdd = false
         end
@@ -279,6 +282,16 @@ function LeoGM.ListPurge()
     LeoGM.BuildDepositsHistory(guildId, scanSince)
 end

+function LeoGMWindow.OnBlacklistChanged(displayName, text)
+    LeoGM.savedVariables.rules[LeoGM.savedVariables.selectedGuild].blacklist = {}
+    for line in string.gmatch( text, "[^\r\n]+" ) do
+        if line ~= nil and line:len() > 1 then
+            table.insert(LeoGM.savedVariables.rules[LeoGM.savedVariables.selectedGuild].blacklist, line)
+        end
+    end
+    LeoGMWindowRulesPanelBlacklistList:SetText(table.concat(LeoGM.savedVariables.rules[LeoGM.savedVariables.selectedGuild].blacklist, ", "))
+end
+
 function LeoGM.InitializeUI()
     LeoGMWindowTitle:SetText(LeoGM.displayName .. " v" .. LeoGM.version)

@@ -297,6 +310,7 @@ function LeoGM.InitializeUI()
             LeoGMWindowRulesPanelTicketsSlider:SetValue(LeoGM.savedVariables.rules[LeoGM.savedVariables.selectedGuild].tickets)
             LeoGMWindowRulesPanelSalesSlider:SetValue(LeoGM.savedVariables.rules[LeoGM.savedVariables.selectedGuild].sales)
             LeoGMWindowRulesPanelOfflineSlider:SetValue(LeoGM.savedVariables.rules[LeoGM.savedVariables.selectedGuild].offline)
+            LeoGMWindowRulesPanelBlacklistList:SetText(table.concat(LeoGM.savedVariables.rules[LeoGM.savedVariables.selectedGuild].blacklist, ", "))

             local guildId = LeoGM.GetGuilds(guildName)
             local rankDropdown = ZO_ComboBox_ObjectFromContainer(LeoGMWindowRankDropdown)
@@ -323,8 +337,11 @@ function LeoGM.InitializeUI()
             LeoGM.savedVariables.rules[guildName] = {
                 tickets = 0,
                 sales = 0,
-                offline = 0
+                offline = 0,
+                blacklist = {}
             }
+        elseif not LeoGM.savedVariables.rules[guildName].blacklist then
+            LeoGM.savedVariables.rules[guildName].blacklist = {}
         end
         if not LeoGM.savedVariables.selectedGuild then
             LeoGM.savedVariables.selectedGuild = guildName
@@ -348,6 +365,7 @@ function LeoGM.InitializeUI()
         LeoGMWindowRulesPanelTicketsSlider:SetValue(LeoGM.savedVariables.rules[LeoGM.savedVariables.selectedGuild].tickets)
         LeoGMWindowRulesPanelSalesSlider:SetValue(LeoGM.savedVariables.rules[LeoGM.savedVariables.selectedGuild].sales)
         LeoGMWindowRulesPanelOfflineSlider:SetValue(LeoGM.savedVariables.rules[LeoGM.savedVariables.selectedGuild].offline)
+        LeoGMWindowRulesPanelBlacklistList:SetText(table.concat(LeoGM.savedVariables.rules[LeoGM.savedVariables.selectedGuild].blacklist, ", "))
     end

     LeoGM.memberScroll = LeoGMMemberList:New(LeoGMWindowPurgePanelMemberScroll) -- check
@@ -355,6 +373,14 @@ function LeoGM.InitializeUI()
     LeoGMWindowPurgePanelLoadingIcon.animation = ANIMATION_MANAGER:CreateTimelineFromVirtual('LoadIconAnimation', LeoGMWindowPurgePanelLoadingIcon)
 end

+function LeoGMWindow.OnBlackListClick()
+    ClearMenu()
+    ZO_Dialogs_ShowDialog("EDIT_NOTE", {
+        displayName = "One UserID per line",
+        note = table.concat(LeoGM.savedVariables.rules[LeoGM.savedVariables.selectedGuild].blacklist, "\n"),
+        changedCallback = LeoGMWindow.OnBlacklistChanged
+    })
+end
 function LeoGM.GetTime(seconds)
     if seconds and seconds > 0 then
         local ss = seconds % 60