Skip to content

Commit

Permalink
Update formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ntowle committed Nov 9, 2023
1 parent 3d89064 commit dcddc39
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 52 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
104 changes: 52 additions & 52 deletions SilenceBanLu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ local CreateFrame, C_ChatBubbles, UnitClass, C_AddOns, MuteSoundFile, ChatFrame_

-- disable the addon for non-Monk players
if select(2, UnitClass('player')) ~= "MONK" then
C_AddOns.DisableAddOn("SilenceBanLu")
return
C_AddOns.DisableAddOn("SilenceBanLu")
return
end

-- mute Ban-Lu's sound files
Expand Down Expand Up @@ -33,80 +33,80 @@ local banLuMessages = {}

-- returns the text contained within a currently displayed chat bubble
local function getChatBubbleText(chatBubble)
-- get chat bubble frame
local chatBubbleFrame = select(1, 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
-- get chat bubble frame
local chatBubbleFrame = select(1, 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)
local message = getChatBubbleText(chatBubble)

-- only Ban-Lu's messages will be in this table (author will always be Ban-Lu)
local author = banLuMessages[message]
-- 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
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
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
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
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
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, ...
-- 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
Expand All @@ -115,10 +115,10 @@ 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, ...
-- 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
Expand Down

0 comments on commit dcddc39

Please sign in to comment.