Skip to content

Commit

Permalink
[Bot] Add /info
Browse files Browse the repository at this point in the history
  • Loading branch information
Pythonic-Rainbow committed Mar 14, 2024
1 parent 1ec9d29 commit 20c3889
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
39 changes: 39 additions & 0 deletions Bot/Discord/Cmds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> 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());
}
}
2 changes: 2 additions & 0 deletions Bot/Sql/Alt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public Alt() : this("", "") { }

public TableQuery<Alt> GetOtherAlts() => Db.s_db.Table<Alt>().Where(a => a.MainId == MainId && a.AltId != AltId);

public Main GetMain() => Db.s_db.Table<Main>().Where(m => m.MainId == MainId).First();

public bool UpdateMain(string id)
{
MainId = id;
Expand Down
2 changes: 2 additions & 0 deletions Bot/Sql/Member.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public bool IsAltMain()

public Main? TryToMain() => Db.s_db.Table<Main>().FirstOrDefault(m => m.MainId == CocId);

public Main ToMain() => Db.s_db.Table<Main>().First(m => m.MainId == CocId);

public TableQuery<Alt> GetAltsByMain() => Db.s_db.Table<Alt>().Where(a => a.MainId == CocId);

public string GetName() => Coc.GetMember(CocId).Name;
Expand Down

0 comments on commit 20c3889

Please sign in to comment.