Skip to content

Commit 8b15df3

Browse files
committed
Merge branch 'develop' into main
2 parents b7306d1 + ca1a0ed commit 8b15df3

14 files changed

Lines changed: 130 additions & 173 deletions

Present/Commands/GiveawayCommand.Create.cs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -100,34 +100,4 @@ public async Task CreateAsync(InteractionContext context,
100100
followup.AddEmbed(embed);
101101
await context.FollowUpAsync(followup).ConfigureAwait(false);
102102
}
103-
104-
private static async Task<DateTimeOffset> ValidateTimeStamp(
105-
InteractionContext context,
106-
DiscordModalTextInput timeInput,
107-
DiscordEmbedBuilder embed,
108-
DiscordFollowupMessageBuilder followup
109-
)
110-
{
111-
if (!TimeStampUtility.TryParse(timeInput.Value, out DateTimeOffset endTime))
112-
{
113-
Logger.Warn($"Provided time was invalid ({timeInput.Value}). Giveaway creation has been cancelled");
114-
embed.WithDescription(EmbedStrings.GiveawayCreation_InvalidTimestamp);
115-
followup.AsEphemeral();
116-
followup.AddEmbed(embed);
117-
await context.FollowUpAsync(followup).ConfigureAwait(false);
118-
return default;
119-
}
120-
121-
if (endTime < DateTimeOffset.UtcNow)
122-
{
123-
Logger.Warn($"Provided time ({timeInput.Value}) is in the past. Giveaway creation has been cancelled");
124-
embed.WithDescription(EmbedStrings.GiveawayCreation_FutureTimestamp);
125-
followup.AsEphemeral();
126-
followup.AddEmbed(embed);
127-
await context.FollowUpAsync(followup).ConfigureAwait(false);
128-
return default;
129-
}
130-
131-
return endTime;
132-
}
133103
}

