try to rate limit the registration somewhat
This commit is contained in:
@@ -31,7 +31,7 @@ namespace MareSynchronosServer.Discord
|
|||||||
ConcurrentDictionary<ulong, string> DiscordLodestoneMapping = new();
|
ConcurrentDictionary<ulong, string> DiscordLodestoneMapping = new();
|
||||||
private Timer _timer;
|
private Timer _timer;
|
||||||
private readonly string[] LodestoneServers = new[] { "eu", "na", "jp", "fr", "de" };
|
private readonly string[] LodestoneServers = new[] { "eu", "na", "jp", "fr", "de" };
|
||||||
|
private DateTime lastVerifyCall = DateTime.Now;
|
||||||
public DiscordBot(IServiceProvider services, IConfiguration configuration, ILogger<DiscordBot> logger)
|
public DiscordBot(IServiceProvider services, IConfiguration configuration, ILogger<DiscordBot> logger)
|
||||||
{
|
{
|
||||||
this.services = services;
|
this.services = services;
|
||||||
@@ -71,9 +71,17 @@ namespace MareSynchronosServer.Discord
|
|||||||
}
|
}
|
||||||
else if (arg.Data.Name == "verify")
|
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);
|
Embed response = await HandleVerifyAsync(arg.User.Id);
|
||||||
await arg.RespondAsync(embeds: new[] { response }, ephemeral: true);
|
await arg.RespondAsync(embeds: new[] { response }, ephemeral: true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await arg.RespondAsync("idk what you did to get here to start, just follow the instructions as provided.", ephemeral: true);
|
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)];
|
var randomServer = LodestoneServers[rand.Next(LodestoneServers.Length)];
|
||||||
CancellationTokenSource cts = new CancellationTokenSource();
|
CancellationTokenSource cts = new CancellationTokenSource();
|
||||||
cts.CancelAfter(TimeSpan.FromSeconds(2));
|
cts.CancelAfter(TimeSpan.FromSeconds(2));
|
||||||
|
try
|
||||||
|
{
|
||||||
var response = await req.GetAsync($"https://{randomServer}.finalfantasyxiv.com/lodestone/character/{DiscordLodestoneMapping[id]}", cts.Token);
|
var response = await req.GetAsync($"https://{randomServer}.finalfantasyxiv.com/lodestone/character/{DiscordLodestoneMapping[id]}", cts.Token);
|
||||||
if (response.IsSuccessStatusCode)
|
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.");
|
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.WithTitle("Failed to get response from Lodestone");
|
||||||
embedBuilder.WithDescription("Wait a few seconds and try again.");
|
embedBuilder.WithDescription("Wait a few seconds and try again.");
|
||||||
|
|||||||
Reference in New Issue
Block a user