Thread Tools Display Modes
03-14-23, 02:28 AM   #1
nancey
A Kobold Labourer
Join Date: Mar 2023
Posts: 1
Intercept outgoing chatmessages

Hi

Due to a 10 day ban I just got for saying "idiot" I've decided to create a simple addon to filter out the word "idiot".. yes I could just not say it, but solo shuffles.. man..


So far I've figured out (I think) that i want to intercept the event CHAT_MESSAGE_SAY
this is where google stops helping me, so any suggestions on how i either change the "msg" of the event or cancels the event and fires a new one with the edited text?

Code:
print("Outgoing Mature Language Filter Loaded")

local f=CreateFrame("Frame");-- Need a frame to capture events
f:RegisterEvent("CHAT_MSG_SAY");-- Register our event
f:SetScript("OnEvent",function(self,event,msg)-- OnEvent handler receives event triggers
	if event=="CHAT_MSG_SAY" and msg:match("idiot") then-- Someone sends "hello World" in /say
		
		-- somehow set msg to something else, prevent default event and fire new sendmessage

	end
end);
  Reply With Quote
03-15-23, 04:59 AM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,308
By the time CHAT_MSG_SAY fires, the message had already been sent to the server. The event is responding to the server saying your message was sent and is an echo. What you'll need to do is replace SendChatMessage() with a function that does a replacement or blocks the message, then calls the original function if necessary.

Lua Code:
  1. local _SendChatMessage=SendChatMessage;--   Save a reference to the original function
  2. function SendChatMessage(message,...)-- We don't care what the rest of the args are, we just need to pass them on
  3.     _SendChatMessage(message:gsub("idiot","moron"),...);--  Replace instances of "idiot" with "moron"
  4. end

I get the sense that the nature of the ban is due to toxicity rather than the language of the message itself. That being said, it would be easy to modify this to just block the message from going out.

Lua Code:
  1. local _SendChatMessage=SendChatMessage;--   Save a reference to the original function
  2. function SendChatMessage(message,...)-- We don't care what the rest of the args are, we just need to pass them on
  3.     if not message:find("idiot") then-- Block sending message if it contains "idiot"
  4.         _SendChatMessage(message,...);
  5.     end
  6. end
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 03-15-23 at 05:05 AM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » Intercept outgoing chatmessages

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off