MiraWaNeko / DiscordIntegration

Communicate between Minecraft and Discord
https://discordintegration.net
GNU Affero General Public License v3.0
88 stars 42 forks source link

Batch multi-line command responses when sending to Discord #125

Closed Ricket closed 6 years ago

Ricket commented 6 years ago

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

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.

Ricket commented 6 years ago

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.