View Single Post
08-14-22, 10:23 PM   #10
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
To prevent the infinite loop when testing, hook SendChatMessage, save every message you send in a table, then bail out of processing when the event gets those messages. There's a simple trick to figure out if you're the one that used a hooked function with an "unused" argument.

Lua Code:
  1. --the tracking table
  2.  
  3. PriceAnswerSentMessages={}
  4.  
  5. --the hook
  6.  
  7. hooksecurefunc("SendChatMessage",function(message,_,_,_,_,_,_,mine)
  8.     if mine then
  9.         PriceAnswerSentMessages[message]=1
  10.     end
  11. end)
  12.  
  13. --then put this in PriceAnswer:CHAT_MSG_WHISPER()
  14.  
  15. if PriceAnswerSentMessages[incomingMessage] then return end
  16.  
  17. --finally, add some nils and a true to SendChatMessage
  18.  
  19. if outgoingMessageOne ~= "" then
  20.     SendChatMessage(outgoingMessageOne, "WHISPER", nil, senderName, nil, nil, nil, true)
  21. end
  22. if outgoingMessageTwo ~= "" then
  23.     SendChatMessage(outgoingMessageTwo, "WHISPER", nil, senderName, nil, nil, nil, true)
  24. end
  25.  
  26. if outgoingMessageOne == "" and outgoingMessageTwo == "" then
  27.     SendChatMessage(format(L["Syntax: '%s N item' without quotes, N is an optional quantity, default 1, item is an item link or itemID"], L[db.trigger]), "WHISPER", nil, senderName, nil, nil, nil, true)
  28. end


As for the control characters, there's an obscure function in the UI code that I believe strips them:

message = SubstituteChatMessageBeforeSend(message)

There's no documentation for it though.
  Reply With Quote