diff --git a/PluralKit.Bot/Commands/MemberCommands.cs b/PluralKit.Bot/Commands/MemberCommands.cs index 322f43b1..51e91060 100644 --- a/PluralKit.Bot/Commands/MemberCommands.cs +++ b/PluralKit.Bot/Commands/MemberCommands.cs @@ -8,7 +8,9 @@ namespace PluralKit.Bot.Commands [Group("member")] public class MemberCommands : ContextParameterModuleBase { + public SystemStore Systems { get; set; } public MemberStore Members { get; set; } + public EmbedService Embeds { get; set; } public override string Prefix => "member"; public override string ContextNoun => "member"; @@ -115,6 +117,14 @@ namespace PluralKit.Bot.Commands await Context.Channel.SendMessageAsync($"{Emojis.Success} Member color {(color == null ? "cleared" : "changed")}."); } + + [Command] + [Remarks("member")] + public async Task ViewMember(PKMember member) + { + var system = await Systems.GetById(member.Id); + await Context.Channel.SendMessageAsync(embed: await Embeds.CreateMemberEmbed(system, member)); + } public override async Task ReadContextParameterAsync(string value) { diff --git a/PluralKit.Bot/Services/EmbedService.cs b/PluralKit.Bot/Services/EmbedService.cs index 9c80a0f4..3c1af3f3 100644 --- a/PluralKit.Bot/Services/EmbedService.cs +++ b/PluralKit.Bot/Services/EmbedService.cs @@ -1,3 +1,4 @@ +using System.Globalization; using System.Linq; using System.Threading.Tasks; using Discord; @@ -5,11 +6,13 @@ using Discord; namespace PluralKit.Bot { public class EmbedService { private SystemStore _systems; + private MemberStore _members; private IDiscordClient _client; - public EmbedService(SystemStore systems, IDiscordClient client) + public EmbedService(SystemStore systems, MemberStore members, IDiscordClient client) { this._systems = systems; + this._members = members; this._client = client; } @@ -41,5 +44,30 @@ namespace PluralKit.Bot { .WithTimestamp(message.Timestamp) .Build(); } + + public async Task CreateMemberEmbed(PKSystem system, PKMember member) + { + var name = member.Name; + if (system.Name != null) name = $"{member.Name} ({system.Name})"; + + var color = Color.Default; + if (member.Color != null) color = new Color(uint.Parse(member.Color, NumberStyles.HexNumber)); + + var messageCount = await _members.MessageCount(member); + + var eb = new EmbedBuilder() + // TODO: add URL of website when that's up + .WithAuthor(name, member.AvatarUrl) + .WithColor(color) + .WithDescription(member.Description) + .WithFooter($"System ID: {system.Hid} | Member ID: {member.Hid}"); + + if (member.Birthday != null) eb.AddField("Birthdate", member.BirthdayString); + if (member.Pronouns != null) eb.AddField("Pronouns", member.Pronouns); + if (messageCount > 0) eb.AddField("Message Count", messageCount); + if (member.HasProxyTags) eb.AddField("Proxy Tags", $"{member.Prefix}text{member.Suffix}"); + + return eb.Build(); + } } } \ No newline at end of file diff --git a/PluralKit.Core/Stores.cs b/PluralKit.Core/Stores.cs index 3dba40f6..5b27b5b7 100644 --- a/PluralKit.Core/Stores.cs +++ b/PluralKit.Core/Stores.cs @@ -35,6 +35,11 @@ namespace PluralKit { public async Task GetByToken(string token) { return await conn.QuerySingleOrDefaultAsync("select * from systems where token = @Token", new { Token = token }); } + + public async Task GetById(int id) + { + return await conn.QuerySingleOrDefaultAsync("select * from systems where id = @Id", new { Id = id }); + } public async Task Save(PKSystem system) { await conn.ExecuteAsync("update systems set name = @Name, description = @Description, tag = @Tag, avatar_url = @AvatarUrl, token = @Token, ui_tz = @UiTz where id = @Id", system); @@ -95,6 +100,11 @@ namespace PluralKit { public async Task Delete(PKMember member) { await conn.ExecuteAsync("delete from members where id = @Id", member); } + + public async Task MessageCount(PKMember member) + { + return await conn.QuerySingleAsync("select count(*) from messages where member = @Id", member); + } } public class MessageStore {