LenweSaralonde / MessageQueue

Implements an alternative to SendChatMessage() to securely send messages in chat channels in response to a hardware event.
GNU General Public License v3.0
2 stars 1 forks source link

Spammed message if user is afk for a while and no auto-trigger is used #2

Closed Rdyx closed 2 years ago

Rdyx commented 2 years ago

Happened to some friends of mine, I'm using a custom WA to trigger auto-message and got the same case. After some AFK time and no "auto-trigger" (i.e AutoHotKey) is used, channels are kinda flooded.

Here is a quick suggestion and edition to let user purge the queue by himself if he needs to do it

--- Allow manual queue purging and retrieve only first queue element to send
-- i.e: avoid spamming if too many messages have been enqueued due to AFK
-- and no auto-trigger system is used
MessageQueue.Purge = function()
    queue = {queue[1]}
end

Thanks for your addon btw, great workaround ;D

Edit: maybe we are missusing MessageQueue functions though. Case seems to happens when we call MessageQueue.SendChatMessage(), should we use MessageQueue.Run() instead to avoid fire all messages at once? I have to say I'm not using AutoFlood so I'm not sure how everything is interacting over here.

LenweSaralonde commented 2 years ago

MessageQueue.SendChatMessage() adds a message to the queue and MessageQueue.Run() is called when a hardware event is received (ie click, keystroke etc). MessageQueue.Run() runs all the queue at once so if you have enqueued like 10 messages, they will be sent all at once.

You could modify your WA script so it doesn't call MessageQueue.SendChatMessage() when you're AFK or if there are already too much messages in the queue (use MessageQueue.GetNumPendingMessages()).

Rdyx commented 2 years ago

Yeah that's the whole point of allowing user to call a "purge" function to avoid sending 10 messages at once like I've seen on /world already haha ^^

I see your point with WA modification about not sending messages if AFK (which is a bit tricky to implement imo) but wouldn't the other point somehow "break" your work? I mean, if the queue reach a determined size and MessageQueue is not allowed to send messages because of queue length, doesn't it mean it would not send any other message untill user /reload or relog?

Allowing user to purge the queue would then allow MessageQueue to send messages again since queue should be "fresh" by being composed of only 1 element

LenweSaralonde commented 2 years ago

Alternately, if your WA sends messages periodically, you could change it to send the next message after the current one has been actually sent using the callback, something like that :

local periodicalMessageTimer
local isSendingPeriodicalMessage

function sendPeriodicalMessage(period, msg, chatType, languageID, target)
    stopPeriodicalMessage()
    isSendingPeriodicalMessage = true
    MessageQueue.SendChatMessage(msg, chatType, languageID, target, function()
        if not isSendingPeriodicalMessage then return end
        periodicalMessageTimer = C_Timer.NewTimer(period, function()
            sendPeriodicalMessage(period, msg, chatType, languageID, target)
        end)
    end)
end

function stopPeriodicalMessage()
    isSendingPeriodicalMessage = false
    if periodicalMessageTimer then
        periodicalMessageTimer:Cancel()
    end
end