View Single Post
08-14-22, 03:36 PM   #8
myrroddin
A Pyroguard Emberseer
 
myrroddin's Avatar
AddOn Author - Click to view addons
Join Date: Oct 2008
Posts: 1,240
I rewrote this function, then saw your reply. I was about to test it, and if it still goes into an infinite loop, I don't know how to stop it, given the delay to the server and back.
Lua Code:
  1. function PriceAnswer:CHAT_MSG_WHISPER(event, ...)
  2.     -- stop listening to the event while we process the incoming message
  3.     self:UnregisterEvent("CHAT_MSG_WHISPER")
  4.    
  5.     local incomingMessage, senderName = ...
  6.     local outgoingMessageOne, outgoingMessageTwo = self:GetOutgoingMessage(incomingMessage) -- need to split returned prices into two; each message must be <= 255 characters
  7.     outgoingMessageOne = outgoingMessageOne or ""
  8.     outgoingMessageTwo = outgoingMessageTwo or ""
  9.  
  10.     -- stop possible infinite loops
  11.     if outgoingMessageOne == incomingMessage then
  12.         self:RegisterEvent("CHAT_MSG_WHISPER")
  13.         return
  14.     end
  15.     if outgoingMessageTwo == incomingMessage then
  16.         self:RegisterEvent("CHAT_MSG_WHISPER")
  17.         return
  18.     end
  19.  
  20.     -- debug prints
  21.     self:Print("Outgoing message one", outgoingMessageOne == "" and UNKNOWN or outgoingMessageOne)
  22.     self:Print("Outgoing message two", outgoingMessageTwo == "" and UNKNOWN or outgoingMessageTwo)
  23.  
  24.     if outgoingMessageOne ~= "" then
  25.         SendChatMessage(outgoingMessageOne, "WHISPER", nil, senderName)
  26.     end
  27.     if outgoingMessageTwo ~= "" then
  28.         SendChatMessage(outgoingMessageTwo, "WHISPER", nil, senderName)
  29.     end
  30.  
  31.     if outgoingMessageOne == "" and outgoingMessageTwo == "" then
  32.         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)
  33.     end
  34.  
  35.     -- we are done processing the incoming message, listen to the  event again
  36.     self:RegisterEvent("CHAT_MSG_WHISPER")
  37. end
And Dridzt was correct about hidden control strings. I had to write my own function, as I couldn't gsub things in TSM I don't know about. Writing my own function was a simpler solution.
Lua Code:
  1. -- TradeSkillMaster has some weird control characters in TSM_API.FormatMoneyString, build our own version
  2. function PriceAnswer:ConvertToHumanReadable(num_copper)
  3.     local gold_string, silver_string, copper_string = "", "", ""
  4.     local gold, silver, copper
  5.     if num_copper > 0 then
  6.         gold = floor(num_copper / 10000)
  7.         if gold >= 1 then
  8.             gold_string = format("%d" .. L["g"], gold)
  9.         end
  10.         silver = (num_copper / 100) % 100
  11.         if silver >= 1 then
  12.             silver_string = format("%d" .. L["s"], silver)
  13.         end
  14.         copper = num_copper % 100
  15.         if copper >= 1 then
  16.             copper_string = format("%d" .. L["c"], copper)
  17.         end
  18.         return gold_string .. silver_string .. copper_string
  19.     end
  20.     return nil
  21. end
  Reply With Quote