adapt register and relink module

This commit is contained in:
rootdarkarchon
2023-10-21 00:17:02 +02:00
parent 4e88c6e68f
commit 48ec4f0c27
4 changed files with 35 additions and 29 deletions

View File

@@ -75,8 +75,8 @@ public partial class MareWizardModule
_logger.LogInformation("{method}:{userId}:{verificationcode}", nameof(ComponentRegisterVerify), Context.Interaction.User.Id, verificationCode);
_botServices.VerificationQueue.Enqueue(new KeyValuePair<ulong, Action<IServiceProvider>>(Context.User.Id,
async (_) => await HandleVerifyAsync(Context.User.Id, verificationCode).ConfigureAwait(false)));
_botServices.VerificationQueue.Enqueue(new KeyValuePair<ulong, Action<DiscordBotServices>>(Context.User.Id,
async (service) => await HandleVerifyAsync(Context.User.Id, verificationCode, service).ConfigureAwait(false)));
EmbedBuilder eb = new();
ComponentBuilder cb = new();
eb.WithColor(Color.Purple);
@@ -204,15 +204,15 @@ public partial class MareWizardModule
return (true, lodestoneAuth);
}
private async Task HandleVerifyAsync(ulong userid, string authString)
private async Task HandleVerifyAsync(ulong userid, string authString, DiscordBotServices services)
{
var req = new HttpClient();
_botServices.DiscordVerifiedUsers.Remove(userid, out _);
if (_botServices.DiscordLodestoneMapping.ContainsKey(userid))
services.DiscordVerifiedUsers.Remove(userid, out _);
if (services.DiscordLodestoneMapping.ContainsKey(userid))
{
var randomServer = _botServices.LodestoneServers[random.Next(_botServices.LodestoneServers.Length)];
var url = $"https://{randomServer}.finalfantasyxiv.com/lodestone/character/{_botServices.DiscordLodestoneMapping[userid]}";
var randomServer = services.LodestoneServers[random.Next(services.LodestoneServers.Length)];
var url = $"https://{randomServer}.finalfantasyxiv.com/lodestone/character/{services.DiscordLodestoneMapping[userid]}";
var response = await req.GetAsync(url).ConfigureAwait(false);
_logger.LogInformation("Verifying {userid} with URL {url}", userid, url);
if (response.IsSuccessStatusCode)
@@ -220,14 +220,14 @@ public partial class MareWizardModule
var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);
if (content.Contains(authString))
{
_logger.LogInformation("Verified {userid} from lodestone {lodestone}", userid, _botServices.DiscordLodestoneMapping[userid]);
_botServices.DiscordVerifiedUsers[userid] = true;
_botServices.DiscordLodestoneMapping.TryRemove(userid, out _);
services.DiscordVerifiedUsers[userid] = true;
services.DiscordLodestoneMapping.TryRemove(userid, out _);
_logger.LogInformation("Verified {userid} from lodestone {lodestone}", userid, services.DiscordLodestoneMapping[userid]);
}
else
{
_logger.LogInformation("Could not verify {userid} from lodestone {lodestone}, did not find authString: {authString}", userid, _botServices.DiscordLodestoneMapping[userid], authString);
_botServices.DiscordVerifiedUsers[userid] = false;
services.DiscordVerifiedUsers[userid] = false;
_logger.LogInformation("Could not verify {userid} from lodestone {lodestone}, did not find authString: {authString}", userid, services.DiscordLodestoneMapping[userid], authString);
}
}
else