|
| 1 | +using CSharpVitamins; |
| 2 | +using DSharpPlus.Entities; |
| 3 | +using DSharpPlus.SlashCommands; |
| 4 | +using DSharpPlus.SlashCommands.Attributes; |
| 5 | +using Present.Data; |
| 6 | +using Present.Resources; |
| 7 | +using X10D.DSharpPlus; |
| 8 | + |
| 9 | +namespace Present.Commands; |
| 10 | + |
| 11 | +internal sealed partial class GiveawayCommand |
| 12 | +{ |
| 13 | + [SlashCommand(CommandNames.ViewEntrants, CommandDescriptions.ViewEntrants, false)] |
| 14 | + [SlashRequireGuild] |
| 15 | + public async Task ViewEntrantsAsync(InteractionContext context, |
| 16 | + [Option(OptionNames.Id, OptionDescriptions.ViewGiveawayId)] string idRaw |
| 17 | + ) |
| 18 | + { |
| 19 | + var embed = new DiscordEmbedBuilder(); |
| 20 | + embed.WithColor(DiscordColor.Red); |
| 21 | + embed.WithTitle(EmbedStrings.InvalidGiveawayId); |
| 22 | + |
| 23 | + if (!ShortGuid.TryParse(idRaw, out ShortGuid giveawayId)) |
| 24 | + { |
| 25 | + embed.WithDescription(string.Format(EmbedStrings.InvalidId, idRaw)); |
| 26 | + await context.CreateResponseAsync(embed, true).ConfigureAwait(false); |
| 27 | + return; |
| 28 | + } |
| 29 | + |
| 30 | + DiscordGuild guild = context.Guild; |
| 31 | + if (!_giveawayService.TryGetGiveaway(giveawayId, out Giveaway? giveaway) || giveaway.GuildId != guild.Id) |
| 32 | + { |
| 33 | + embed.WithDescription(string.Format(EmbedStrings.NoGiveawayFound, giveawayId)); |
| 34 | + await context.CreateResponseAsync(embed, true).ConfigureAwait(false); |
| 35 | + return; |
| 36 | + } |
| 37 | + |
| 38 | + embed.WithColor(DiscordColor.CornflowerBlue); |
| 39 | + embed.WithTitle(EmbedStrings.GiveawayEntrants); |
| 40 | + |
| 41 | + embed.AddField("Entrants", giveaway.Entrants.Count.ToString("0")); |
| 42 | + if (giveaway.Entrants.Count > 0) |
| 43 | + embed.WithDescription(string.Join('\n', giveaway.Entrants.Select(e => $"• {MentionUtility.MentionUser(e)} ({e:0})"))); |
| 44 | + |
| 45 | + await context.CreateResponseAsync(embed).ConfigureAwait(false); |
| 46 | + } |
| 47 | +} |
0 commit comments