-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMessageManager.lua
More file actions
57 lines (45 loc) · 2.25 KB
/
MessageManager.lua
File metadata and controls
57 lines (45 loc) · 2.25 KB
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
AutoBiographer_MessageManager = {
AddonMessagePrefix = "AutoBiographer",
SentMessageTimestamps = {},
}
local MM = AutoBiographer_MessageManager
local AceComm = LibStub:GetLibrary("AceComm-3.0")
local LibSerialize = LibStub("LibSerialize")
local LibDeflate = LibStub("LibDeflate")
function MM.OnAddonMessageReceived(prefix, text, channel, sender, target, zoneChannelID, localID, name, instanceID)
--print(string.format("%s, %s, %s, %s", prefix, text, channel, sender))
if (channel ~= "GUILD") then return end
local decoded = LibDeflate:DecodeForWoWAddonChannel(text)
if (not decoded) then return end
local decompressed = LibDeflate:DecompressDeflate(decoded)
if (not decompressed) then return end
local success, message = LibSerialize:Deserialize(decompressed)
if (not success) then return end
local addonMessageType, arg1 = strsplit("!", message, 2)
addonMessageType = tonumber(addonMessageType)
if (addonMessageType == AutoBiographerEnum.AddonMessageType.CustomEvent) then
if (AutoBiographer_Settings.Options["EnableCustomEventSharing"]) then
local playerName = sender
if (UnitName("player") == sender) then playerName = "You" end
print("\124cFFFFD700[AutoBiographer] " .. tostring(playerName) .. " shared the following event: \"" .. HelperFunctions.ShortenString(arg1, 500) .. "\"")
elseif (UnitName("player") == sender) then
print("\124cFFFF0000[AutoBiographer] You shared a custom event, but you haven't enabled the option for guild members to share custom events with you.")
end
end
end
function MM.SendAddonMessage(addonMessageType, arg1)
local nowTimestamp = GetTime()
if (MM.SentMessageTimestamps[addonMessageType] and nowTimestamp - MM.SentMessageTimestamps[addonMessageType] < 10) then
print("\124cFFFF0000[AutoBiographer] Message not sent, you are sending messages too quickly.")
return
end
MM.SentMessageTimestamps[addonMessageType] = nowTimestamp
local message = addonMessageType
if (arg1 ~= nil) then
message = message .. "!" .. arg1
end
local serialized = LibSerialize:Serialize(message)
local compressed = LibDeflate:CompressDeflate(serialized)
local encoded = LibDeflate:EncodeForWoWAddonChannel(compressed)
AceComm:SendCommMessage(MM.AddonMessagePrefix, encoded, "GUILD")
end