Skip to content

Commit

Permalink
Add /giveaway viewentrants
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverbooth committed Dec 28, 2022
1 parent 697064d commit 0573be7
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
47 changes: 47 additions & 0 deletions Present/Commands/GiveawayCommand.ViewEntrants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using CSharpVitamins;
using DSharpPlus.Entities;
using DSharpPlus.SlashCommands;
using DSharpPlus.SlashCommands.Attributes;
using Present.Data;
using Present.Resources;
using X10D.DSharpPlus;

namespace Present.Commands;

internal sealed partial class GiveawayCommand
{
[SlashCommand(CommandNames.ViewEntrants, CommandDescriptions.ViewEntrants, false)]
[SlashRequireGuild]
public async Task ViewEntrantsAsync(InteractionContext context,
[Option(OptionNames.Id, OptionDescriptions.ViewGiveawayId)] string idRaw
)
{
var embed = new DiscordEmbedBuilder();
embed.WithColor(DiscordColor.Red);
embed.WithTitle(EmbedStrings.InvalidGiveawayId);

if (!ShortGuid.TryParse(idRaw, out ShortGuid giveawayId))
{
embed.WithDescription(string.Format(EmbedStrings.InvalidId, idRaw));
await context.CreateResponseAsync(embed, true).ConfigureAwait(false);
return;
}

DiscordGuild guild = context.Guild;
if (!_giveawayService.TryGetGiveaway(giveawayId, out Giveaway? giveaway) || giveaway.GuildId != guild.Id)
{
embed.WithDescription(string.Format(EmbedStrings.NoGiveawayFound, giveawayId));
await context.CreateResponseAsync(embed, true).ConfigureAwait(false);
return;
}

embed.WithColor(DiscordColor.CornflowerBlue);
embed.WithTitle(EmbedStrings.GiveawayEntrants);

embed.AddField("Entrants", giveaway.Entrants.Count.ToString("0"));
if (giveaway.Entrants.Count > 0)
embed.WithDescription(string.Join('\n', giveaway.Entrants.Select(e => $"{MentionUtility.MentionUser(e)} ({e:0})")));

await context.CreateResponseAsync(embed).ConfigureAwait(false);
}
}
1 change: 1 addition & 0 deletions Present/Resources/CommandDescriptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ internal static class CommandDescriptions
public const string SetWinners = "Updates the number of winners in an ongoing giveaway.";
public const string UnblockRole = "Unblocks a role, so they are able to win giveaways.";
public const string UnblockUser = "Unblocks a user, so they are able to win giveaways.";
public const string ViewEntrants = "View the entrants of a giveaway.";
public const string ViewGiveaway = "View the details of a giveaway.";
}
1 change: 1 addition & 0 deletions Present/Resources/CommandNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ internal static class CommandNames
public const string Redraw = "redraw";
public const string SetWinners = "setwinners";
public const string View = "view";
public const string ViewEntrants = "viewentrants";
public const string UnblockRole = "unblockrole";
public const string UnblockUser = "unblockuser";
}
9 changes: 9 additions & 0 deletions Present/Resources/EmbedStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Present/Resources/EmbedStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@
<value>The following IDs were ignored because they correspond to invalid or excluded members: {0}</value>
</data>

<data name="GiveawayEntrants" xml:space="preserve">
<value>Giveaway Entrants</value>
</data>
<data name="GiveawayInformation" xml:space="preserve">
<value>Giveaway Information</value>
</data>
Expand Down

0 comments on commit 0573be7

Please sign in to comment.