Skip to content

Conversation

@rogersau
Copy link

This change allows people to specify an update value of less than 300 seconds, when having channel name updates enabled.

I found an issue that I wanted the bots to be as up to date as possible. But had to specify an Update Time greater than 300 seconds otherwise channel names went a bit crazy.

Added a rather rudimentary check that validates whether then channel name update occurred greater than 5 minutes ago.

@rogersau
Copy link
Author

Also added a warning as per #77

@GravityWolfNotAmused GravityWolfNotAmused changed the base branch from latest to dev April 16, 2025 02:08
@GravityWolfNotAmused
Copy link
Owner

I appreciate the pull request! I'll review this when I get home from holiday. We might want to break this time limit stuff into its own interface and class though, but I'm highly for having this implemented into the bot.

@rogersau
Copy link
Author

I wrote it quite quickly as i wasnt sure if there was a desire for this functionality. happy to break it out :)

bot.Information.Id.ToString());
}
}
}

Choose a reason for hiding this comment

The 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.

foreach (var botName in botNames)
{
var address = botAddresses.ElementAtOrDefault(index);
var port = botPorts.ElementAtOrDefault(index);
var token = botTokens.ElementAtOrDefault(index) ?? throw new ApplicationException("Missing bot token.");
var status = botStatuses.ElementAtOrDefault(index);
var statusFormat = statusFormats.ElementAtOrDefault(index);
var nameAsLabel = botTags.ElementAtOrDefault(index);
var channelID = channelIds.ElementAtOrDefault(index);
var provider = EnumHelper.GetDataProvider(providerTypes.ElementAtOrDefault(index));
var info = new BotInformation()
{
Name = botName,
Address = string.Format("{0}:{1}", address, port),
Token = token,
Status = status,
StatusFormat = statusFormat,
UseNameAsLabel = nameAsLabel,
ChannelID = channelID,
ProviderType = provider
};
var bot = new Bot.Bot(info, applicationTokens, dataProviders);
await bot.StartAsync(shouldStart);
bots.Add(bot.Information.Id.ToString(), bot);
index++;
}

foreach (var info in config.ServerInformation)
{
var bot = new Bot.Bot(info, config.ApplicationTokens, dataProviders);
await bot.StartAsync(shouldStart);
bots.Add(bot.Information!.Id.ToString(), bot);
}

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


await DiscordClient.SetGameAsync(LastKnownStatus, null, (ActivityType)activityInteger);
await DiscordClient.SetChannelName(Information.ChannelID, LastKnownStatus);

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.

public interface IRateLimiter
{
    /// <summary>
    /// Determines if the operation can be executed under current rate limits.
    /// </summary>
    bool CanExecute(string key);

    /// <summary>
    /// Records an operation attempt.
    /// </summary>
    void RecordExecution(string key);
}

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:

await obj.TryExecuteAsync("rename_channel", async () =>
{
    Console.WriteLine("Renaming channel..."); // Could do anything, not just log.
});

Maybe the key shouldn't be a string and should be an enum?

What are your thoughts?

@rogersau
Copy link
Author

yep will work towards the above

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants