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:
function PriceAnswer:CHAT_MSG_WHISPER(event, ...)
-- stop listening to the event while we process the incoming message
self:UnregisterEvent("CHAT_MSG_WHISPER")
local incomingMessage, senderName = ...
local outgoingMessageOne, outgoingMessageTwo = self:GetOutgoingMessage(incomingMessage) -- need to split returned prices into two; each message must be <= 255 characters
outgoingMessageOne = outgoingMessageOne or ""
outgoingMessageTwo = outgoingMessageTwo or ""
-- stop possible infinite loops
if outgoingMessageOne == incomingMessage then
self:RegisterEvent("CHAT_MSG_WHISPER")
return
end
if outgoingMessageTwo == incomingMessage then
self:RegisterEvent("CHAT_MSG_WHISPER")
return
end
-- debug prints
self:Print("Outgoing message one", outgoingMessageOne == "" and UNKNOWN or outgoingMessageOne)
self:Print("Outgoing message two", outgoingMessageTwo == "" and UNKNOWN or outgoingMessageTwo)
if outgoingMessageOne ~= "" then
SendChatMessage(outgoingMessageOne, "WHISPER", nil, senderName)
end
if outgoingMessageTwo ~= "" then
SendChatMessage(outgoingMessageTwo, "WHISPER", nil, senderName)
end
if outgoingMessageOne == "" and outgoingMessageTwo == "" then
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)
end
-- we are done processing the incoming message, listen to the event again
self:RegisterEvent("CHAT_MSG_WHISPER")
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:
-- TradeSkillMaster has some weird control characters in TSM_API.FormatMoneyString, build our own version
function PriceAnswer:ConvertToHumanReadable(num_copper)
local gold_string, silver_string, copper_string = "", "", ""
local gold, silver, copper
if num_copper > 0 then
gold = floor(num_copper / 10000)
if gold >= 1 then
gold_string = format("%d" .. L["g"], gold)
end
silver = (num_copper / 100) % 100
if silver >= 1 then
silver_string = format("%d" .. L["s"], silver)
end
copper = num_copper % 100
if copper >= 1 then
copper_string = format("%d" .. L["c"], copper)
end
return gold_string .. silver_string .. copper_string
end
return nil
end