Zerotorescue@3: -- You can access this addon's object through: LibStub("AceAddon-3.0"):GetAddon("MailOpener") Zerotorescue@3: local MailOpener = LibStub("AceAddon-3.0"):NewAddon("MailOpener", "AceEvent-3.0", "AceTimer-3.0"); Zerotorescue@0: Zerotorescue@8: -- You can check if MailOpener is busy with the global MailAddonBusy (if not MailAddonBusy then ...do something... end) Zerotorescue@8: -- MailAddonBusy will be nil when nothing is happening or filled with the addon name when MO is working Zerotorescue@8: -- Another addon can use this variable to indicate they're working too, MailOpener will then wait for that to finish Zerotorescue@3: Zerotorescue@3: local AutoOpenMail, MailOpenerConfig, lastAmount, lastQuickAuctionsStatus, freshList, mailboxEmptySoundPlayed; Zerotorescue@0: Zerotorescue@0: function MailOpener:OnInitialize() Zerotorescue@0: local defaults = { Zerotorescue@0: profile = { Zerotorescue@8: uses = 0, Zerotorescue@0: general = { Zerotorescue@8: defaultStatus = "disabled", -- addon enabled, but mail opening not auto on Zerotorescue@0: defaultQAStatus = "__remember", Zerotorescue@0: continueOpeningStackableItems = false, Zerotorescue@0: autoDisableQAAutoMail = true, Zerotorescue@0: autoReenableQAAutoMail = false, Zerotorescue@0: autoSetBackQAAutoMail = true, Zerotorescue@0: continueOpening = false, Zerotorescue@0: waitTime = 5, Zerotorescue@0: initialDelay = 0.5, Zerotorescue@0: }, Zerotorescue@0: modules = { Zerotorescue@0: Collected = true, Zerotorescue@5: FailSafe = true, Zerotorescue@0: }, Zerotorescue@0: notifications = { Zerotorescue@3: welcome = false, Zerotorescue@3: bye = false, Zerotorescue@0: finishedCurrentBatch = true, Zerotorescue@0: mailboxIsEmpty = true, Zerotorescue@0: Zerotorescue@0: skipped = { Zerotorescue@0: all = true, Zerotorescue@0: inventoryFull = true, Zerotorescue@0: keepFreeSpaceLimit = true, Zerotorescue@0: GMMail = true, Zerotorescue@0: COD = true, Zerotorescue@0: normalGoldMail = true, Zerotorescue@0: normalItemsMail = true, Zerotorescue@0: AHexpired = true, Zerotorescue@0: AHsuccess = true, Zerotorescue@0: AHwon = true, Zerotorescue@0: AHcanceled = true, Zerotorescue@0: AHoutbid = true, Zerotorescue@0: other = true, Zerotorescue@0: }, Zerotorescue@0: processed = { Zerotorescue@0: all = true, Zerotorescue@0: normalGoldMail = true, Zerotorescue@0: normalItemsMail = true, Zerotorescue@0: AHexpired = true, Zerotorescue@0: AHsuccess = true, Zerotorescue@0: AHwon = true, Zerotorescue@0: AHcanceled = true, Zerotorescue@0: AHoutbid = true, Zerotorescue@0: other = true, Zerotorescue@0: }, Zerotorescue@0: Zerotorescue@0: bagsFullSound = false, Zerotorescue@0: bagsFullSoundFile = "Sound\\Spells\\SimonGame_Visual_BadPress.wav", Zerotorescue@0: bagsFullSoundFileName = "Simon Error", Zerotorescue@0: bagsFullSoundOnlyOnce = true, Zerotorescue@0: mailboxEmptySound = false, Zerotorescue@0: mailboxEmptySoundFile = "Sound\\Spells\\SimonGame_Visual_GameStart.wav", Zerotorescue@0: mailboxEmptySoundFileName = "Simon Start", Zerotorescue@0: mailboxEmptySoundOnlyOnce = true, Zerotorescue@0: }, Zerotorescue@0: }, Zerotorescue@0: }; Zerotorescue@0: Zerotorescue@0: -- Register our saved variables database Zerotorescue@0: self.db = LibStub("AceDB-3.0"):New("MailOpenerDB", defaults, true); Zerotorescue@0: Zerotorescue@0: -- Set these as object variables so we can use them in our modules Zerotorescue@0: if select(6, GetAddOnInfo("Postal")) == nil then Zerotorescue@0: self.PostalEnabled = true; Zerotorescue@0: Zerotorescue@0: -- Ensure this addon is loaded if AddonLoader is installed Zerotorescue@0: if AddonLoader and AddonLoader.LoadAddOn and not Postal then Zerotorescue@0: AddonLoader:LoadAddOn("Postal"); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: if select(6, GetAddOnInfo("QuickAuctions")) == nil then Zerotorescue@0: self.QuickAuctionsEnabled = true; Zerotorescue@0: Zerotorescue@0: -- Ensure this addon is loaded if AddonLoader is installed Zerotorescue@0: if AddonLoader and AddonLoader.LoadAddOn then Zerotorescue@0: AddonLoader:LoadAddOn("QuickAuctions"); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- Don't enable the config module until we need it Zerotorescue@0: for name, module in self:IterateModules() do Zerotorescue@0: if name == "Config" then Zerotorescue@0: module:SetEnabledState(false); Zerotorescue@0: elseif self.db.profile.modules[name] ~= nil then Zerotorescue@0: if self.db.profile.modules[name] then Zerotorescue@0: self:Debug("|cff00ff00Enabling|r module: " .. name); Zerotorescue@0: else Zerotorescue@0: self:Debug("|cffff0000Disabling|r module: " .. name); Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: module:SetEnabledState(self.db.profile.modules[name]); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- Make the open all checkbox Zerotorescue@0: local check = CreateFrame("CheckButton", "cbMailOpenerEnable", MailFrame, "ChatConfigCheckButtonTemplate"); Zerotorescue@0: check:SetHeight(26); Zerotorescue@0: check:SetWidth(26); Zerotorescue@3: check:SetChecked(true); Zerotorescue@0: check:SetHitRectInsets(0, -80, 0, 0); Zerotorescue@0: check:SetScript("OnClick", function(self) Zerotorescue@3: if IsShiftKeyDown() then Zerotorescue@3: -- Shift key = toggle addon on or off, since addon is already on there's only one option Zerotorescue@3: Zerotorescue@3: if not MailOpener:IsEnabled() then Zerotorescue@3: print("|cff15ff00Mail Opener|r: Shift key was held down, so |cff00ff00enabling|r the entire addon as well as automatic opening of mail."); Zerotorescue@3: Zerotorescue@3: MailOpener:Enable(); Zerotorescue@3: Zerotorescue@3: -- The above calls MAIL_SHOW which changes AutoOpenMail, so we can't remember the old setting Zerotorescue@3: AutoOpenMail = true; Zerotorescue@3: Zerotorescue@3: self:SetChecked(true); Zerotorescue@3: else Zerotorescue@3: print("|cff15ff00Mail Opener|r: Shift key was held down, so |cffff0000disabling|r the entire addon."); Zerotorescue@3: Zerotorescue@3: MailOpener:Disable(); Zerotorescue@3: Zerotorescue@3: self:SetChecked(false); Zerotorescue@3: end Zerotorescue@0: else Zerotorescue@3: -- Normal click Zerotorescue@3: Zerotorescue@3: if self:GetChecked() then Zerotorescue@3: print("|cff15ff00Mail Opener|r: |cff00ff00Enabling|r automatic opening of mail."); Zerotorescue@3: Zerotorescue@3: AutoOpenMail = true; Zerotorescue@8: MailOpener:ScheduleOpen(false); Zerotorescue@3: else Zerotorescue@3: print("|cff15ff00Mail Opener|r: |cffff0000Disabling|r automatic opening of mail."); Zerotorescue@3: Zerotorescue@3: AutoOpenMail = false; Zerotorescue@3: end Zerotorescue@0: end Zerotorescue@0: end); Zerotorescue@3: check.tooltip = "Toggle automatic mail opening on or off (you can force this by holding shift when opening the mailbox.\n\nHold the |cffffffffSHIFT|r key to disable the entire addon."; Zerotorescue@0: check:SetPoint("TOPLEFT", MailFrame, "TOPLEFT", 68, -13) Zerotorescue@0: Zerotorescue@0: if self.QuickAuctionsEnabled then Zerotorescue@0: -- QA is enabled so move the checkbox further to the right Zerotorescue@0: Zerotorescue@0: check:SetPoint("TOPLEFT", MailFrame, "TOPLEFT", 155, -13); Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- Get reference to the text field Zerotorescue@0: local checkboxText = _G[check:GetName() .. "Text"]; Zerotorescue@0: checkboxText:SetText("Mail Opener"); Zerotorescue@0: -- We like this color more Zerotorescue@0: checkboxText:SetTextColor(1, 0.8, 0, 1); Zerotorescue@0: Zerotorescue@0: self.cbOpenAll = check; Zerotorescue@0: Zerotorescue@0: -- Make the config button Zerotorescue@0: local button = CreateFrame("Button", "btnMailOpenerConfig", MailFrame, "UIPanelButtonTemplate") Zerotorescue@0: button:SetText("Config") Zerotorescue@0: button:SetHeight(23) Zerotorescue@0: button:SetWidth(55) Zerotorescue@0: if self.PostalEnabled then Zerotorescue@0: button:SetPoint("TOPRIGHT", MailFrame, "TOPRIGHT", -75, -13); Zerotorescue@0: else Zerotorescue@0: button:SetPoint("TOPRIGHT", MailFrame, "TOPRIGHT", -55, -13); Zerotorescue@0: end Zerotorescue@0: button:SetScript("OnClick", function() Zerotorescue@0: MailOpener:EnableConfigModule(); Zerotorescue@0: Zerotorescue@0: MailOpenerConfig:Show(); Zerotorescue@0: Zerotorescue@8: --BETA:if MailOpener.db.profile.uses >= 15 then Zerotorescue@7: --BETA: MailOpener:ShowBetaPopup(); Zerotorescue@7: --BETA:end Zerotorescue@0: end); Zerotorescue@0: Zerotorescue@0: self.btnConfig = button; Zerotorescue@0: Zerotorescue@0: -- Disable the AddonLoader slash commands Zerotorescue@0: SLASH_MO1 = nil; Zerotorescue@0: SLASH_MAILOPEN1 = nil; Zerotorescue@0: SLASH_MAILOPENER1 = nil; Zerotorescue@0: Zerotorescue@0: -- Register our own slash commands Zerotorescue@0: SLASH_MAILOPENER1 = "/mo"; Zerotorescue@0: SLASH_MAILOPENER2 = "/mailopen"; Zerotorescue@0: SLASH_MAILOPENER3 = "/mailopener"; Zerotorescue@0: SlashCmdList["MAILOPENER"] = function(msg) Zerotorescue@0: MailOpener:EnableConfigModule(); Zerotorescue@0: Zerotorescue@0: MailOpenerConfig:CommandHandler(msg); Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- Attempt to remove the interface options added by AddonLoader (if enabled) Zerotorescue@0: if AddonLoader and AddonLoader.RemoveInterfaceOptions then Zerotorescue@0: AddonLoader:RemoveInterfaceOptions("Mail Opener"); Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- Now create our own options frame Zerotorescue@0: local frame = CreateFrame("Frame", nil, UIParent); Zerotorescue@0: frame:Hide(); Zerotorescue@0: frame.name = "Mail Opener"; Zerotorescue@0: frame:HookScript("OnShow", function(self) Zerotorescue@0: -- Enable the config module Zerotorescue@0: MailOpener:EnableConfigModule(); Zerotorescue@0: Zerotorescue@0: -- Load the options and add it to the blizzard interface list Zerotorescue@0: MailOpenerConfig:Load(); Zerotorescue@0: Zerotorescue@0: -- Refresh the frame to instantly show the right options Zerotorescue@0: InterfaceOptionsFrame_OpenToCategory(self.name) Zerotorescue@0: end); Zerotorescue@0: -- And add it to the interface options Zerotorescue@0: InterfaceOptions_AddCategory(frame); Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: function MailOpener:OnEnable() Zerotorescue@0: self:RegisterEvent("MAIL_SHOW"); Zerotorescue@0: self:RegisterEvent("PLAYER_ENTERING_WORLD"); Zerotorescue@0: Zerotorescue@0: self.btnConfig:Show(); Zerotorescue@0: Zerotorescue@0: -- Reset variables Zerotorescue@0: lastAmount = 0; Zerotorescue@0: self.debugChannel = nil; Zerotorescue@0: Zerotorescue@8: --BETA:if (self.db.profile.uses % 15) == 0 then Zerotorescue@7: --BETA: -- Automatically show once every 15 uses Zerotorescue@7: --BETA: self:ShowBetaPopup(); Zerotorescue@7: --BETA:end Zerotorescue@0: Zerotorescue@0: -- If we were toggling this addon on while the mailbox is opened we must register all events again Zerotorescue@0: if MailFrame:IsVisible() then Zerotorescue@0: self:MAIL_SHOW(); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: function MailOpener:OnDisable() Zerotorescue@0: self:UnregisterEvent("MAIL_SHOW"); Zerotorescue@0: Zerotorescue@0: self.btnConfig:Hide(); Zerotorescue@0: Zerotorescue@0: MailOpener:Stop(); Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- We must disable Quick Auction's auto mail (if set up that way in the settings) before opening the mailbox or it will instantly start sending stuff Zerotorescue@0: function MailOpener:PLAYER_ENTERING_WORLD() Zerotorescue@0: self:UnregisterEvent("PLAYER_ENTERING_WORLD"); Zerotorescue@0: Zerotorescue@0: self:ToggleQAStatus(); Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- Fired when the mailbox is opened Zerotorescue@0: function MailOpener:MAIL_SHOW() Zerotorescue@0: -- To stop the timer when the mailbox is closed Zerotorescue@0: self:RegisterEvent("MAIL_CLOSED", "Stop"); Zerotorescue@0: self:RegisterEvent("PLAYER_LEAVING_WORLD", "Stop"); Zerotorescue@0: Zerotorescue@0: -- To set the timer for when to refresh again Zerotorescue@0: self:RegisterEvent("MAIL_INBOX_UPDATE"); Zerotorescue@0: Zerotorescue@0: -- We need to know when opening has completed Zerotorescue@0: self:RegisterMessage("MO_OPEN_COMPLETE"); Zerotorescue@0: Zerotorescue@8: if self.db.profile.uses == 0 then Zerotorescue@8: --TODO:statispopupdialog Zerotorescue@8: end Zerotorescue@8: Zerotorescue@8: self.db.profile.uses = ( self.db.profile.uses + 1 ); Zerotorescue@8: Zerotorescue@0: self:Debug("defaultStatus:" .. self.db.profile.general.defaultStatus); Zerotorescue@0: -- Change the mail opening status according to our settings Zerotorescue@0: if self.db.profile.general.defaultStatus == "_enabled" then Zerotorescue@3: AutoOpenMail = true; Zerotorescue@3: self.cbOpenAll:SetChecked(true); Zerotorescue@3: elseif self.db.profile.general.defaultStatus == "disabled" then Zerotorescue@3: -- Disable auto opening but leave mail opener enabled Zerotorescue@3: Zerotorescue@3: AutoOpenMail = false; Zerotorescue@3: self.cbOpenAll:SetChecked(false); Zerotorescue@3: elseif self.db.profile.general.defaultStatus == "xdisabled" then Zerotorescue@3: -- Disable entire addon Zerotorescue@3: Zerotorescue@3: MailOpener:Disable(); Zerotorescue@3: self.cbOpenAll:SetChecked(false); Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: self:ToggleQAStatus(); Zerotorescue@0: Zerotorescue@0: -- Hide the InboxTooMuchMail warning to allow room for our mail remaining info line Zerotorescue@0: InboxTooMuchMail:Hide() Zerotorescue@0: InboxTooMuchMail.Show = function() end Zerotorescue@0: Zerotorescue@0: if self.QuickAuctionsEnabled then Zerotorescue@8: local QAMail = LibStub("AceAddon-3.0"):GetAddon("QuickAuctions", true):GetModule("Mail", true); Zerotorescue@0: Zerotorescue@8: if QAMail then Zerotorescue@8: -- Hide the open all button Zerotorescue@8: QAMail.massOpening:Hide(); Zerotorescue@8: -- Hide the x mail remaining text Zerotorescue@8: QAMail.totalMail:Hide(); Zerotorescue@8: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: if self.db.profile.notifications.welcome then Zerotorescue@0: -- Welcome notification Zerotorescue@0: local _, c = UnitClass("player"); Zerotorescue@0: c = RAID_CLASS_COLORS[c]; Zerotorescue@0: c = string.format("|cff%02x%02x%02x", c.r * 255 + 0.5, c.g * 255 + 0.5, c.b * 255 + 0.5); Zerotorescue@0: Zerotorescue@0: print("|cff15ff00Mail Opener|r: Welcome back "..c..UnitName("player").."|r. Requesting new mail from the local Postal Service, your mail will automatically be opened when it becomes available."); Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: mailboxEmptySoundPlayed = nil; Zerotorescue@0: Zerotorescue@0: self:Recheck(); Zerotorescue@0: Zerotorescue@0: if self.db.profile.general.continueOpening then Zerotorescue@6: -- Continue opening mail, but use the "initial mail opening interval" as time Zerotorescue@6: self:ScheduleOpen(false); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- Fired after a successful server sync Zerotorescue@0: -- Fired when mail is deleted (which happens after taking all attachments from a mail sent by the game) Zerotorescue@0: function MailOpener:MAIL_INBOX_UPDATE() Zerotorescue@0: local current, total = GetInboxNumItems(); Zerotorescue@0: Zerotorescue@3: -- Calculate the amount of mail waiting that actually have attachments Zerotorescue@3: -- If we just compare numbers we won't be including mail that isn't automatically deleted when opened, such as mail with attachments sent by other players Zerotorescue@3: local currentMailWithAttachments = 0; Zerotorescue@3: for i = 1, current do Zerotorescue@3: local _, _, _, _, money, _, _, items = GetInboxHeaderInfo(i); Zerotorescue@3: Zerotorescue@3: if (items and items > 0) or (money and money > 0) then Zerotorescue@3: currentMailWithAttachments = currentMailWithAttachments + 1; Zerotorescue@3: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@3: local tempLastAmount = lastAmount; Zerotorescue@3: lastAmount = currentMailWithAttachments; Zerotorescue@3: Zerotorescue@3: if currentMailWithAttachments ~= tempLastAmount then Zerotorescue@3: self:Debug("MAIL_INBOX_UPDATE - lastAmount:" .. tempLastAmount .. " - current:" .. currentMailWithAttachments); Zerotorescue@3: end Zerotorescue@3: Zerotorescue@3: if currentMailWithAttachments > tempLastAmount then Zerotorescue@0: -- New messages arrived in our mailbox, so this was a refresh, so set a timer Zerotorescue@0: Zerotorescue@3: self:Debug("MO_SERVER_SYNCED"); Zerotorescue@3: Zerotorescue@0: -- Yell that we successfully synced with the server Zerotorescue@0: self:SendMessage("MO_SERVER_SYNCED"); Zerotorescue@0: Zerotorescue@0: -- This list is fresh Zerotorescue@0: freshList = true; Zerotorescue@0: mailboxEmptySoundPlayed = nil; Zerotorescue@0: Zerotorescue@0: -- Stop previous timer Zerotorescue@0: self:CancelTimer(self.tmrRecheck, true); Zerotorescue@0: -- More will arrive in 60 seconds Zerotorescue@0: self.tmrRecheck = self:ScheduleTimer(function() Zerotorescue@0: self:Debug("tmrRecheck 61 finished"); Zerotorescue@0: Zerotorescue@0: -- We can get a fresh list now, so query the server Zerotorescue@0: freshList = false; Zerotorescue@0: Zerotorescue@0: -- Look for mail Zerotorescue@0: self:Recheck(); Zerotorescue@0: end, 61); Zerotorescue@0: self:Debug("tmrRecheck 61"); Zerotorescue@0: Zerotorescue@0: if not IsShiftKeyDown() then Zerotorescue@0: -- Allow overriding of mailopening with the shift key Zerotorescue@0: Zerotorescue@0: -- Open the current mail Zerotorescue@0: self:ScheduleOpen(false); Zerotorescue@0: end Zerotorescue@3: elseif currentMailWithAttachments < tempLastAmount then Zerotorescue@2: -- We lost a mail Zerotorescue@2: Zerotorescue@3: -- TODO: NYI: May need to delay this until the mail is actually deleted Zerotorescue@3: Zerotorescue@3: self:Debug("MO_MAIL_EMPTIED"); Zerotorescue@3: Zerotorescue@2: -- Yell that we successfully opened/removed a mail Zerotorescue@3: self:SendMessage("MO_MAIL_EMPTIED"); Zerotorescue@3: elseif (currentMailWithAttachments == 50 and tempLastAmount == 50) then Zerotorescue@0: if not IsShiftKeyDown() then Zerotorescue@0: -- Allow overriding of mailopening with the shift key Zerotorescue@0: Zerotorescue@0: -- Open the current mail Zerotorescue@0: self:ScheduleOpen(false); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: function MailOpener:ScheduleOpen(continued) Zerotorescue@0: if lastAmount > 0 then Zerotorescue@0: local waitTime; Zerotorescue@0: if continued then Zerotorescue@0: waitTime = self.db.profile.general.waitTime; Zerotorescue@0: else Zerotorescue@0: -- Even though this is not a continuation and should be instant, we set a .5 second timer to prevent multiple calls of the OpenNow function Zerotorescue@0: waitTime = self.db.profile.general.initialDelay; Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- Stop previous timer Zerotorescue@0: self:CancelTimer(self.tmrOpenNow, true); Zerotorescue@0: -- Schedule the next open Zerotorescue@0: self.tmrOpenNow = self:ScheduleTimer("OpenNow", waitTime); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: function MailOpener:OpenNow() Zerotorescue@8: self:Debug("OpenNow (" .. ((MailAddonBusy and "1") or "0") .. ")"); Zerotorescue@8: if MailFrame:IsVisible() and AutoOpenMail then Zerotorescue@0: self:Debug("OpenNow"); Zerotorescue@0: Zerotorescue@0: -- BeanCounter is the only addon hiding the mail close button while busy, so we can look for that Zerotorescue@0: local BeanCounterActive = not InboxCloseButton:IsVisible(); Zerotorescue@0: Zerotorescue@8: if not BeanCounterActive and not MailAddonBusy then Zerotorescue@8: -- No other addon is currently active Zerotorescue@0: Zerotorescue@0: self:CancelTimer(self.tmrTryAgain, true); -- Insurance Zerotorescue@0: Zerotorescue@0: if QuickAuctionsAutoMail then Zerotorescue@0: -- Remember the last known quick auctions status Zerotorescue@0: lastQuickAuctionsStatus = QuickAuctionsAutoMail:GetChecked(); Zerotorescue@0: end Zerotorescue@0: if self.db.profile.general.autoDisableQAAutoMail and self.QuickAuctionsEnabled and QuickAuctionsAutoMail and QuickAuctionsAutoMail:GetChecked() then Zerotorescue@0: -- If auto disable "QA Auto mail" is enabled and QA's auto mail is currently toggled on, turn it off Zerotorescue@0: -- We need to do this with a :click to trigger the right events Zerotorescue@0: Zerotorescue@0: self:Debug("Turning automail |cffff0000off|r."); Zerotorescue@0: Zerotorescue@0: QuickAuctionsAutoMail:Click(); Zerotorescue@0: end Zerotorescue@0: Zerotorescue@8: MailAddonBusy = self:GetName(); Zerotorescue@0: Zerotorescue@0: self:Debug("MO_OPEN_MAIL"); Zerotorescue@0: Zerotorescue@0: -- Summon the mail opening gods Zerotorescue@0: self:SendMessage("MO_OPEN_MAIL"); Zerotorescue@0: else Zerotorescue@8: -- Another addon is ACTIVE Zerotorescue@8: self:Debug("Another addon active, waiting .5 seconds..."); Zerotorescue@0: Zerotorescue@0: self:CancelTimer(self.tmrTryAgain, true); -- Insurance Zerotorescue@8: -- Try again every 0.5 seconds Zerotorescue@0: self.tmrTryAgain = self:ScheduleTimer("OpenNow", 0.5); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: function MailOpener:MO_OPEN_COMPLETE() Zerotorescue@8: if MailAddonBusy == self:GetName() then Zerotorescue@8: MailAddonBusy = nil; Zerotorescue@8: end Zerotorescue@1: Zerotorescue@1: -- Try a recheck Zerotorescue@1: self:Recheck(); Zerotorescue@1: Zerotorescue@0: local current, total = GetInboxNumItems(); Zerotorescue@0: Zerotorescue@0: if (total - current) == 0 then Zerotorescue@3: -- There is probably no unopenable mail remaining, so play the sound (if enabled) Zerotorescue@3: Zerotorescue@0: if self.db.profile.notifications.mailboxEmptySound and (not MailOpener.db.profile.notifications.mailboxEmptySoundOnlyOnce or not mailboxEmptySoundPlayed) then Zerotorescue@0: PlaySoundFile(self.db.profile.notifications.mailboxEmptySoundFile); Zerotorescue@0: mailboxEmptySoundPlayed = true; Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@3: if self.QuickAuctionsEnabled then Zerotorescue@3: -- Quick Auctions enabled? Zerotorescue@3: -- Toggle automailing as per settings Zerotorescue@0: Zerotorescue@3: if self.db.profile.general.autoReenableQAAutoMail and QuickAuctionsAutoMail and not QuickAuctionsAutoMail:GetChecked() then Zerotorescue@3: -- If auto re-enable "QA Auto mail" is enabled and QA's auto mail is currently toggled OFF, turn it on Zerotorescue@3: -- We need to do this with a :click to trigger the right events Zerotorescue@3: Zerotorescue@0: self:Debug("Turning automail |cff00ff00on|r."); Zerotorescue@3: Zerotorescue@3: QuickAuctionsAutoMail:Click(); Zerotorescue@3: elseif self.db.profile.general.autoSetBackQAAutoMail and QuickAuctionsAutoMail and lastQuickAuctionsStatus ~= QuickAuctionsAutoMail:GetChecked() then Zerotorescue@3: -- If auto set back "QA Auto mail" is enabled and QA's auto mail is currently not the same as it was before starting, toggle it Zerotorescue@3: -- We need to do this with a :click to trigger the right events Zerotorescue@3: Zerotorescue@3: if lastQuickAuctionsStatus then Zerotorescue@3: self:Debug("Turning automail |cff00ff00on|r."); Zerotorescue@3: else Zerotorescue@3: self:Debug("Turning automail |cffff0000off|r."); Zerotorescue@3: end Zerotorescue@3: Zerotorescue@3: QuickAuctionsAutoMail:Click(); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: if self.db.profile.general.continueOpening then Zerotorescue@0: self:ScheduleOpen(true); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- Run another CheckInbox Zerotorescue@0: function MailOpener:Recheck() Zerotorescue@0: self:Debug("|cffffff00Recheck|r"); Zerotorescue@0: Zerotorescue@0: -- Freshlist prevents this from being run too often Zerotorescue@0: -- It is set to true after a server sync Zerotorescue@0: -- and set to false 61 seconds afterwards with a recheck called instantly after it Zerotorescue@3: Zerotorescue@3: -- We're not refreshing while we're opening because it is automatically done when current batch was completely opened Zerotorescue@8: if not freshList and MailFrame:IsVisible() then Zerotorescue@0: self:Debug("|cff00ff00Recheck|r"); Zerotorescue@0: Zerotorescue@0: -- If this isn't a fresh list (so messages weren't received within the last 60 seconds) and the mailbox wasn't closed Zerotorescue@0: Zerotorescue@0: -- BeanCounter is the only addon hiding the mail close button while busy, so we can look for that Zerotorescue@0: local BeanCounterActive = not InboxCloseButton:IsVisible(); Zerotorescue@0: Zerotorescue@8: if not BeanCounterActive and AutoOpenMail and not MailAddonBusy then Zerotorescue@0: -- Query the server Zerotorescue@0: CheckInbox(); Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- Stop previous timer Zerotorescue@0: self:CancelTimer(self.tmrRecheck, true); Zerotorescue@0: -- Keep trying until it works Zerotorescue@0: self.tmrRecheck = self:ScheduleTimer("Recheck", 2); Zerotorescue@0: Zerotorescue@0: self:Debug("tmrRecheck 2"); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- Stop checking for new mail and unregister the events we needed Zerotorescue@0: function MailOpener:Stop() Zerotorescue@0: if self.db.profile.notifications.bye then Zerotorescue@0: print("|cff15ff00Mail Opener|r: Have a nice day. :)"); Zerotorescue@0: end Zerotorescue@0: Zerotorescue@8: if MailAddonBusy == self:GetName() then Zerotorescue@8: MailAddonBusy = nil; Zerotorescue@8: end Zerotorescue@0: Zerotorescue@0: -- We won't need this anymore Zerotorescue@0: self:UnregisterEvent("MAIL_CLOSED"); Zerotorescue@0: self:UnregisterEvent("PLAYER_LEAVING_WORLD"); Zerotorescue@0: self:UnregisterEvent("MAIL_INBOX_UPDATE"); Zerotorescue@0: Zerotorescue@0: -- Messages Zerotorescue@0: self:UnregisterMessage("MO_OPEN_COMPLETE"); Zerotorescue@0: Zerotorescue@0: -- Timers Zerotorescue@0: self:CancelTimer(self.tmrTryAgain, true); Zerotorescue@0: self:CancelTimer(self.tmrOpenNow, true); Zerotorescue@0: Zerotorescue@0: -- If we wait with disabling QA automail until MAIL_SHOW, QA will beat us to it and already start sending stuff Zerotorescue@0: self:ToggleQAStatus(); Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: function MailOpener:Debug(t) Zerotorescue@0: if not self.debugChannel and self.debugChannel ~= false then Zerotorescue@0: -- We want to check just once, so if you add a debug channel later just do a /reload (registering an event for this is wasted resources) Zerotorescue@0: self.debugChannel = false; Zerotorescue@0: Zerotorescue@0: for i = 1, NUM_CHAT_WINDOWS do Zerotorescue@0: local name = GetChatWindowInfo(i); Zerotorescue@0: Zerotorescue@0: if name:upper() == "DEBUG" then Zerotorescue@0: self.debugChannel = _G["ChatFrame" .. i]; Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: if self.debugChannel then Zerotorescue@0: self.debugChannel:AddMessage(t); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- Enable our config module if it's disabled and make a reference to it Zerotorescue@0: function MailOpener:EnableConfigModule() Zerotorescue@0: if not MailOpenerConfig then Zerotorescue@0: MailOpenerConfig = self:GetModule("Config"); Zerotorescue@0: MailOpenerConfig:Enable(); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- Toggle Postal's opening modules on or off Zerotorescue@0: function MailOpener:TogglePostalModule(name, status) Zerotorescue@0: if MailOpener.PostalEnabled and Postal then Zerotorescue@0: -- Postal must be enabled Zerotorescue@0: Zerotorescue@3: -- Toggle module (let Postal handle this) Zerotorescue@3: Postal.ToggleModule(nil, name, Postal:GetModule(name), status); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- Change Quick Auction's auto mail status based on our prefered settings Zerotorescue@0: function MailOpener:ToggleQAStatus() Zerotorescue@0: self:Debug("defaultQAStatus:" .. self.db.profile.general.defaultQAStatus); Zerotorescue@0: Zerotorescue@0: if self.QuickAuctionsEnabled and self.db.profile.general.defaultQAStatus ~= "__remember" and QuickAuctionsAutoMail then Zerotorescue@0: if self.db.profile.general.defaultQAStatus == "_enabled" and not QuickAuctionsAutoMail:GetChecked() then Zerotorescue@0: self:Debug("Turning automail |cff00ff00on|r."); Zerotorescue@0: Zerotorescue@0: QuickAuctionsAutoMail:Click(); Zerotorescue@0: elseif self.db.profile.general.defaultQAStatus == "disabled" and QuickAuctionsAutoMail:GetChecked() then Zerotorescue@0: self:Debug("Turning automail |cffff0000off|r."); Zerotorescue@0: Zerotorescue@0: QuickAuctionsAutoMail:Click(); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: function MailOpener:FormatMoney(copper) Zerotorescue@0: local gold = floor( copper / 10000 ); Zerotorescue@0: local silver = floor( ( copper - ( gold * 10000 ) ) / 100 ); Zerotorescue@0: local copper = mod(copper, 100); Zerotorescue@0: Zerotorescue@0: if gold > 0 then Zerotorescue@0: return format(GOLD_AMOUNT_TEXTURE .. " " .. SILVER_AMOUNT_TEXTURE .. " " .. COPPER_AMOUNT_TEXTURE, gold, 0, 0, silver, 0, 0, copper, 0, 0); Zerotorescue@0: elseif silver > 0 then Zerotorescue@0: return format(SILVER_AMOUNT_TEXTURE .. " " .. COPPER_AMOUNT_TEXTURE, silver, 0, 0, copper, 0, 0); Zerotorescue@0: else Zerotorescue@0: return format(COPPER_AMOUNT_TEXTURE, copper, 0, 0); Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@7: -- General copy window for multiple things (clickable URLs, the time remaining, and such) Zerotorescue@0: StaticPopupDialogs["MailOpenerCopyWindow"] = { Zerotorescue@0: text = "Please CTRL-C to copy.", Zerotorescue@0: button2 = CLOSE, Zerotorescue@0: hasEditBox = 1, Zerotorescue@0: hasWideEditBox = 1, Zerotorescue@0: OnShow = function() Zerotorescue@0: local editBox = _G[this:GetName().."WideEditBox"]; Zerotorescue@0: if editBox and MailOpener.currentPopupContents then Zerotorescue@0: editBox:SetText(MailOpener.currentPopupContents); Zerotorescue@0: editBox:SetFocus(); Zerotorescue@0: editBox:HighlightText(0); Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: -- Position the close button in the middle Zerotorescue@0: local button = _G[this:GetName().."Button2"]; Zerotorescue@0: if button then Zerotorescue@0: -- Remove previous know position Zerotorescue@0: button:ClearAllPoints(); Zerotorescue@0: button:SetWidth(200); Zerotorescue@0: -- Reposition in the center Zerotorescue@0: button:SetPoint("CENTER", editBox, "CENTER", 0, -30); Zerotorescue@0: end Zerotorescue@0: end, Zerotorescue@0: EditBoxOnEscapePressed = function() Zerotorescue@0: this:GetParent():Hide(); Zerotorescue@0: end, Zerotorescue@0: timeout = 0, Zerotorescue@0: whileDead = 1, Zerotorescue@0: hideOnEscape = 1, Zerotorescue@0: maxLetters = 1024, Zerotorescue@1: }; Zerotorescue@1: Zerotorescue@7: --BETA: The below either has to be removed or changed when releasing Zerotorescue@0: Zerotorescue@7: --[[ Zerotorescue@7: BETA/ALPHA request box Zerotorescue@0: function MailOpener:ShowBetaPopup() Zerotorescue@0: function TableDump(key, val, jumps) Zerotorescue@0: local cache = ""; Zerotorescue@0: Zerotorescue@0: if not jumps then Zerotorescue@0: jumps = 0; Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: local spacer = ""; Zerotorescue@0: if jumps > 0 then Zerotorescue@0: for i = 1, jumps do Zerotorescue@0: spacer = spacer .. " "; Zerotorescue@0: end Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: if type(val) == "table" then Zerotorescue@0: cache = cache .. spacer .. key .. " = {\n"; Zerotorescue@0: foreach(val, function(k, v) Zerotorescue@0: cache = cache .. TableDump(k, v, (jumps + 1)); Zerotorescue@0: end); Zerotorescue@0: cache = cache .. spacer .. "},\n"; Zerotorescue@0: else Zerotorescue@0: cache = cache .. spacer .. key .. " = " .. tostring(val) .. ",\n"; Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: return cache; Zerotorescue@0: end Zerotorescue@0: Zerotorescue@0: local cache = ""; Zerotorescue@0: foreach(MailOpener.db.profile, function(k, v) Zerotorescue@0: cache = cache .. TableDump(k, v, 0); Zerotorescue@0: end); Zerotorescue@0: Zerotorescue@0: local AceGUI = LibStub("AceGUI-3.0"); Zerotorescue@0: local frame = AceGUI:Create("Frame"); Zerotorescue@0: frame:SetTitle("Mail Opener ALPHA"); Zerotorescue@0: frame:SetWidth(575); Zerotorescue@0: frame:SetHeight(375); Zerotorescue@0: Zerotorescue@0: -- Add a normal description label Zerotorescue@0: local desc = AceGUI:Create("Label"); Zerotorescue@0: desc:SetText("|cff00ff00After you have been using Mail Opener for a while and configured it just as you want it to be, please report your favorite settings by copying the text below at either of the below links. Thanks in advance!|r\n\n"); Zerotorescue@0: desc:SetFont(GameFontHighlightSmall:GetFont(), 13); Zerotorescue@0: desc:SetFullWidth(true); Zerotorescue@0: frame:AddChild(desc); Zerotorescue@0: Zerotorescue@0: -- Add a MultiLineEditBox Zerotorescue@0: local settingsMLEEB = AceGUI:Create("MultiLineEditBox"); Zerotorescue@0: settingsMLEEB:SetText(cache); Zerotorescue@0: settingsMLEEB:SetLabel("Hit CTRL-A to select all and CTRL-C to copy the text. You can then use CTRL-V to paste."); Zerotorescue@0: settingsMLEEB:SetFullWidth(true); Zerotorescue@0: settingsMLEEB:SetNumLines(8); Zerotorescue@0: settingsMLEEB:DisableButton(true); Zerotorescue@0: settingsMLEEB:SetCallback("OnTextChanged", function() Zerotorescue@0: settingsMLEEB:SetText(cache); Zerotorescue@0: end); Zerotorescue@0: frame:AddChild(settingsMLEEB); Zerotorescue@0: Zerotorescue@0: -- Empty line between the two links Zerotorescue@0: local label = AceGUI:Create("Label"); Zerotorescue@0: label:SetText("Please post the above text at either of these two links:"); Zerotorescue@0: label:SetFullWidth(true); Zerotorescue@0: frame:AddChild(label); Zerotorescue@0: Zerotorescue@0: local desc1 = AceGUI:Create("InteractiveLabel"); Zerotorescue@0: desc1:SetText("|cff00bbbb[http://wow.curseforge.com/addons/mailopener/create-ticket/]|r"); Zerotorescue@0: desc1:SetFont(GameFontHighlightSmall:GetFont(), 13); Zerotorescue@0: desc1:SetFullWidth(true); Zerotorescue@0: desc1:SetCallback("OnClick", function() Zerotorescue@0: MailOpener.currentPopupContents = "http://wow.curseforge.com/addons/mailopener/create-ticket/"; Zerotorescue@0: Zerotorescue@0: StaticPopup_Show("MailOpenerCopyWindow"); Zerotorescue@0: end); Zerotorescue@0: desc1:SetCallback("OnEnter", function() Zerotorescue@0: frame:SetStatusText("Click to copy this URL."); Zerotorescue@0: end); Zerotorescue@0: desc1:SetCallback("OnLeave", function() Zerotorescue@0: frame:SetStatusText(""); Zerotorescue@0: end); Zerotorescue@0: frame:AddChild(desc1); Zerotorescue@0: Zerotorescue@0: -- Empty line between the two links Zerotorescue@0: local spacer = AceGUI:Create("Label"); Zerotorescue@0: spacer:SetText(" "); Zerotorescue@0: frame:AddChild(spacer); Zerotorescue@0: Zerotorescue@0: local desc2 = AceGUI:Create("InteractiveLabel"); Zerotorescue@0: desc2:SetText("|cff00bbbb[http://20kleveling.com/JMTCforum/posting.php?mode=reply&f=9&t=1403]|r"); Zerotorescue@0: desc2:SetFont(GameFontHighlightSmall:GetFont(), 13); Zerotorescue@0: desc2:SetFullWidth(true); Zerotorescue@0: desc2:SetCallback("OnClick", function() Zerotorescue@0: MailOpener.currentPopupContents = "http://20kleveling.com/JMTCforum/posting.php?mode=reply&f=9&t=1403"; Zerotorescue@0: Zerotorescue@0: StaticPopup_Show("MailOpenerCopyWindow"); Zerotorescue@0: end); Zerotorescue@0: desc2:SetCallback("OnEnter", function() Zerotorescue@0: frame:SetStatusText("Click to copy this URL."); Zerotorescue@0: end); Zerotorescue@0: desc2:SetCallback("OnLeave", function() Zerotorescue@0: frame:SetStatusText(""); Zerotorescue@0: end); Zerotorescue@0: frame:AddChild(desc2); Zerotorescue@0: Zerotorescue@0: -- Empty line between the two links Zerotorescue@0: local label = AceGUI:Create("Label"); Zerotorescue@0: label:SetText("\n\nps. You can always view this window again at a later time by clicking the \"Config\" button in the mail frame.\nps2. The information above is completely Mail Opener related. It will be used to determine the best default settings."); Zerotorescue@0: label:SetFullWidth(true); Zerotorescue@0: frame:AddChild(label); Zerotorescue@7: end Zerotorescue@7: ]]