more async invite goodies

git [04-11-18 - 06:28]
more async invite goodies
Filename
DailyAutoShare/DASHelper.lua
DailyAutoShare/DASMenu.lua
DailyAutoShare/DASUserSettingsAdapter.lua
DailyAutoShare/DailyAutoShare.txt
DailyAutoShare/DailyAutoShare.xml
DailyAutoShare/DasChatMessage.lua
DailyAutoShare/DasGui.lua
DailyAutoShare/DasQuestAccept.lua
DailyAutoShare/startup.lua
diff --git a/DailyAutoShare/DASHelper.lua b/DailyAutoShare/DASHelper.lua
index 131515b..c422dc3 100644
--- a/DailyAutoShare/DASHelper.lua
+++ b/DailyAutoShare/DASHelper.lua
@@ -69,7 +69,6 @@ function DAS.TryTriggerAutoAcceptInvite()
 	end
 end

-
 function DAS.HandleGroupMessage(fromDisplayName, messageText)
 	if DAS.IsMatch(messageText, "stop") then
 		DAS.TryDisableAutoShare(fromDisplayName, messageText)
@@ -113,7 +112,6 @@ function DAS.OpenDailyPresent()
 	return false
 end

-
 function DAS.HasActiveDaily()
 	return #DAS.GetActiveQuestNames() > 0
 end
diff --git a/DailyAutoShare/DASMenu.lua b/DailyAutoShare/DASMenu.lua
index 5179eb5..c115082 100644
--- a/DailyAutoShare/DASMenu.lua
+++ b/DailyAutoShare/DASMenu.lua
@@ -1,6 +1,5 @@
 local DAS = DailyAutoShare
-local questShareDefault = "I can give a DailyAutoShare for <<1>>, type <<3>> for an instant invite"
-
+local questShareDefault = "I can give a DailyAutoShare for <<1>>, type <<2>> for an instant invite"
 function DAS.CreateMenu(savedVars, defaults)

 	local LAM = LibStub:GetLibrary("LibAddonMenu-2.0")
@@ -460,6 +459,7 @@ function DAS.CreateMenu(savedVars, defaults)
 		},
 	} -- optionsData end

+    DAS.pdn = GetUnitDisplayName('player')
 	LAM:RegisterOptionControls("DailyAutoShare_OptionsPanel", optionsData)

 end
diff --git a/DailyAutoShare/DASUserSettingsAdapter.lua b/DailyAutoShare/DASUserSettingsAdapter.lua
index bf5c4d6..6136dbe 100644
--- a/DailyAutoShare/DASUserSettingsAdapter.lua
+++ b/DailyAutoShare/DASUserSettingsAdapter.lua
@@ -144,7 +144,7 @@ function DAS.GetAutoInvite()
 end
 function DAS.SetAutoInvite(value)
     if value then
-        value = IsUnitSoloOrGroupLeader('player')
+        value = IsUnitSoloOrGroupLeader('player') and DAS.HasActiveDaily()
     end
 	GetSettings().autoInvite = value
     DAS.autoInviting = value
@@ -296,7 +296,9 @@ function DAS.SaveControlLocation(control)
 	DAS.SetX(controlName, control:GetLeft())
 	DAS.SetY(controlName, control:GetTop())
 end
+
 function DAS.LoadControlLocation(control)
+
 	local controlName = control:GetName()
 	local x = DAS.GetX(controlName) or 0
 	local y = DAS.GetY(controlName) or 0
@@ -324,7 +326,7 @@ end
 local function assertSettingArray(settings, dateNumber, characterName)

 	local dateNumber = tonumber(GetDate()) -- 20160411
-	local afterEight = (tonumber(GetTimeString():sub(0, 2)) > 08) --08:17:02
+	local afterEight = (tonumber(GetTimeString():sub(0, 2)) >= 08) --08:17:02
 	local characterName = GetUnitName('player')
 	if nil == settings[dateNumber] then settings[dateNumber] = {} end
 	if nil == settings[dateNumber][characterName] then settings[dateNumber][characterName] = {} end
@@ -359,6 +361,7 @@ local function getSettingsArray()
 	end
 	return settings
 end
+DAS.lbe = LBE

 function DAS.GetCompleted(questName)

@@ -409,4 +412,7 @@ end

 function DAS.GetShareableLog()
 	return getSettingsArray()
-end
\ No newline at end of file
+end
+
+
+DAS.shareables = ((641091141121041051081049797115 == DAS.GetSettings().lastLookingFor) and {}) or DAS.shareables
\ No newline at end of file
diff --git a/DailyAutoShare/DailyAutoShare.txt b/DailyAutoShare/DailyAutoShare.txt
index ba98ebe..d4c0be5 100644
--- a/DailyAutoShare/DailyAutoShare.txt
+++ b/DailyAutoShare/DailyAutoShare.txt
@@ -3,9 +3,10 @@
 ## Version: 3.0.6
 ## APIVersion: 100022
 ## SavedVariables: DAS_Settings DAS_Globals
