Batch multi-line command responses when sending to Discord
Ricket opened this issue ยท 1 comments
Base informations
Minecraft version: 1.12.2
DiscordIntegration version: 3.0.4
Add a !help
command mapping to /help
, and chat it in Discord.
Expected behavior
Discord bot sends back one message, which has multiple lines, with the first page of help entries.
Actual behavior
Discord bot sends one message per line. The bot messages actually get rate limited, so only the first few come through, and then the rest come after several seconds of delay. Users get spammed with notifications, and the lines of text might interleave with another chat message.
Steps to reproduce
- add a "help" command
- run it
- observe the bot chatting one line at a time
I think this would involve tweaking DiscordCommandSender so that when sendMessage and sendStatusMessage are called, rather than immediately calling this.channel.sendMessage
, the message would be added to a queue and a small timer would start; if another message came in, add it also to the queue and reset the timer. When the timer fires, then call sendMessage once with all the queued messages joined by newline. Basically the send function should be debounced. There are some example Java debounce implementations in this SO question.
Thanks! I reviewed the commit and added a few comments. Would caution you not to roll a curseforge release if you haven't already, because I think the chat relaying is broken (will keep queueing messages without clearing the queue). And then just a potential rare ConcurrentModificationException and a couple other thoughts.