- switching to new C_AddOns API changes
- cascaded message hooking for Retail v12 engine - messages during encounters are sent unchanged, with a one-time notice - ignore numbered chats that do not exist - /r no longer sends to an empty whisper target if the last told target is unavailable - fixed replacements in instance chats - messages to unknown numbered channels are now discarded - right-click on the minimap button
This commit is contained in:
+87
-10
@@ -2,8 +2,8 @@
|
||||
local _G = _G or getfenv()
|
||||
local Grichelde = _G.Grichelde or {}
|
||||
|
||||
local IsAddOnLoaded, assert, nilOrEmpty, pairs, ipairs, spairs, tContains, tFilter, tInsert, tIsEmpty, tSize, find, sub, gsub, getNextCharUtf8, isUtf8MultiByte, getUtf8Sequence, isUpper, isLower, toUpper, toLower, bytes2Char, trim, length, lengthUtf8
|
||||
= Grichelde.F.IsAddOnLoaded, Grichelde.F.assert, Grichelde.F.nilOrEmpty, Grichelde.F.pairs, Grichelde.F.ipairs, Grichelde.F.spairs, Grichelde.F.tContains, Grichelde.F.tFilter, Grichelde.F.tInsert, Grichelde.F.tIsEmpty, Grichelde.F.tSize,
|
||||
local assert, nilOrEmpty, pairs, ipairs, spairs, tContains, tFilter, tInsert, tIsEmpty, tSize, find, sub, gsub, getNextCharUtf8, isUtf8MultiByte, getUtf8Sequence, isUpper, isLower, toUpper, toLower, bytes2Char, trim, length, lengthUtf8
|
||||
= Grichelde.F.assert, Grichelde.F.nilOrEmpty, Grichelde.F.pairs, Grichelde.F.ipairs, Grichelde.F.spairs, Grichelde.F.tContains, Grichelde.F.tFilter, Grichelde.F.tInsert, Grichelde.F.tIsEmpty, Grichelde.F.tSize,
|
||||
Grichelde.F.find, Grichelde.F.sub, Grichelde.F.gsub, Grichelde.F.getNextCharUtf8, Grichelde.F.isUtf8MultiByte, Grichelde.F.getUtf8Sequence, Grichelde.F.isUpper, Grichelde.F.isLower, Grichelde.F.toUpper, Grichelde.F.toLower, Grichelde.F.bytes2Char, Grichelde.F.trim, Grichelde.F.length, Grichelde.F.lengthUtf8
|
||||
|
||||
--- Splits a long text in longest possible chunks of <= 255 length, split at last available space
|
||||
@@ -145,10 +145,10 @@ function Grichelde:SendChunkifiedChatMessage(message, ...)
|
||||
self:DebugPrint("SendChunkifiedChatMessage : #chunks:", tSize(chunks))
|
||||
|
||||
for _, chunk in ipairs(chunks) do
|
||||
self.hooks["SendChatMessage"](chunk, ...);
|
||||
self:SendOriginal(chunk, ...)
|
||||
end
|
||||
else
|
||||
self.hooks["SendChatMessage"](message, ...);
|
||||
self:SendOriginal(message, ...)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -886,8 +886,18 @@ function Grichelde:CheckAndExtractMessageTypeTarget(message)
|
||||
-- special reply handling
|
||||
if ("/r" == chatCmd) or ("/reply" == chatCmd) then
|
||||
-- reuse last type and target if possible
|
||||
local lastTold, lastToldType = ChatEdit_GetLastToldTarget()
|
||||
-- TODO: add the Retail 12.x replacement of ChatEdit_GetLastToldTarget once confirmed in-game
|
||||
local lastTold, lastToldType
|
||||
if (_G.ChatEdit_GetLastToldTarget ~= nil) then
|
||||
lastTold, lastToldType = _G.ChatEdit_GetLastToldTarget()
|
||||
end
|
||||
self:DebugPrint("CheckAndExtractMessageTypeTarget : lastTell, lastTellType =", lastTold, lastToldType)
|
||||
|
||||
if (nilOrEmpty(lastTold)) then
|
||||
self:ErrorPrint(self.L.Error_InvalidWhisperTarget)
|
||||
-- dont send text at all
|
||||
return nil
|
||||
end
|
||||
return targetAndText, lastToldType or "WHISPER", lastTold
|
||||
elseif ("/tt" == chatCmd) then
|
||||
-- determine target from game world selection
|
||||
@@ -931,7 +941,7 @@ function Grichelde:CheckAndExtractMessageTypeTarget(message)
|
||||
local _, _, channelNumber = find(chatCmd, "^/(%d+)")
|
||||
if (channelNumber ~= nil) then
|
||||
local channelId = GetChannelName(channelNumber)
|
||||
if (channelId ~= nil) then
|
||||
if (channelId ~= nil) and (channelId > 0) then
|
||||
return targetAndText, "CHANNEL", channelId
|
||||
end
|
||||
end
|
||||
@@ -950,8 +960,50 @@ function Grichelde:CheckAndExtractMessageTypeTarget(message)
|
||||
end
|
||||
end
|
||||
|
||||
--- Hooks C_ChatInfo.SendChatMessage (Retail) and the global SendChatMessage (Classic, deprecated alias on Retail).
|
||||
--- The original C_ChatInfo function is preferred for sending.
|
||||
function Grichelde:HookSendChatMessage()
|
||||
local chatInfo = _G.C_ChatInfo
|
||||
if (chatInfo ~= nil) and (chatInfo.SendChatMessage ~= nil) then
|
||||
self:RawHook(chatInfo, "SendChatMessage", "SendChatMessage", true)
|
||||
self.originalSend = self.hooks[chatInfo]["SendChatMessage"]
|
||||
end
|
||||
|
||||
if (_G.SendChatMessage ~= nil) then
|
||||
self:RawHook("SendChatMessage", true)
|
||||
self.originalSend = self.originalSend or self.hooks["SendChatMessage"]
|
||||
end
|
||||
end
|
||||
|
||||
--- Sends a message with the original (unhooked) send function.
|
||||
function Grichelde:SendOriginal(...)
|
||||
return self.originalSend(...)
|
||||
end
|
||||
|
||||
--- Midnight blocks chat modifications by addons during instance encounters.
|
||||
--- Prints a notice once per lockdown.
|
||||
-- @return boolean
|
||||
function Grichelde:IsChatLockedDown()
|
||||
local chatInfo = _G.C_ChatInfo
|
||||
if (chatInfo == nil) or (chatInfo.InChatMessagingLockdown == nil) then
|
||||
return false
|
||||
end
|
||||
|
||||
if (chatInfo.InChatMessagingLockdown()) then
|
||||
if (not self.lockdownNoticeShown) then
|
||||
self.lockdownNoticeShown = true
|
||||
self:PrefixedPrint(self.L.Chat_Lockdown_Notice)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
self.lockdownNoticeShown = false
|
||||
return false
|
||||
end
|
||||
|
||||
function Grichelde:CleanseMessage(message)
|
||||
local text = message or ""
|
||||
local IsAddOnLoaded = (_G.C_AddOns and _G.C_AddOns.IsAddOnLoaded) or _G.IsAddOnLoaded
|
||||
if (IsAddOnLoaded("Misspelled")) then
|
||||
self:DebugPrint("Misspelled detected: cleansing message")
|
||||
text = _G.Misspelled:RemoveHighlighting(message)
|
||||
@@ -971,7 +1023,12 @@ function Grichelde:SendChatMessageOverride(message, ...)
|
||||
local msg, type, chan = self:CheckAndExtractMessageTypeTarget(cleasendText)
|
||||
|
||||
if (msg ~= nil) then
|
||||
msg = self:ReplaceText(msg)
|
||||
if (not self:IsChatLockedDown()) then
|
||||
msg = self:ReplaceText(msg)
|
||||
else
|
||||
-- do not modify message in any way during encounters
|
||||
-- msg = msg .. self.L.Chat_Lockdown_Suffix
|
||||
end
|
||||
|
||||
if (type ~= nil) then
|
||||
self:SendChunkifiedChatMessage(msg, type, fallbackLang, chan, ...)
|
||||
@@ -989,19 +1046,39 @@ end
|
||||
-- @param language string
|
||||
-- @param channel string
|
||||
function Grichelde:SendChatMessage(message, type, ...)
|
||||
if (self.isReplacing) then
|
||||
-- re-entered through the other hooked send function, text is already replaced
|
||||
self:DebugPrint("SendChatMessage : already replacing")
|
||||
self:SendOriginal(message, type, ...)
|
||||
return
|
||||
end
|
||||
|
||||
self.isReplacing = true
|
||||
-- always reset the guard, even if replacing fails
|
||||
local ok, err = pcall(self.ReplaceAndSendChatMessage, self, message, type, ...)
|
||||
self.isReplacing = false
|
||||
if (not ok) then
|
||||
error(err, 0)
|
||||
end
|
||||
end
|
||||
|
||||
function Grichelde:ReplaceAndSendChatMessage(message, type, ...)
|
||||
if (not self.db.profile.enabled) then
|
||||
self:DebugPrint("SendChatMessage : disabled")
|
||||
self.hooks["SendChatMessage"](message, type, ...);
|
||||
self:SendOriginal(message, type, ...)
|
||||
elseif (nilOrEmpty(message)) then
|
||||
self:DebugPrint("SendChatMessage : no text")
|
||||
self.hooks["SendChatMessage"](message, type, ...);
|
||||
self:SendOriginal(message, type, ...)
|
||||
elseif (self:IsChatLockedDown()) then
|
||||
self:DebugPrint("SendChatMessage : chat lockdown")
|
||||
self:SendOriginal(message, type, ...)
|
||||
else
|
||||
local cleasendText = self:CleanseMessage(message)
|
||||
if (self:CheckReplacementAllowed(cleasendText, type)) then
|
||||
cleasendText = self:ReplaceText(cleasendText)
|
||||
self:SendChunkifiedChatMessage(cleasendText, type, ...)
|
||||
else
|
||||
self.hooks["SendChatMessage"](message, type, ...);
|
||||
self:SendOriginal(message, type, ...)
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user