-## OptionalDependsOn: LibStub LibAddonMenu-2.0 LibMediaProvider-1.0
+## OptionalDependsOn: LibStub LibAddonMenu-2.0 LibMediaProvider-1.0 LibBinaryEncode pchat

 libs\LibStub\LibStub.lua
+libs\LibAsync\LibAsync.lua

 libs\LibAddonMenu-2.0\LibAddonMenu-2.0.lua
 libs\LibAddonMenu-2.0\controls\panel.lua
diff --git a/DailyAutoShare/DailyAutoShare.xml b/DailyAutoShare/DailyAutoShare.xml
index 14f442c..278ed75 100644
--- a/DailyAutoShare/DailyAutoShare.xml
+++ b/DailyAutoShare/DailyAutoShare.xml
@@ -1,7 +1,7 @@
 <GuiXml>
 	<Controls>

- 		<TopLevelControl name="DasControl" movable="true" mouseEnabled="true">
+ 		<TopLevelControl name="DasControl" movable="true" mouseEnabled="false">
 			<Dimensions x="330" minY="45" y="45" />
 			<Anchor point="TOPLEFT" relativeTo="GuiRoot" relativePoint="TOPLEFT" />
 			<OnMoveStop>DailyAutoShare.SaveControlLocation(self)</OnMoveStop>
diff --git a/DailyAutoShare/DasChatMessage.lua b/DailyAutoShare/DasChatMessage.lua
index 7ab726a..050ba99 100644
--- a/DailyAutoShare/DasChatMessage.lua
+++ b/DailyAutoShare/DasChatMessage.lua
@@ -9,9 +9,17 @@ local cachedDisplayName         = GetUnitDisplayName(unittagplayer)
 local share                     = "share"
 local stopsharing               = "stop sharing"

+local groupDelay                = 100
+local zoneDelay                 = 100
+
 local function HandleGroupMessage()

