diff --git a/Bot/Discord/Cmds.cs b/Bot/Discord/Cmds.cs index 95d2e74..f454e21 100644 --- a/Bot/Discord/Cmds.cs +++ b/Bot/Discord/Cmds.cs @@ -90,4 +90,43 @@ public async Task LinkAsync(Member coc, IGuildUser discord) main.Update(); await RespondAsync("Linked"); } + + [SlashCommand("info", "Shows info of a Coc member")] + public async Task InfoAsync(Member member) + { + ClanMember cocMem = Coc.GetMember(member.CocId); + + EmbedBuilder embed = new() + { + Title = cocMem.Name, + Author = new EmbedAuthorBuilder { Name = cocMem.Tag } + }; + + Alt? alt = member.TryToAlt(); + if (alt == null) + { + embed.Description = string.Join(", ", member.GetAltsByMain().Select(a => Coc.GetMember(a.AltId).Name)); + Main main = member.ToMain(); + if (main.Discord != null) + { + embed.AddField("Discord", $"<@{main.Discord}>"); + } + } + else + { + embed.Description = $"__{Coc.GetMember(alt.MainId).Name}__"; + IEnumerable altNames = alt.GetOtherAlts().Select(a => Coc.GetMember(a.AltId).Name); + foreach (string altName in altNames) + { + embed.Description += $", {altName}"; + } + Main main = alt.GetMain(); + if (main.Discord != null) + { + embed.AddField("Discord", $"<@{main.Discord}>"); + } + } + + await RespondAsync(embed: embed.Build()); + } } diff --git a/Bot/Sql/Alt.cs b/Bot/Sql/Alt.cs index 45a6eb5..f1849b8 100644 --- a/Bot/Sql/Alt.cs +++ b/Bot/Sql/Alt.cs @@ -14,6 +14,8 @@ public Alt() : this("", "") { } public TableQuery GetOtherAlts() => Db.s_db.Table().Where(a => a.MainId == MainId && a.AltId != AltId); + public Main GetMain() => Db.s_db.Table
().Where(m => m.MainId == MainId).First(); + public bool UpdateMain(string id) { MainId = id; diff --git a/Bot/Sql/Member.cs b/Bot/Sql/Member.cs index b034e51..81ee928 100644 --- a/Bot/Sql/Member.cs +++ b/Bot/Sql/Member.cs @@ -42,6 +42,8 @@ public bool IsAltMain() public Main? TryToMain() => Db.s_db.Table
().FirstOrDefault(m => m.MainId == CocId); + public Main ToMain() => Db.s_db.Table
().First(m => m.MainId == CocId); + public TableQuery GetAltsByMain() => Db.s_db.Table().Where(a => a.MainId == CocId); public string GetName() => Coc.GetMember(CocId).Name;