-
Notifications
You must be signed in to change notification settings - Fork 18
Implement channel name update rate limiting in Bot class #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -55,6 +55,20 @@ public async Task LoadConfig() | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Time = config.Item2; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Info($"Created: {Bots.Count} bot(s) that update every {Time} seconds."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Check for channel IDs set with update frequency less than 5 minutes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (Time < 300) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| foreach (var bot in Bots.Values) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (bot.Information.ChannelID != null && bot.Information.ChannelID != 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Warn($"Bot '{bot.Information.Name}' has a channel ID set and update time is less than 5 minutes ({Time} seconds). " + | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| $"Channel name updates will be rate-limited to once every 5 minutes regardless of update timer to avoid Discord API throttling.", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| bot.Information.Id.ToString()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe it's best to do this warning message whenever we are running IConfigurable#Configure, as this is where we are populating and starting the bots. PlayerCountDiscordBot/DiscordPlayerCountBot/Configuration/DockerConfiguration.cs Lines 40 to 67 in 6cd7df7
PlayerCountDiscordBot/DiscordPlayerCountBot/Configuration/StandardConfiguration.cs Lines 43 to 48 in 6cd7df7
I believe the message is clear on what is going on; however, I do not like to concat strings like this and would rather use a string builder instead. https://learn.microsoft.com/en-us/dotnet/api/system.text.stringbuilder?view=net-9.0 |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public async Task UpdatePlayerCounts() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that there is an interface and classes to be built here to support this. I think that we would want some sort of generic solution just in case Discord ever imposes a rate limit on any other part of the application.
The above is the interface that I think full encompasses what a rate limit would be.
As far as what is the implementation of what would use these objects I cannot say at this moment, I can only image in the short term, for the usage would be:
Maybe the key shouldn't be a string and should be an enum?
What are your thoughts?