-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMailer.lua
103 lines (80 loc) · 2.4 KB
/
Mailer.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
local f = CreateFrame("Frame")
local mailerArgs={}
local invToSend={}
local dbg=false
f:RegisterEvent("MAIL_FAILED")
f:RegisterEvent("MAIL_SHOW")
f:RegisterEvent("MAIL_CLOSED")
f:SetScript("OnEvent", function(self,event, ...)
if (event == "BAG_UPDATE_DELAYED") then
debugPrint("message handler after mail send success")
SendItems()
end
if (event == "MAIL_FAILED") then
debugPrint("Mail failed")
end
if (event == "MAIL_CLOSED") then
debugPrint("mail frame closed, removing event listener")
f:UnregisterEvent("BAG_UPDATE_DELAYED")
end
if (event == "MAIL_SHOW") then
debugPrint("mail frame opened, listening for MAIL_SEND_SUCCESS event")
f:RegisterEvent("BAG_UPDATE_DELAYED")
end
end)
local function LaunchMailer(msg)
mailerArgs={}
for str in string.gmatch(msg, "([^%s]+)") do
table.insert(mailerArgs, str)
end
if (#mailerArgs == 0 or mailerArgs[1] == "help") then
print("To send something, type /mailer recipientName itemId itemRarity")
print("Example: /mailer Leeroy 171267 1")
print("Common=1 Uncommon=2 Rare=3 Epic=4 Legendary=5")
return
end
debugPrint("Mailing target is " .. mailerArgs[1]);
debugPrint("ItemID target is " .. mailerArgs[2]);
debugPrint("Rarity target is " .. mailerArgs[3]);
GetItemsToSend()
SendItems()
end
function GetItemsToSend()
invToSend={}
for i=0,4 do
for j=1,C_Container.GetContainerNumSlots(i) do
local item = C_Container.GetContainerItemInfo(i,j);
if (item ~= nil and item.isLocked == false and item.quality == tonumber(mailerArgs[3]) and item.itemID == tonumber(mailerArgs[2])) then
debugPrint({i,j})
table.insert(invToSend, {i,j})
end
end
end
end
function SendItems()
if next(invToSend) then
local count=0;
for k, v in pairs(invToSend) do
count = count + 1;
C_Container.PickupContainerItem(v[1],v[2]);
ClickSendMailItemButton(count);
invToSend[k] = nil
if (count == 12) then
debugPrint("sending full mail")
SendMail(mailerArgs[1], "Mailer sending stuff", "");
break;
end
end
if (count ~= 12) and (count ~= 0) then
debugPrint("sending partial mail")
SendMail(mailerArgs[1], "Mailer sending stuff", "");
end
end
end
function debugPrint(msg)
if (dbg==true) then
print(msg)
end
end
SLASH_MAILER1, SLASH_MAILER2 = "/mailer", "/am"
SlashCmdList["MAILER"] = LaunchMailer