📄 mailmonitor.lua
字号:
--[[ BeanCounter Addon for World of Warcraft(tm). Version: 3.5.0.0914 (Platypus) Revision: $Id: MailMonitor.lua 827 2006-04-18 07:42:44Z vindicator $ MailMonitor - Handles all mailbox interactions License: This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program(see GPL.txt); if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.--]]--------------------------------------------------------------------------------- Function Imports-------------------------------------------------------------------------------local chatPrint = BeanCounter.ChatPrint;local nilSafe = BeanCounter.NilSafe;--------------------------------------------------------------------------------- Function Prototypes-------------------------------------------------------------------------------local addTask;local processMailMessage;local isSenderAuctionHouse;local isSubjectAuctionExpired;local isSubjectAuctionCancelled;local isSubjectAuctionWon;local isSubjectAuctionSuccessful;local isSubjectOutbidOn;local getItemNameFromSubject;local reconcileDatabases;local debugPrint;local InboxTask_OnEvent;local InboxTask_OnUpdate;local InboxTask_Execute;local createWaitForInboxUpdateTask;local WaitForInboxUpdate_OnEvent;local createWaitForTakeInboxItem;local WaitForTakeInboxItem_OnEvent;local createWaitForTakeInboxMoney;local WaitForTakeInboxMoney_OnEvent;local createWaitForDeleteInboxItem;local WaitForDeleteInboxItem_OnEvent;local createWaitForInvoiceTask;local WaitForInvoiceTask_OnEvent;local WaitForInvoiceTask_OnUpdate;local createWaitForReadMessage;local WaitForReadMessage_OnEvent;local createProcessMessageTask;local ProcessMessageTask_Execute;local createTakeInboxMoneyTask;local TakeInboxMoneyTask_Execute;local createTakeInboxItemTask;local TakeInboxItemTask_Execute;--------------------------------------------------------------------------------- Constants-------------------------------------------------------------------------------local MAX_DAYS_LEFT = 30; -- Maximum number of days left for an unread message--------------------------------------------------------------------------------- Local variables-------------------------------------------------------------------------------local InboxTasks = {};local LastMailCount = 0;local MailDownloaded = false;local MailDownloadTime = nil;local MailBacklog = false;--------------------------------------------------------------------------------- Constants-------------------------------------------------------------------------------local MAX_INBOX_MESSAGES = 50;--------------------------------------------------------------------------------------------------------------------------------------------------------------function MailMonitor_OnLoad() -- Hook all the methods we need! Stubby.RegisterFunctionHook("TakeInboxItem", -100, MailMonitor_PreTakeInboxItemHook); Stubby.RegisterFunctionHook("TakeInboxMoney", -100, MailMonitor_PreTakeInboxMoneyHook); Stubby.RegisterFunctionHook("GetInboxText", -100, MailMonitor_PreGetInboxTextHook); Stubby.RegisterFunctionHook("GetInboxText", 100, MailMonitor_PostGetInboxTextHook); Stubby.RegisterFunctionHook("DeleteInboxItem", -100, MailMonitor_DeleteInboxItemHook); -- Register for the events we need! Stubby.RegisterEventHook("MAIL_INBOX_UPDATE", "BeanCounter_MailMonitor", MailMonitor_OnEventHook); Stubby.RegisterEventHook("UI_ERROR_MESSAGE", "BeanCounter_MailMonitor", MailMonitor_OnEventHook); Stubby.RegisterEventHook("MAIL_SHOW", "BeanCounter_MailMonitor", MailMonitor_OnEventHook); Stubby.RegisterEventHook("MAIL_CLOSED", "BeanCounter_MailMonitor", MailMonitor_OnEventHook);end--------------------------------------------------------------------------------------------------------------------------------------------------------------function MailMonitor_OnUpdate() -- Check if we satisfied an event task. if (table.getn(InboxTasks) > 0) then local task = InboxTasks[1]; table.remove(InboxTasks, 1); if (task:OnUpdate()) then debugPrint("Timed out event task: "..task.name); else table.insert(InboxTasks, 1, task); end end -- Check if we've got function tasks to perform. local executed = true; while (table.getn(InboxTasks) > 0 and executed) do local task = InboxTasks[1]; table.remove(InboxTasks, 1); executed = task:Execute(); if (executed) then debugPrint("Executed task: "..task.name); else table.insert(InboxTasks, 1, task); end endend--------------------------------------------------------------------------------------------------------------------------------------------------------------function MailMonitor_OnEventHook(_, event, arg1) debugPrint(event); -- Check if we satisfied an event task. if (table.getn(InboxTasks) > 0) then local task = InboxTasks[1]; table.remove(InboxTasks, 1); if (task:OnEvent(event, arg1)) then debugPrint("Satisfied event task: "..task.name); else table.insert(InboxTasks, 1, task); end end -- Check if we've got function tasks to perform. local executed = true; while (table.getn(InboxTasks) > 0 and executed) do local task = InboxTasks[1]; table.remove(InboxTasks, 1); executed = task:Execute(); if (executed) then debugPrint("Executed task: "..task.name); else table.insert(InboxTasks, 1, task); end end -- Reconcilation management. if (event == "MAIL_SHOW") then LastMailCount = GetInboxNumItems(); MailDownloaded = false; MailDownloadTime = nil; elseif (event == "MAIL_INBOX_UPDATE") then local count = GetInboxNumItems(); if (count > LastMailCount) then MailDownloaded = true; MailDownloadTime = time(); MailBacklog = (count == MAX_INBOX_MESSAGES); if (MailBacklog) then debugPrint("Mail downloaded from server at "..date("%c", MailDownloadTime).." ("..count.." messages - backlog)"); else debugPrint("Mail downloaded from server at "..date("%c", MailDownloadTime).." ("..count.." messages)"); end end LastMailCount = count; elseif (event == "MAIL_CLOSED") then if (MailDownloaded and MailDownloadTime ~= nil and not MailBacklog) then reconcileDatabases(MailDownloadTime); end MailDownloaded = false; MailDownloadTime = nil; endend--------------------------------------------------------------------------------- Hooks taking items from messages.-------------------------------------------------------------------------------function MailMonitor_PreTakeInboxItemHook(funcArgs, retVal, index) debugPrint("MailMonitor_PreTakeInboxItemHook("..nilSafe(index)..") called"); -- Allow this method call if there is no pending tasks. if (table.getn(InboxTasks) == 0) then if (index ~= nil and index > 0) then -- Read the message, before allowing the TakeInboxItem() call. local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, hasItem, wasRead, wasReturned, textCreated, canReply = GetInboxHeaderInfo(index); if (not wasRead and isSenderAuctionHouse(sender)) then GetInboxText(index); end -- If there are pending tasks, we must delay the execution of -- TakeInboxItem(). if (table.getn(InboxTasks) > 0) then -- Queue a task for taking the inbox item. addTask(createTakeInboxItemTask(index)); -- Abort the execution of TakeInboxItem() for now... debugPrint("Delaying TakeInboxItem() call"); return "abort"; else -- Wait for the item to be taken. addTask(createWaitForTakeInboxItem(index)); end end else debugPrint("Ignoring TakeInboxItem() call"); return "abort"; endend--------------------------------------------------------------------------------- Hooks taking money from messages.-------------------------------------------------------------------------------function MailMonitor_PreTakeInboxMoneyHook(funcArgs, retVal, index) debugPrint("MailMonitor_PreTakeInboxMoneyHook("..nilSafe(index)..") called"); -- Allow this method call if there is no pending action. if (table.getn(InboxTasks) == 0) then if (index ~= nil and index > 0) then -- Read the message, before allowing the TakeInboxMoney() call. local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, hasItem, wasRead, wasReturned, textCreated, canReply = GetInboxHeaderInfo(index); if (not wasRead and isSenderAuctionHouse(sender)) then GetInboxText(index); end -- If there are pending tasks, we must delay the execution of -- TakeInboxMoney(). if (table.getn(InboxTasks) > 0) then -- Queue a task for taking the inbox money. addTask(createTakeInboxMoneyTask(index)); -- Abort the execution of TakeInboxMoney() for now... debugPrint("Delaying TakeInboxMoney() call"); return "abort"; else -- Wait for the money to be taken. addTask(createWaitForTakeInboxMoney(index)); end end else debugPrint("Ignoring TakeInboxMoney() call"); return "abort"; endend--------------------------------------------------------------------------------- Hooks before reading a message.-------------------------------------------------------------------------------local getInboxTextRecursionLevel = 0;local messageWasRead = true;local messageDaysLeft = 0;function MailMonitor_PreGetInboxTextHook(funcArgs, retVal, index) debugPrint("MailMonitor_PreGetInboxTextHook("..nilSafe(index)..") called"); -- The GetInboxText is called re-entrantly in some cases. We only care -- about the first (outermost) call. getInboxTextRecursionLevel = getInboxTextRecursionLevel + 1; if (index > 0 and index <= GetInboxNumItems() and getInboxTextRecursionLevel == 1) then -- Check if we are reading the message for the first time. If so, this
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -