using Discord.Interactions; using Discord; using MareSynchronosShared.Data; using Microsoft.EntityFrameworkCore; namespace MareSynchronosServices.Discord; public partial class MareWizardModule { [ComponentInteraction("wizard-userinfo")] public async Task ComponentUserinfo() { 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"); eb.WithColor(Color.Blue); eb.WithDescription("You can see information about your user account(s) here." + Environment.NewLine + "Use the selection below to select a user account to see info for." + Environment.NewLine + Environment.NewLine + "- 1️⃣ is your primary account/UID" + Environment.NewLine + "- 2️⃣ are all your secondary accounts/UIDs" + Environment.NewLine + "If you are using Vanity UIDs the original UID is displayed in the second line of the account selection."); ComponentBuilder cb = new(); await AddUserSelection(mareDb, cb, "wizard-userinfo-select").ConfigureAwait(false); AddHome(cb); await ModifyInteraction(eb, cb).ConfigureAwait(false); } [ComponentInteraction("wizard-userinfo-select")] public async Task SelectionUserinfo(string uid) { 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}"); await HandleUserInfo(eb, mareDb, uid).ConfigureAwait(false); eb.WithColor(Color.Green); ComponentBuilder cb = new(); await AddUserSelection(mareDb, cb, "wizard-userinfo-select").ConfigureAwait(false); AddHome(cb); await ModifyInteraction(eb, cb).ConfigureAwait(false); } private async Task HandleUserInfo(EmbedBuilder eb, MareDbContext db, string uid) { ulong userToCheckForDiscordId = Context.User.Id; var dbUser = await db.Users.SingleOrDefaultAsync(u => u.UID == uid).ConfigureAwait(false); var groups = await db.Groups.Where(g => g.OwnerUID == dbUser.UID).ToListAsync().ConfigureAwait(false); var groupsJoined = await db.GroupPairs.Where(g => g.GroupUserUID == dbUser.UID).ToListAsync().ConfigureAwait(false); var identity = await _connectionMultiplexer.GetDatabase().StringGetAsync("UID:" + dbUser.UID).ConfigureAwait(false); eb.WithDescription("This is the user info for your selected UID. You can check other UIDs or go back using the menu below."); if (!string.IsNullOrEmpty(dbUser.Alias)) { eb.AddField("Vanity UID", dbUser.Alias); } eb.AddField("Last Online (UTC)", dbUser.LastLoggedIn.ToString("U")); eb.AddField("Currently online ", !string.IsNullOrEmpty(identity)); eb.AddField("Joined Syncshells", groupsJoined.Count); eb.AddField("Owned Syncshells", groups.Count); foreach (var group in groups) { var syncShellUserCount = await db.GroupPairs.CountAsync(g => g.GroupGID == group.GID).ConfigureAwait(false); if (!string.IsNullOrEmpty(group.Alias)) { eb.AddField("Owned Syncshell " + group.GID + " Vanity ID", group.Alias); } eb.AddField("Owned Syncshell " + group.GID + " User Count", syncShellUserCount); } } }