rebuild discord bot to better user interactions
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
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;
|
||||
|
||||
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;
|
||||
|
||||
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 auth = await db.Auth.Include(u => u.PrimaryUser).SingleOrDefaultAsync(u => u.UserUID == dbUser.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." + Environment.NewLine
|
||||
+ "If you want to verify your secret key is valid, go to https://emn178.github.io/online-tools/sha256.html and copy your secret key into there and compare it to the Hashed Secret Key provided 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("Hashed Secret Key", auth.HashedKey);
|
||||
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);
|
||||
}
|
||||
|
||||
eb.AddField("Currently online", !string.IsNullOrEmpty(identity));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user