bot: add member lookup command
This commit is contained in:
parent
c63e20ca50
commit
b42e052fee
@ -8,7 +8,9 @@ namespace PluralKit.Bot.Commands
|
||||
[Group("member")]
|
||||
public class MemberCommands : ContextParameterModuleBase<PKMember>
|
||||
{
|
||||
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<PKMember> ReadContextParameterAsync(string value)
|
||||
{
|
||||
|
@ -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<Embed> 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();
|
||||
}
|
||||
}
|
||||
}
|
@ -35,6 +35,11 @@ namespace PluralKit {
|
||||
public async Task<PKSystem> GetByToken(string token) {
|
||||
return await conn.QuerySingleOrDefaultAsync<PKSystem>("select * from systems where token = @Token", new { Token = token });
|
||||
}
|
||||
|
||||
public async Task<PKSystem> GetById(int id)
|
||||
{
|
||||
return await conn.QuerySingleOrDefaultAsync<PKSystem>("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<int> MessageCount(PKMember member)
|
||||
{
|
||||
return await conn.QuerySingleAsync<int>("select count(*) from messages where member = @Id", member);
|
||||
}
|
||||
}
|
||||
|
||||
public class MessageStore {
|
||||
|
Loading…
Reference in New Issue
Block a user