private async Task UpdateOrSendQueue(KaraokeEntry?lastSinger = null, bool mention = true, bool announce = true) { var karaoke = await GetKaraokeAsync(Context.Guild.Id); if (await QueueIsEmptyAsync(karaoke, announce)) { return; } IMessage?message; if (karaoke.KaraokeMessage is not null) { var channel = Context.Guild.GetTextChannel(karaoke.KaraokeChannel); message = await channel.GetMessageAsync((ulong)karaoke.KaraokeMessage); if (message != null) { _ = message.DeleteAsync(); } } var embed = new EmbedBuilder() .WithTitle("Karaoke Queue") .WithUserAsAuthor(Context.User) .AddField("Currently Singing", $"{GetSong(karaoke.CurrentSinger()!)} sang by <@!{karaoke.CurrentSinger()!.User.Id}>"); if (karaoke.NextUp().Any()) { embed.AddLinesIntoFields("Next Up", karaoke.NextUp(), (u, i) => $"{i + 1}. {GetSong(u)} sang by <@!{u.User.Id}>"); } if (lastSinger is not null) { embed.WithDescription( $"The last song was {GetSong(lastSinger)} by <@!{lastSinger.User.Id}>"); } var user = Context.Client.GetUser(karaoke.CurrentSinger() !.User.Id); message = await ReplyAsync($"It is now {(mention ? user.Mention : user.ToString())}'s turn to sing! They're singing {GetSong(karaoke.CurrentSinger())}!", embed : embed.Build()); karaoke.KaraokeMessage = message.Id; await _db.SaveChangesAsync(); }
public static EmbedBuilder AddLinesIntoFields <T>(this EmbedBuilder builder, string title, IEnumerable <T> lines, Func <T, int, string> lineSelector) => builder.AddLinesIntoFields(title, lines.Select(lineSelector));
public async Task AddUserLogs(EmbedBuilder builder, ulong id, Reprimands?reprimands = null) { var guild = await _db.Guilds.FindAsync(Context.Guild.Id); var logs = guild.Moderation !.Logs; switch (reprimands) { case Reprimands.All: await AddUserLogs(builder, id, Reprimands.Default); await AddUserLogs(builder, id, Reprimands.Unmute); await AddUserLogs(builder, id, Reprimands.Unban); break; case Reprimands.Note: AddLogsIntoFields("Notes", logs.Notes, w => $"`[{w.Date:G}]` {w.Reason} by <@!{w.Moderator.Id}>."); break; case Reprimands.Warning: AddLogsIntoFields("Warnings", logs.Warnings, w => $"`[{w.Date:G}]` {w.Reason} by <@!{w.Moderator.Id}>."); break; case Reprimands.Kick: AddLogsIntoFields("Kicks", logs.Kicks, k => $"`[{k.Date:G}]` {k.Reason} by <@!{k.Moderator.Id}>."); break; case Reprimands.Ban: AddLogsIntoFields("Bans", logs.Bans, b => $"``[{b.Date:G}]` {b.Reason} by <@!{b.Moderator.Id}>. {b.Length}"); break; case Reprimands.Unban: AddLogsIntoFields("Bans", logs.Unbans, b => $"``[{b.Date:G}]` {b.Reason} by <@!{b.Moderator.Id}>."); break; case Reprimands.Mute: AddLogsIntoFields("Mutes", logs.Mutes, m => $"`[{m.Date:G}]` {m.Reason} by <@!{m.Moderator.Id}> for {m.Length}."); break; case Reprimands.Unmute: AddLogsIntoFields("Unmute", logs.Unmutes, u => $"`[{u.Date:G}]` {u.Reason} by <@!{u.Moderator.Id}>."); break; default: await AddUserLogs(builder, id, Reprimands.Note); await AddUserLogs(builder, id, Reprimands.Warning); await AddUserLogs(builder, id, Reprimands.Kick); await AddUserLogs(builder, id, Reprimands.Ban); await AddUserLogs(builder, id, Reprimands.Mute); break; } EmbedBuilder AddLogsIntoFields <T>(string title, IEnumerable <T> lines, Func <T, string> lineSelector) where T : Action => builder.AddLinesIntoFields(title, lines .Where(l => l.User.Id == id) .Select(lineSelector)); }