try to rate limit the registration somewhat

This commit is contained in:
Stanley Dimant
2022-08-02 23:38:17 +02:00
parent bcb4f6565e
commit 31bc36c136

View File

@@ -31,7 +31,7 @@ namespace MareSynchronosServer.Discord
ConcurrentDictionary<ulong, string> DiscordLodestoneMapping = new();
private Timer _timer;
private readonly string[] LodestoneServers = new[] { "eu", "na", "jp", "fr", "de" };
private DateTime lastVerifyCall = DateTime.Now;
public DiscordBot(IServiceProvider services, IConfiguration configuration, ILogger<DiscordBot> logger)
{
this.services = services;
@@ -71,9 +71,17 @@ namespace MareSynchronosServer.Discord
}
else if (arg.Data.Name == "verify")
{
if (lastVerifyCall > DateTime.Now.Subtract(TimeSpan.FromSeconds(5)))
{
await arg.RespondAsync("The verification is a rate limited process. Under heavy load it might take a while until you get your turn. Please wait a few seconds and try again.");
}
else
{
lastVerifyCall = DateTime.Now;
Embed response = await HandleVerifyAsync(arg.User.Id);
await arg.RespondAsync(embeds: new[] { response }, ephemeral: true);
}
}
else
{
await arg.RespondAsync("idk what you did to get here to start, just follow the instructions as provided.", ephemeral: true);
@@ -125,6 +133,8 @@ namespace MareSynchronosServer.Discord
var randomServer = LodestoneServers[rand.Next(LodestoneServers.Length)];
CancellationTokenSource cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromSeconds(2));
try
{
var response = await req.GetAsync($"https://{randomServer}.finalfantasyxiv.com/lodestone/character/{DiscordLodestoneMapping[id]}", cts.Token);
if (response.IsSuccessStatusCode)
{
@@ -193,7 +203,8 @@ namespace MareSynchronosServer.Discord
embedBuilder.WithDescription("Did not find requested authentication key on your profile. Make sure you have saved *twice*, then do **/verify** again.");
}
}
else
}
catch
{
embedBuilder.WithTitle("Failed to get response from Lodestone");
embedBuilder.WithDescription("Wait a few seconds and try again.");