WoW:Hooking outgoing chat messages: Difference between revisions

m
Move page script moved page Hooking outgoing chat messages to WoW:Hooking outgoing chat messages without leaving a redirect
No edit summary
 
m (Move page script moved page Hooking outgoing chat messages to WoW:Hooking outgoing chat messages without leaving a redirect)
 
(3 intermediate revisions by 3 users not shown)
Line 1: Line 1:
To modify outgoing chat messages we are going to hook the ChatEdit_ParseText function.
To modify outgoing chat messages we are going to hook the ChatEdit_ParseText function. However, this function also handles macros; so to avoid tainting we must use [[API_hooksecurefunc|hooksecurefunc]]() to hook the function properly. Otherwise, your macros will no longer work.


You probably want to do this in an OnLoad function. Sea screws up the normal function hooking process, so you need to do it differently depending on whether Sea is installed or not.
  -- Place this code in the OnLoad function of your addon
   -- Make these variable global to the whole lua file
   hooksecurefunc('ChatEdit_ParseText',MyAddon_ParseText);
  local oldChatEdit_ParseText;
  local seaPresent = (Sea ~= nil);


  -- Place this code in the OnLoad function
MyAddon_ParseText will now be called after ChatEdit_ParseText has had a chance to handle macros and slash commands.
  if (seaPresent) then
      Sea.util.hook("ChatEdit_ParseText","My_ParseText","after");
  else
      oldChatEdit_ParseText = ChatEdit_ParseText;
      ChatEdit_ParseText = My_ParseText;
  end;


My_ParseTest is going to get called now instead of ChatEdit_ParseText. It should look something like:
   function MyAddon_ParseText(chatEntry, send)
 
   function My_ParseText(chatEntry, send)
      -- if Sea is not installed, call the original function first. If Sea
      -- is installed it does this step for you. The original function will
      -- process any slash commands for you, so all that's left is chat messages
      if (~seaPresent) then
        oldChatEdit_ParseText(chatEntry, send);
      end
      --
       -- This function actually gets called every time the user hits a key. But the
       -- This function actually gets called every time the user hits a key. But the
       -- send flag will only be set when he hits return to send the message.
       -- send flag will only be set when he hits return to send the message.
Line 32: Line 15:
       end
       end
   end
   end
[[Category:HOWTOs|Hook Outgoing Chat Messages]]
Anonymous user