From 2f1b1f4b27c2c56147e40c3e207537e357076fe5 Mon Sep 17 00:00:00 2001 From: rootdarkarchon Date: Thu, 12 Oct 2023 17:11:39 +0200 Subject: [PATCH] add more logging to mare wizard module --- .../Discord/DiscordBotServices.cs | 4 +--- .../Discord/MareWizardModule.Delete.cs | 8 ++++++++ .../Discord/MareWizardModule.Recover.cs | 4 ++++ .../Discord/MareWizardModule.Register.cs | 20 ++++++++++++++++++- .../Discord/MareWizardModule.Relink.cs | 11 ++++++++++ .../Discord/MareWizardModule.Secondary.cs | 4 ++++ .../Discord/MareWizardModule.UserInfo.cs | 4 ++++ .../Discord/MareWizardModule.Vanity.cs | 14 +++++++++++++ .../Discord/MareWizardModule.cs | 3 +++ 9 files changed, 68 insertions(+), 4 deletions(-) diff --git a/MareSynchronosServer/MareSynchronosServices/Discord/DiscordBotServices.cs b/MareSynchronosServer/MareSynchronosServices/Discord/DiscordBotServices.cs index 301b97d..130bb45 100644 --- a/MareSynchronosServer/MareSynchronosServices/Discord/DiscordBotServices.cs +++ b/MareSynchronosServer/MareSynchronosServices/Discord/DiscordBotServices.cs @@ -1,6 +1,5 @@ using System.Collections.Concurrent; using Discord.Rest; -using Discord.WebSocket; using MareSynchronosShared.Metrics; namespace MareSynchronosServices.Discord; @@ -46,13 +45,12 @@ public class DiscordBotServices verificationTaskCts = new CancellationTokenSource(); while (!verificationTaskCts.IsCancellationRequested) { + Logger.LogInformation("Processing Verification Queue, Entries: {entr}", VerificationQueue.Count); if (VerificationQueue.TryDequeue(out var queueitem)) { try { queueitem.Value.Invoke(_serviceProvider); - - Logger.LogInformation("Sent login information to user"); } catch (Exception e) { diff --git a/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.Delete.cs b/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.Delete.cs index 243f130..b5aef5b 100644 --- a/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.Delete.cs +++ b/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.Delete.cs @@ -12,6 +12,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}", nameof(ComponentDelete), Context.Interaction.User.Id); + using var mareDb = GetDbContext(); EmbedBuilder eb = new(); eb.WithTitle("Delete Account"); @@ -33,6 +35,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}:{uid}", nameof(SelectionDeleteAccount), Context.Interaction.User.Id, uid); + using var mareDb = GetDbContext(); bool isPrimary = mareDb.Auth.Single(u => u.UserUID == uid).PrimaryUserUID == null; EmbedBuilder eb = new(); @@ -53,6 +57,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}:{uid}", nameof(ComponentDeleteAccountConfirm), Context.Interaction.User.Id, uid); + await RespondWithModalAsync("wizard-delete-confirm-modal:" + uid).ConfigureAwait(false); } @@ -61,6 +67,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}:{uid}", nameof(ModalDeleteAccountConfirm), Context.Interaction.User.Id, uid); + try { if (!string.Equals("DELETE", modal.Delete, StringComparison.Ordinal)) diff --git a/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.Recover.cs b/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.Recover.cs index 95bac24..69933f2 100644 --- a/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.Recover.cs +++ b/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.Recover.cs @@ -14,6 +14,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}", nameof(ComponentRecover), Context.Interaction.User.Id); + using var mareDb = GetDbContext(); EmbedBuilder eb = new(); eb.WithColor(Color.Blue); @@ -34,6 +36,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}:{uid}", nameof(SelectionRecovery), Context.Interaction.User.Id, uid); + using var mareDb = GetDbContext(); EmbedBuilder eb = new(); eb.WithColor(Color.Green); diff --git a/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.Register.cs b/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.Register.cs index 4582f17..82c6380 100644 --- a/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.Register.cs +++ b/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.Register.cs @@ -14,6 +14,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}", nameof(ComponentRegister), Context.Interaction.User.Id); + EmbedBuilder eb = new(); eb.WithColor(Color.Blue); eb.WithTitle("Start Registration"); @@ -33,6 +35,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}", nameof(ComponentRegisterStart), Context.Interaction.User.Id); + using var db = GetDbContext(); var entry = await db.LodeStoneAuth.SingleOrDefaultAsync(u => u.DiscordId == Context.User.Id && u.StartedAt != null).ConfigureAwait(false); if (entry != null) @@ -52,6 +56,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}:{lodestone}", nameof(ModalRegister), Context.Interaction.User.Id, lodestoneModal.LodestoneUrl); + EmbedBuilder eb = new(); eb.WithColor(Color.Purple); var success = await HandleRegisterModalAsync(eb, lodestoneModal).ConfigureAwait(false); @@ -67,6 +73,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}:{verificationcode}", nameof(ComponentRegisterVerify), Context.Interaction.User.Id, verificationCode); + _botServices.VerificationQueue.Enqueue(new KeyValuePair>(Context.User.Id, async (_) => await HandleVerifyAsync(Context.User.Id, verificationCode).ConfigureAwait(false))); EmbedBuilder eb = new(); @@ -86,6 +94,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}:{uid}", nameof(ComponentRegisterVerify), Context.Interaction.User.Id, verificationCode); + EmbedBuilder eb = new(); ComponentBuilder cb = new(); bool stillEnqueued = _botServices.VerificationQueue.Any(k => k.Key == Context.User.Id); @@ -202,20 +212,28 @@ public partial class MareWizardModule if (_botServices.DiscordLodestoneMapping.ContainsKey(userid)) { var randomServer = _botServices.LodestoneServers[random.Next(_botServices.LodestoneServers.Length)]; - var response = await req.GetAsync($"https://{randomServer}.finalfantasyxiv.com/lodestone/character/{_botServices.DiscordLodestoneMapping[userid]}").ConfigureAwait(false); + var url = $"https://{randomServer}.finalfantasyxiv.com/lodestone/character/{_botServices.DiscordLodestoneMapping[userid]}"; + var response = await req.GetAsync(url).ConfigureAwait(false); + _logger.LogInformation("Verifying {userid} with URL {url}", userid, url); if (response.IsSuccessStatusCode) { 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 _); } else { + _logger.LogInformation("Could not verify {userid} from lodestone {lodestone}, did not find authString: {authString}", userid, _botServices.DiscordLodestoneMapping[userid], authString); _botServices.DiscordVerifiedUsers[userid] = false; } } + else + { + _logger.LogWarning("Could not verify {userid}, HttpStatusCode: {code}", userid, response.StatusCode); + } } } diff --git a/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.Relink.cs b/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.Relink.cs index 79642b8..ef0d0ab 100644 --- a/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.Relink.cs +++ b/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.Relink.cs @@ -14,6 +14,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}", nameof(ComponentRelink), Context.Interaction.User.Id); + EmbedBuilder eb = new(); eb.WithTitle("Relink"); eb.WithColor(Color.Blue); @@ -32,6 +34,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}", nameof(ComponentRelinkStart), Context.Interaction.User.Id); + using var db = GetDbContext(); db.LodeStoneAuth.RemoveRange(db.LodeStoneAuth.Where(u => u.DiscordId == Context.User.Id)); _botServices.DiscordVerifiedUsers.TryRemove(Context.User.Id, out _); @@ -46,6 +50,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}:{url}", nameof(ModalRelink), Context.Interaction.User.Id, lodestoneModal.LodestoneUrl); + EmbedBuilder eb = new(); eb.WithColor(Color.Purple); var result = await HandleRelinkModalAsync(eb, lodestoneModal).ConfigureAwait(false); @@ -61,6 +67,9 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}:{uid}:{verificationCode}", nameof(ComponentRelinkVerify), Context.Interaction.User.Id, uid, verificationCode); + + _botServices.VerificationQueue.Enqueue(new KeyValuePair>(Context.User.Id, async (_) => await HandleVerifyRelinkAsync(Context.User.Id, verificationCode).ConfigureAwait(false))); EmbedBuilder eb = new(); @@ -80,6 +89,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}:{uid}:{verificationCode}", nameof(ComponentRelinkVerifyCheck), Context.Interaction.User.Id, uid, verificationCode); + EmbedBuilder eb = new(); ComponentBuilder cb = new(); bool stillEnqueued = _botServices.VerificationQueue.Any(k => k.Key == Context.User.Id); diff --git a/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.Secondary.cs b/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.Secondary.cs index bb75b8c..47451a3 100644 --- a/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.Secondary.cs +++ b/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.Secondary.cs @@ -14,6 +14,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}", nameof(ComponentSecondary), Context.Interaction.User.Id); + using var mareDb = GetDbContext(); var primaryUID = (await mareDb.LodeStoneAuth.Include(u => u.User).SingleAsync(u => u.DiscordId == Context.User.Id).ConfigureAwait(false)).User.UID; var secondaryUids = await mareDb.Auth.CountAsync(p => p.PrimaryUserUID == primaryUID).ConfigureAwait(false); @@ -36,6 +38,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}:{primary}", nameof(ComponentSecondaryCreate), Context.Interaction.User.Id, primaryUid); + using var mareDb = GetDbContext(); EmbedBuilder eb = new(); eb.WithTitle("Secondary UID created"); diff --git a/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.UserInfo.cs b/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.UserInfo.cs index 1396596..f205d8d 100644 --- a/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.UserInfo.cs +++ b/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.UserInfo.cs @@ -12,6 +12,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}", nameof(ComponentUserinfo), Context.Interaction.User.Id); + using var mareDb = GetDbContext(); EmbedBuilder eb = new(); eb.WithTitle("User Info"); @@ -32,6 +34,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}:{uid}", nameof(SelectionUserinfo), Context.Interaction.User.Id, uid); + using var mareDb = GetDbContext(); EmbedBuilder eb = new(); eb.WithTitle($"User Info for {uid}"); diff --git a/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.Vanity.cs b/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.Vanity.cs index cfb00f3..a27139d 100644 --- a/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.Vanity.cs +++ b/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.Vanity.cs @@ -13,6 +13,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}", nameof(ComponentVanity), Context.Interaction.User.Id); + StringBuilder sb = new(); var user = await Context.Guild.GetUserAsync(Context.User.Id).ConfigureAwait(false); bool userIsInVanityRole = _botServices.VanityRoles.Exists(u => user.RoleIds.Contains(u.Id)) || !_botServices.VanityRoles.Any(); @@ -52,6 +54,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}:{uid}", nameof(SelectionVanityUid), Context.Interaction.User.Id, uid); + using var db = GetDbContext(); var user = db.Users.Single(u => u.UID == uid); EmbedBuilder eb = new(); @@ -71,6 +75,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}:{uid}", nameof(SelectionVanityUidSet), Context.Interaction.User.Id, uid); + await RespondWithModalAsync("wizard-vanity-uid-modal:" + uid).ConfigureAwait(false); } @@ -79,6 +85,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}:{uid}:{vanity}", nameof(ConfirmVanityUidModal), Context.Interaction.User.Id, uid, modal.DesiredVanityUID); + EmbedBuilder eb = new(); ComponentBuilder cb = new(); var desiredVanityUid = modal.DesiredVanityUID; @@ -121,6 +129,8 @@ public partial class MareWizardModule [ComponentInteraction("wizard-vanity-gid")] public async Task SelectionVanityGid(string gid) { + _logger.LogInformation("{method}:{userId}:{uid}", nameof(SelectionVanityGid), Context.Interaction.User.Id, gid); + using var db = GetDbContext(); var group = db.Groups.Single(u => u.GID == gid); EmbedBuilder eb = new(); @@ -140,6 +150,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}:{gid}", nameof(SelectionVanityGidSet), Context.Interaction.User.Id, gid); + await RespondWithModalAsync("wizard-vanity-gid-modal:" + gid).ConfigureAwait(false); } @@ -148,6 +160,8 @@ public partial class MareWizardModule { if (!(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}:{gid}:{vanity}", nameof(ConfirmVanityGidModal), Context.Interaction.User.Id, gid, modal.DesiredVanityGID); + EmbedBuilder eb = new(); ComponentBuilder cb = new(); var desiredVanityUid = modal.DesiredVanityGID; diff --git a/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.cs b/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.cs index 024db99..5035cbc 100644 --- a/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.cs +++ b/MareSynchronosServer/MareSynchronosServices/Discord/MareWizardModule.cs @@ -6,6 +6,7 @@ using MareSynchronosShared.Models; using MareSynchronosShared.Services; using MareSynchronosShared.Utils; using Microsoft.EntityFrameworkCore; +using Microsoft.Win32; using StackExchange.Redis; using System.Text.RegularExpressions; @@ -40,6 +41,8 @@ public partial class MareWizardModule : InteractionModuleBase { if (!init && !(await ValidateInteraction().ConfigureAwait(false))) return; + _logger.LogInformation("{method}:{userId}", nameof(StartWizard), Context.Interaction.User.Id); + using var mareDb = GetDbContext(); bool hasAccount = await mareDb.LodeStoneAuth.AnyAsync(u => u.DiscordId == Context.User.Id && u.StartedAt == null).ConfigureAwait(false);