Present/Commands/GiveawayCommand.End.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using CSharpVitamins;
2-
using DSharpPlus.Entities;
1+
using DSharpPlus.Entities;
32
using DSharpPlus.SlashCommands;
43
using DSharpPlus.SlashCommands.Attributes;
54
using Present.Data;
@@ -13,20 +12,13 @@ internal sealed partial class GiveawayCommand
1312
[SlashCommand(CommandNames.End, CommandDescriptions.End, false)]
1413
[SlashRequireGuild]
1514
public async Task EndAsync(InteractionContext context,
16-
[Option(OptionNames.Id, OptionDescriptions.EndGiveawayId)] string idRaw
15+
[Option(OptionNames.Id, OptionDescriptions.EndGiveawayId)] long giveawayId
1716
)
1817
{
1918
var embed = new DiscordEmbedBuilder();
2019
embed.WithColor(DiscordColor.Red);
2120
embed.WithTitle(EmbedStrings.InvalidGiveawayId);
2221

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-
3022
DiscordGuild guild = context.Guild;
3123
if (!_giveawayService.TryGetGiveaway(giveawayId, out Giveaway? giveaway) || giveaway.GuildId != guild.Id)
3224
{

Present/Commands/GiveawayCommand.Redraw.cs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using CSharpVitamins;
2-
using DSharpPlus.Entities;
1+
using DSharpPlus.Entities;
32
using DSharpPlus.SlashCommands;
43
using DSharpPlus.SlashCommands.Attributes;
54
using Present.Data;
@@ -12,21 +11,14 @@ internal sealed partial class GiveawayCommand
1211
[SlashCommand(CommandNames.Redraw, CommandDescriptions.Redraw, false)]
1312
[SlashRequireGuild]
1413
public async Task RedrawAsync(InteractionContext context,
15-
[Option(OptionNames.Id, OptionDescriptions.RedrawGiveawayId)] string idRaw,
14+
[Option(OptionNames.Id, OptionDescriptions.RedrawGiveawayId)] long giveawayId,
1615
[Option(OptionNames.KeepIds, OptionDescriptions.RedrawKeep)] string? keepIds = null
1716
)
1817
{
1918
var embed = new DiscordEmbedBuilder();
2019
embed.WithColor(DiscordColor.Red);
2120
embed.WithTitle(EmbedStrings.InvalidGiveawayId);
2221

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-
3022
DiscordGuild guild = context.Guild;
3123
if (!_giveawayService.TryGetGiveaway(giveawayId, out Giveaway? giveaway) || giveaway.GuildId != guild.Id)
3224
{
@@ -49,22 +41,26 @@ public async Task RedrawAsync(InteractionContext context,
4941
{
5042
foreach (string keepId in keepIds.Split((char[]?) null, StringSplitOptions.RemoveEmptyEntries))
5143
{
52-
if (ulong.TryParse(keepId, out ulong userId) &&
53-
_giveawayService.ValidateUser(userId, guild, out DiscordMember? member))
54-
keep.Add(member);
55-
else
44+
if (!ulong.TryParse(keepId, out ulong userId))
45+
{
5646
invalidKeepIds.Add(keepId);
47+
continue;
48+
}
49+
50+
DiscordMember? member = await _giveawayService.ValidateUserAsync(userId, giveaway).ConfigureAwait(false);
51+
if (member is null) invalidKeepIds.Add(keepId);
52+
else keep.Add(member);
5753
}
5854
}
5955

60-
IReadOnlyList<DiscordMember> winners = _giveawayService.SelectWinners(giveaway, keep);
56+
IReadOnlyList<DiscordMember> winners = await _giveawayService.SelectWinnersAsync(giveaway, keep).ConfigureAwait(false);
6157
await _giveawayService.UpdateWinnersAsync(giveaway, winners).ConfigureAwait(false);
6258

6359
await _giveawayService.EditGiveawayAsync(giveaway).ConfigureAwait(false);
6460
await _giveawayService.UpdateGiveawayLogMessageAsync(giveaway).ConfigureAwait(false);
6561
await _giveawayService.UpdateGiveawayPublicMessageAsync(giveaway).ConfigureAwait(false);
6662

67-
embed = _giveawayService.CreateGiveawayInformationEmbed(giveaway);
63+
embed = await _giveawayService.CreateGiveawayInformationEmbedAsync(giveaway).ConfigureAwait(false);
6864
embed.WithColor(DiscordColor.Green);
6965
embed.WithTitle(EmbedStrings.GiveawayEdited_Title);
7066

Present/Commands/GiveawayCommand.SetWinners.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using CSharpVitamins;
2-
using DSharpPlus.Entities;
1+
using DSharpPlus.Entities;
32
using DSharpPlus.SlashCommands;
43
using DSharpPlus.SlashCommands.Attributes;
54
using Present.Data;
@@ -12,21 +11,14 @@ internal sealed partial class GiveawayCommand
1211
[SlashCommand(CommandNames.SetWinners, CommandDescriptions.End, false)]
1312
[SlashRequireGuild]
1413
public async Task SetWinnersAsync(InteractionContext context,
15-
[Option(OptionNames.Id, OptionDescriptions.EndGiveawayId)] string idRaw,
14+
[Option(OptionNames.Id, OptionDescriptions.EndGiveawayId)] long giveawayId,
1615
[Option(OptionNames.WinnerCount, OptionDescriptions.WinnerCount)] long winnerCount
1716
)
1817
{
1918
var embed = new DiscordEmbedBuilder();
2019
embed.WithColor(DiscordColor.Red);
2120
embed.WithTitle(EmbedStrings.InvalidGiveawayId);
2221

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-
3022
DiscordGuild guild = context.Guild;
3123
if (!_giveawayService.TryGetGiveaway(giveawayId, out Giveaway? giveaway) || giveaway.GuildId != guild.Id)
3224
{
@@ -55,7 +47,7 @@ public async Task SetWinnersAsync(InteractionContext context,
5547
await _giveawayService.UpdateGiveawayLogMessageAsync(giveaway).ConfigureAwait(false);
5648
await _giveawayService.UpdateGiveawayPublicMessageAsync(giveaway).ConfigureAwait(false);
5749

58-
embed = _giveawayService.CreateGiveawayInformationEmbed(giveaway);
50+
embed = await _giveawayService.CreateGiveawayInformationEmbedAsync(giveaway).ConfigureAwait(false);
5951
embed.WithColor(DiscordColor.Green);
6052
embed.WithTitle(EmbedStrings.GiveawayEdited_Title);
6153
await context.CreateResponseAsync(embed).ConfigureAwait(false);

Present/Commands/GiveawayCommand.View.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using CSharpVitamins;
2-
using DSharpPlus.Entities;
1+
using DSharpPlus.Entities;
32
using DSharpPlus.SlashCommands;
43
using DSharpPlus.SlashCommands.Attributes;
54
using Present.Data;
@@ -12,20 +11,13 @@ internal sealed partial class GiveawayCommand
1211
[SlashCommand(CommandNames.View, CommandDescriptions.ViewGiveaway, false)]
1312
[SlashRequireGuild]
1413
public async Task ViewAsync(InteractionContext context,
15-
[Option(OptionNames.Id, OptionDescriptions.ViewGiveawayId)] string idRaw
14+
[Option(OptionNames.Id, OptionDescriptions.ViewGiveawayId)] long giveawayId
1615
)
1716
{
1817
var embed = new DiscordEmbedBuilder();
1918
embed.WithColor(DiscordColor.Red);
2019
embed.WithTitle(EmbedStrings.InvalidGiveawayId);
2120

22-
if (!ShortGuid.TryParse(idRaw, out ShortGuid giveawayId))
23-
{
24-
embed.WithDescription(string.Format(EmbedStrings.InvalidId, idRaw));
25-
await context.CreateResponseAsync(embed, true).ConfigureAwait(false);
26-
return;
27-
}
28-
2921
DiscordGuild guild = context.Guild;
3022
if (!_giveawayService.TryGetGiveaway(giveawayId, out Giveaway? giveaway) || giveaway.GuildId != guild.Id)
3123
{
@@ -34,7 +26,7 @@ public async Task ViewAsync(InteractionContext context,
3426
return;
3527
}
3628

37-
embed = _giveawayService.CreateGiveawayInformationEmbed(giveaway);
29+
embed = await _giveawayService.CreateGiveawayInformationEmbedAsync(giveaway).ConfigureAwait(false);
3830
embed.WithTitle(EmbedStrings.GiveawayInformation);
3931

4032
await context.CreateResponseAsync(embed).ConfigureAwait(false);

Present/Commands/GiveawayCommand.ViewEntrants.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using CSharpVitamins;
2-
using DSharpPlus.Entities;
1+
using DSharpPlus.Entities;
32
using DSharpPlus.SlashCommands;
43
using DSharpPlus.SlashCommands.Attributes;
54
using Present.Data;
@@ -13,20 +12,13 @@ internal sealed partial class GiveawayCommand
1312
[SlashCommand(CommandNames.ViewEntrants, CommandDescriptions.ViewEntrants, false)]
1413
[SlashRequireGuild]
1514
public async Task ViewEntrantsAsync(InteractionContext context,
16-
[Option(OptionNames.Id, OptionDescriptions.ViewGiveawayId)] string idRaw
15+
[Option(OptionNames.Id, OptionDescriptions.ViewGiveawayId)] long giveawayId
1716
)
1817
{
1918
var embed = new DiscordEmbedBuilder();
2019
embed.WithColor(DiscordColor.Red);
2120
embed.WithTitle(EmbedStrings.InvalidGiveawayId);
2221

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-
3022
DiscordGuild guild = context.Guild;
3123
if (!_giveawayService.TryGetGiveaway(giveawayId, out Giveaway? giveaway) || giveaway.GuildId != guild.Id)
3224
{

Present/Commands/GiveawayCommand.cs

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
using DSharpPlus.SlashCommands;
1+
using DSharpPlus.Entities;
2+
using DSharpPlus.SlashCommands;
23
using Present.Resources;
34
using Present.Services;
45
using NLog;
6+
using Present.Interactivity;
57

68
namespace Present.Commands;
79

@@ -41,4 +43,34 @@ UserExclusionService userExclusionService
4143
_roleExclusionService = roleExclusionService;
4244
_userExclusionService = userExclusionService;
4345
}
46+
47+
private static async Task<DateTimeOffset> ValidateTimeStamp(
48+
InteractionContext context,
49+
DiscordModalTextInput timeInput,
50+
DiscordEmbedBuilder embed,
51+
DiscordFollowupMessageBuilder followup
52+
)
53+
{
54+
if (!TimeStampUtility.TryParse(timeInput.Value, out DateTimeOffset endTime))
55+
{
56+
Logger.Warn($"Provided time was invalid ({timeInput.Value}). Giveaway creation has been cancelled");
57+
embed.WithDescription(EmbedStrings.GiveawayCreation_InvalidTimestamp);
58+
followup.AsEphemeral();
59+
followup.AddEmbed(embed);
60+
await context.FollowUpAsync(followup).ConfigureAwait(false);
61+
return default;
62+
}
63+
64+
if (endTime < DateTimeOffset.UtcNow)
65+
{
66+
Logger.Warn($"Provided time ({timeInput.Value}) is in the past. Giveaway creation has been cancelled");
67+
embed.WithDescription(EmbedStrings.GiveawayCreation_FutureTimestamp);
68+
followup.AsEphemeral();
69+
followup.AddEmbed(embed);
70+
await context.FollowUpAsync(followup).ConfigureAwait(false);
71+
return default;
72+
}
73+
74+
return endTime;
75+
}
4476
}

Present/Data/EntityConfigurations/GiveawayConfiguration.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public void Configure(EntityTypeBuilder<Giveaway> builder)
1616
builder.ToTable(nameof(Giveaway));
1717
builder.HasKey(e => e.Id);
1818

19-
builder.Property(e => e.Id).HasConversion<ShortGuidToBytesConverter>();
19+
builder.Property(e => e.Id);
2020
builder.Property(e => e.StartTime).HasConversion<DateTimeOffsetToBytesConverter>();
2121
builder.Property(e => e.EndTime).HasConversion<DateTimeOffsetToBytesConverter>();
2222
builder.Property(e => e.EndHandled);
@@ -27,6 +27,8 @@ public void Configure(EntityTypeBuilder<Giveaway> builder)
2727
builder.Property(e => e.Description);
2828
builder.Property(e => e.ImageUri).HasConversion<UriToStringConverter>();
2929
builder.Property(e => e.Entrants).HasConversion<UInt64ListToBytesConverter>();
30+
builder.Property(e => e.ExcludedRoles).HasConversion<UInt64ListToBytesConverter>();
31+
builder.Property(e => e.ExcludedUsers).HasConversion<UInt64ListToBytesConverter>();
3032
builder.Property(e => e.WinnerCount);
3133
builder.Property(e => e.WinnerIds).HasConversion<UInt64ListToBytesConverter>();
3234
builder.Property(e => e.MessageId);

Present/Data/Giveaway.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using CSharpVitamins;
2-
3-
namespace Present.Data;
1+
namespace Present.Data;
42

53
/// <summary>
64
/// Represents a giveaway.
@@ -43,6 +41,18 @@ internal sealed class Giveaway : IEquatable<Giveaway>
4341
/// <value>The end date and time.</value>
4442
public DateTimeOffset EndTime { get; set; }
4543

44+
/// <summary>
45+
/// Gets or sets the list of excluded role IDs for this giveaway.
46+
/// </summary>
47+
/// <value>A <see cref="List{T}" /> of <see cref="ulong" /> representing the excluded role IDs.</value>
48+
public List<ulong> ExcludedRoles { get; set; } = new();
49+
50+
/// <summary>
51+
/// Gets or sets the list of excluded user IDs for this giveaway.
52+
/// </summary>
53+
/// <value>A <see cref="List{T}" /> of <see cref="ulong" /> representing the excluded user IDs.</value>
54+
public List<ulong> ExcludedUsers { get; set; } = new();
55+
4656
/// <summary>
4757
/// Gets or sets the guild ID of the giveaway.
4858
/// </summary>
@@ -53,7 +63,7 @@ internal sealed class Giveaway : IEquatable<Giveaway>
5363
/// Gets or sets the ID of the giveaway.
5464
/// </summary>
5565
/// <value>The giveaway ID.</value>
56-
public ShortGuid Id { get; set; }
66+
public long Id { get; set; }
5767

5868
/// <summary>
5969
/// Gets or sets the image URI for this giveaway.

Present/Data/ValueConverters/ShortGuidToBytesConverter.cs

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)