-
Notifications
You must be signed in to change notification settings - Fork 0
/
SilenceBanLu.lua
130 lines (114 loc) · 4.27 KB
/
SilenceBanLu.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
local addonName = ...
-- globals
local CreateFrame, C_ChatBubbles, UnitClassBase, C_AddOns, UnitName, MuteSoundFile, ChatFrame_AddMessageEventFilter, WorldFrame = CreateFrame, C_ChatBubbles, UnitClassBase, C_AddOns, UnitName, MuteSoundFile, ChatFrame_AddMessageEventFilter, WorldFrame
-- disable the addon for non-Monk players
if UnitClassBase("player") ~= "MONK" then
C_AddOns.DisableAddOn(addonName, UnitName("player"))
return
end
-- mute Ban-Lu's sound files
MuteSoundFile(1593212)
MuteSoundFile(1593213)
MuteSoundFile(1593214)
MuteSoundFile(1593215)
MuteSoundFile(1593216)
MuteSoundFile(1593217)
MuteSoundFile(1593218)
MuteSoundFile(1593219)
MuteSoundFile(1593220)
MuteSoundFile(1593221)
MuteSoundFile(1593222)
MuteSoundFile(1593223)
MuteSoundFile(1593224)
MuteSoundFile(1593225)
MuteSoundFile(1593226)
MuteSoundFile(1593227)
MuteSoundFile(1593228)
MuteSoundFile(1593229)
MuteSoundFile(1593236)
-- things Ban-Lu says
local banLuMessages = {}
-- returns the text contained within a currently displayed chat bubble
local function getChatBubbleText(chatBubble)
-- get chat bubble frame
local chatBubbleFrame = chatBubble:GetChildren()
for i = 1, chatBubbleFrame:GetNumRegions() do
local region = select(i, chatBubbleFrame:GetRegions())
-- only the bubble region with text will have ObjectType == FontString
if region:GetObjectType() == "FontString" then
return region:GetText()
end
end
end
-- check an individual bubble to see if Ban-Lu is talking
local function checkChatBubble(chatBubble)
local message = getChatBubbleText(chatBubble)
-- only Ban-Lu's messages will be in this table (author will always be Ban-Lu)
local author = banLuMessages[message]
if author == "Ban-Lu" and not chatBubble.banlu then
-- this bubble isn't hidden already, and Ban-Lu said the line contained within, hide the frame
local chatBubbleFrame = select(1, chatBubble:GetChildren())
chatBubbleFrame:Hide()
chatBubble.banlu = true
elseif author ~= "Ban-Lu" and chatBubble.banlu then
-- the author is not Ban-Lu but the frame is hidden, show the frame
local chatBubbleFrame = select(1, chatBubble:GetChildren())
chatBubbleFrame:Show()
chatBubble.banlu = nil
end
end
-- iterate through all bubbles we're allowed to modify and check each one
local function checkChatBubbles(chatBubbles)
for _, chatBubble in pairs(chatBubbles) do
if not chatBubble:IsForbidden() then
checkChatBubble(chatBubble)
end
end
end
-- a Frame to watch speech bubbles and hide anything said by Ban-Lu
local BubbleWatcher = CreateFrame("Frame", nil, WorldFrame)
BubbleWatcher:SetFrameStrata("TOOLTIP")
-- function to reset the watcher
BubbleWatcher.Reset = function(self)
self:Hide()
self.elapsed = 0
end
-- init
BubbleWatcher:Reset()
-- timer function to check the bubbles
BubbleWatcher:SetScript("OnUpdate", function(self, elapsed)
self.elapsed = self.elapsed + elapsed
-- have to wait because bubbles show up the frame after the chat event
if self.elapsed > 0.01 then
self:Reset()
checkChatBubbles(C_ChatBubbles:GetAllChatBubbles())
end
end)
-- filter Ban-Lu's spam from chat, and any chat bubbles he might produce
local function maybeBanLuFilter(_, _, message, author, ...)
if author == "Ban-Lu" then
banLuMessages[message] = author
BubbleWatcher:Show()
-- returning true filters the message from chat
return true
end
-- a monster who isn't Ban-Lu is talking
banLuMessages[message] = nil
BubbleWatcher:Show()
return false, message, author, ...
end
-- Ban-Lu is a monster so he talks in MONSTER_SAY
ChatFrame_AddMessageEventFilter("CHAT_MSG_MONSTER_SAY", maybeBanLuFilter)
-- we have to make sure to force show all chat bubbles that aren't Ban-Lu
-- previous chat bubbles get re-used for new chats and they retain their state
local function notBanLuFilter(_, _, message, ...)
-- nil out any table entry for this message, in case someone who isn't Ban-Lu wants to say one of his lines, I guess... lol
banLuMessages[message] = nil
BubbleWatcher:Show()
return false, message, ...
end
-- the chat events which can create bubbles which are guaranteed not to be Ban-Lu
ChatFrame_AddMessageEventFilter("CHAT_MSG_SAY", notBanLuFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_PARTY", notBanLuFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_YELL", notBanLuFilter)
ChatFrame_AddMessageEventFilter("CHAT_MSG_MONSTER_YELL", notBanLuFilter)