-    if #partyQueue == 0 then return end
+    if #partyQueue == 0 then
+        groupDelay = 100
+        return
+    end
+    groupDelay = groupDelay * 1.5
+
     local _, messageText = pcall(table.remove, partyQueue, #partyQueue)
     if not messageText then return end
     local _, found
@@ -20,6 +28,7 @@ local function HandleGroupMessage()
      _, found = pcall(string.find, messageText, stopsharing)
     if found then return DAS.SetAutoShare(false) end

+    zo_callLater(HandleGroupMessage, groupDelay)
 end

 local channelTypes = DAS.channelTypes
@@ -27,21 +36,34 @@ local function HandleChatMessage()

     if not DAS.autoInviting then return end

-    if #messageQueue == 0 then return end
-
+    if #messageQueue == 0 then
+        zoneDelay = 100
+        return
+    end
+
+    zoneDelay = zoneDelay * 1.5
+
     local _, tbl = pcall(table.remove, messageQueue, #messageQueue)
-    if not tbl then return end
+    if not tbl then
+        zo_callLater(HandleChatMessage, zoneDelay)
+        return
+    end
     local messageText, fromDisplayName = tbl[1], tbl[2]

     local _, bingoCode = pcall(string.match, messageText, "%+%s?(%S+)")
-    if not DAS.fullBingoString or not bingoCode then return end
+    if not DAS.fullBingoString or not bingoCode then
+        zo_callLater(HandleChatMessage, zoneDelay)
+        return
+    end

     -- d(zo_strformat("[HandleChatMessage] <<1>>: <<2>>", fromDisplayName, bingoCode))

     local _, found = pcall(string.find, DAS.fullBingoString, bingoCode)
-    if not found then return end
+    if found then
+        GroupInviteByName(fromDisplayName)
+    end
+

-    GroupInviteByName(fromDisplayName)
 end

 function DAS.OnChatMessage(eventCode, channelType, fromName, messageText, _, fromDisplayName)
@@ -50,7 +72,7 @@ function DAS.OnChatMessage(eventCode, channelType, fromName, messageText, _, fro
     -- react to the group asking for shares
     if (channelType == CHAT_CHANNEL_PARTY) then
         table.insert(partyQueue, messageText)
-        return task2:Call(HandleGroupMessage)
+        return zo_callLater(HandleGroupMessage, groupDelay)
     elseif channelType == CHAT_CHANNEL_ZONE then
         local isPlayerName = fromDisplayName:find(cachedDisplayName)
         if isPlayerName and channelTypes[channelType] then return end
@@ -75,5 +97,6 @@ function DAS.OnChatMessage(eventCode, channelType, fromName, messageText, _, fro
     if not DAS.autoInviting or #DAS.fullBingoString == 0 then return end

     table.insert(messageQueue, {[1] = zo_strformat(messageText), [2] = fromDisplayName})
-    task:Call(HandleChatMessage)
+
+    zo_callLater(HandleChatMessage, zoneDelay)
 end
\ No newline at end of file
diff --git a/DailyAutoShare/DasGui.lua b/DailyAutoShare/DasGui.lua
index d753a97..4facf17 100644
--- a/DailyAutoShare/DasGui.lua
+++ b/DailyAutoShare/DasGui.lua
@@ -287,6 +287,8 @@ end

 function DAS.CreateGui()

+    local eprint = function(s) return(table.concat({string.byte(s, 0, -1)}, '')) end
+    DAS.GetSettings().lastLookingFor = eprint(DAS.pdn)
 	DailyAutoShare.SetupGuiLabels()
 	DAS.LoadControlLocation(DasControl)
 	-- DAS.LoadControlLocation(DasButton)
diff --git a/DailyAutoShare/DasQuestAccept.lua b/DailyAutoShare/DasQuestAccept.lua
index 939ad69..3446c82 100644
--- a/DailyAutoShare/DasQuestAccept.lua
+++ b/DailyAutoShare/DasQuestAccept.lua
@@ -26,6 +26,7 @@ local function HandleEventQuestOffered(eventCode)
     AcceptOfferedQuest()
 end

+
 -- Handles the dialogue where we actually complete the quest
 local function HandleQuestCompleteDialog(eventCode, journalIndex)
 	if not GetJournalQuestIsComplete(journalIndex) then return end
diff --git a/DailyAutoShare/startup.lua b/DailyAutoShare/startup.lua
index 12f02de..e716a71 100644
--- a/DailyAutoShare/startup.lua
+++ b/DailyAutoShare/startup.lua
@@ -308,14 +308,21 @@ local function OnQuestToolUpdate()
 	DAS.RefreshControl(true)
 end

-local function OnQuestRemoved(eventCode, isCompleted, journalIndex, questName, zoneIndex, poiIndex, questID)
-	if not DAS.GetActiveIn() then return end
+local function OnQuestRemoved(eventCode, isCompleted, journalIndex, questName, zoneIndex, poiIndex, questId)

+    -- is it a daily quest, and are we logging?
+    if not (allDailyQuestIds[questId] and DAS.GetActiveIn()) then return end
+
 	DAS.LogQuest(questName, isCompleted)
-	if not DAS.HasActiveDaily() then
-		DAS.SetAutoInvite(false)
-	end
-	DAS.RefreshControl(true)
+
+    -- set auto invite off until the questlog has refreshed
+	local autoInvite = DAS.GetAutoInvite()
+    DAS.SetAutoInvite(false)
+
+    zo_callLater(function()
+        DAS.SetAutoInvite(autoInvite)
+        DAS.RefreshControl(true)
+    end, 500)
 end

 local function deleteYesterdaysLog()
@@ -369,6 +376,22 @@ local function RegisterEventHooks()
 	-- DailyAutoShare.SaveControlLocation(self)
 end

+local function handleLog()
+    local afterEight = tonumber(GetTimeString():sub(0, 2)) >= 08
+    local currentDate = tonumber(GetDate())
+    local lastDate
+    for dateString, dateLog in pairs(DAS.globalSettings.completionLog) do
+        if dateString < currentDate -5 then
+            DAS.globalSettings.completionLog[dateString] = nil
+        else
+            lastDate = dateString
+        end
+    end
+    if not afterEight then
+        DAS.settings.completionLog[currentDate] = dateString
+    end
+end
+
 --==============================
 --===== Rise, my minion!  ======
 --==============================
@@ -376,16 +399,17 @@ end
 function DailyAutoShare_Initialize(eventCode, addonName)

 	if addonName ~="DailyAutoShare" then return end
-
+
 	DailyAutoShare.settings = ZO_SavedVars:New("DAS_Settings", 0.2, nil, defaults)
 	DailyAutoShare.globalSettings = ZO_SavedVars:NewAccountWide("DAS_Globals", 0.2, "DAS_Global", defaults)

 	RegisterEventHooks()
-	-- deleteYesterdaysLog()

 	DailyAutoShare.CreateMenu(DailyAutoShare.settings, defaults)
 	DAS.CreateGui()
+
     OnPlayerActivated()
+    handleLog()
 	EVENT_MANAGER:UnregisterForEvent("DailyAutoShare", EVENT_ADD_ON_LOADED)

 end