momentum-mod / discord-bot

The Discord bot used in the official Momentum Mod Discord Server.
https://discord.gg/momentummod
MIT License
9 stars 7 forks source link

Rate limit Twitch stream announces #145

Open tsa96 opened 1 year ago

tsa96 commented 1 year ago

We quite often see Twitch streams on bad internet spamming the #live-streams channel every time their stream restarts. Also, it's obviously pretty abuse-able, so worth limiting before 1.0.0 drops.

Here's a sketch of the system we've been discussing:

  1. When a stream message is deleted, store the streamer ID, and schedule a method call for 1 hour in the future (time should be configurable)
  2. If it drops and comes back up a first time, announce again but don't ping users with the "@Live Streams" role.
  3. If it drops and comes back up a second time, don't re-announce, but track that this has happened.
  4. In the delayed call scheduled in (1), check if the stream is in the announce-blocked state tracked in (3), and re-announce it.
  5. Follow the same logic each hour, if it's been reannounced, allow it to drop and be re-announced only once per hour.
  6. Stream pings should be limited to once per 6 hours (again, this can be configurable), so any re-announces 6 hours after the first announce don't ping.

This should be a fun little programming task that doesn't require a great deal of knowledge of DSharpPlus, mostly just C# task scheduling and writing sensible data structures for handling the states. So a very good first issue.