[Feature] Scheduled event recurrence rule (#3023)

* api modelsssssssss

* recurrence rulesssss
This commit is contained in:
Mihail Gribkov
2024-12-21 04:16:11 +08:00
committed by GitHub
parent 438e31edd1
commit b7208d4d99
24 changed files with 585 additions and 131 deletions

View File

@@ -0,0 +1,20 @@
using System;
namespace Discord;
/// <summary>
/// Represents the privacy level of a guild scheduled event.
/// </summary>
public enum GuildScheduledEventPrivacyLevel
{
/// <summary>
/// The scheduled event is public and available in discovery.
/// </summary>
[Obsolete("This event type isn't supported yet! check back later.", true)]
Public = 1,
/// <summary>
/// The scheduled event is only accessible to guild members.
/// </summary>
Private = 2,
}

View File

@@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
namespace Discord;
public readonly struct GuildScheduledEventRecurrenceRule
{
/// <summary>
/// Gets the starting time of the recurrence interval.
/// </summary>
public DateTimeOffset StartsAt { get; }
/// <summary>
/// Gets the ending time of the recurrence interval.
/// </summary>
public DateTimeOffset? EndsAt { get; }
/// <summary>
/// Gets how often the event occurs.
/// </summary>
public RecurrenceFrequency Frequency { get; }
/// <summary>
/// Gets the spacing between the events, defined by <see cref="Frequency"/>.
/// </summary>
public int Interval { get; }
/// <summary>
/// Gets the set of specific days within a week for the event to recur on.
/// </summary>
public IReadOnlyCollection<RecurrenceRuleWeekday> ByWeekday { get; }
/// <summary>
/// Gets the list of specific days within a specific week to recur on.
/// </summary>
public IReadOnlyCollection<RecurrenceRuleByNWeekday> ByNWeekday { get; }
/// <summary>
/// Gets the set of specific months to recur on.
/// </summary>
public IReadOnlyCollection<RecurrenceRuleMonth> ByMonth { get; }
/// <summary>
/// Gets the set of specific dates within a month to recur on.
/// </summary>
public IReadOnlyCollection<int> ByMonthDay { get; }
/// <summary>
/// Gets the set of days within a year to recur on. (1-364)
/// </summary>
public IReadOnlyCollection<int> ByYearDay { get; }
/// <summary>
/// Gets the total amount of times that the event is allowed to recur before stopping.
/// </summary>
/// <remarks>
/// <see langword="null"/> if the event recurs endlessly.
/// </remarks>
public int? Count { get; }
internal GuildScheduledEventRecurrenceRule(DateTimeOffset startsAt, DateTimeOffset? endsAt, RecurrenceFrequency frequency,
int interval, IReadOnlyCollection<RecurrenceRuleWeekday> byWeekday, IReadOnlyCollection<RecurrenceRuleByNWeekday> byNWeekday,
IReadOnlyCollection<RecurrenceRuleMonth> byMonth, IReadOnlyCollection<int> byMonthDay, IReadOnlyCollection<int> byYearDay, int? count)
{
StartsAt = startsAt;
EndsAt = endsAt;
Frequency = frequency;
Interval = interval;
ByWeekday = byWeekday;
ByNWeekday = byNWeekday;
ByMonth = byMonth;
ByMonthDay = byMonthDay;
ByYearDay = byYearDay;
Count = count;
}
}

View File

@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace Discord;
public class GuildScheduledEventRecurrenceRuleProperties
{
/// <summary>
/// Gets or sets the starting time of the recurrence interval.
/// </summary>
public DateTimeOffset StartsAt { get; set; }
/// <summary>
/// Gets or sets how often the event occurs.
/// </summary>
public RecurrenceFrequency Frequency { get; set; }
/// <summary>
/// Gets or sets the spacing between the events, defined by <see cref="Frequency"/>.
/// </summary>
public int Interval { get; set; }
/// <summary>
/// Gets or sets the set of specific days within a week for the event to recur on.
/// </summary>
public HashSet<RecurrenceRuleWeekday> ByWeekday { get; set; }
/// <summary>
/// Gets or sets the list of specific days within a specific week to recur on.
/// </summary>
public List<RecurrenceRuleByNWeekday> ByNWeekday { get; set; }
/// <summary>
/// Gets or sets the set of specific months to recur on.
/// </summary>
public HashSet<RecurrenceRuleMonth> ByMonth { get; set; }
/// <summary>
/// Gets or sets the set of specific dates within a month to recur on.
/// </summary>
public HashSet<int> ByMonthDay { get; set; }
public GuildScheduledEventRecurrenceRuleProperties() {}
public GuildScheduledEventRecurrenceRuleProperties(DateTimeOffset startsAt, RecurrenceFrequency frequency,
int interval, HashSet<RecurrenceRuleWeekday> byWeekday, IEnumerable<RecurrenceRuleByNWeekday> byNWeekday,
HashSet<RecurrenceRuleMonth> byMonth, HashSet<int> byMonthDay)
{
StartsAt = startsAt;
Frequency = frequency;
Interval = interval;
ByWeekday = byWeekday;
ByNWeekday = byNWeekday?.ToList();
ByMonth = byMonth;
ByMonthDay = byMonthDay;
}
}

View File

@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Discord
{
@@ -59,5 +55,10 @@ namespace Discord
/// Gets or sets the banner image of the event.
/// </summary>
public Optional<Image?> CoverImage { get; set; }
/// <summary>
/// Gets or sets the definition for how often this event should recur.
/// </summary>
public Optional<GuildScheduledEventRecurrenceRuleProperties> RecurrenceRule { get; set; }
}
}

View File

@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Discord
@@ -90,6 +88,11 @@ namespace Discord
/// </summary>
int? UserCount { get; }
/// <summary>
/// Gets the definition for how often this event should recur. <cref langword="null"/> if not set.
/// </summary>
GuildScheduledEventRecurrenceRule? RecurrenceRule { get; }
/// <summary>
/// Gets this events banner image url.
/// </summary>

View File

@@ -0,0 +1,12 @@
namespace Discord;
public enum RecurrenceFrequency
{
Yearly = 0,
Monthly = 1,
Weekly = 2,
Daily = 3
}

View File

@@ -0,0 +1,20 @@
namespace Discord;
public readonly struct RecurrenceRuleByNWeekday
{
/// <summary>
/// Gets the week to reoccur on. (from 1 to 5)
/// </summary>
public int Week { get; }
/// <summary>
/// Gets the day within a week to reoccur on.
/// </summary>
public RecurrenceRuleWeekday Day { get; }
internal RecurrenceRuleByNWeekday(int week, RecurrenceRuleWeekday day)
{
Week = week;
Day = day;
}
}

View File

@@ -0,0 +1,22 @@
namespace Discord;
public class RecurrenceRuleByNWeekdayProperties
{
/// <summary>
/// Gets or sets the week to reoccur on. (from 1 to 5)
/// </summary>
public int Week { get; set; }
/// <summary>
/// Gets or sets the day within a week to reoccur on.
/// </summary>
public RecurrenceRuleWeekday Day { get; set; }
public RecurrenceRuleByNWeekdayProperties() {}
public RecurrenceRuleByNWeekdayProperties(int week, RecurrenceRuleWeekday day)
{
Week = week;
Day = day;
}
}

View File

@@ -0,0 +1,28 @@
namespace Discord;
public enum RecurrenceRuleMonth
{
January = 1,
February = 2,
March = 3,
April = 4,
May = 5,
June = 6,
July = 7,
August = 8,
September = 9,
October = 10,
November = 11,
December = 12
}

View File

@@ -0,0 +1,18 @@
namespace Discord;
public enum RecurrenceRuleWeekday
{
Monday = 0,
Tuesday = 1,
Wednesday = 2,
Thursday = 3,
Friday = 4,
Saturday = 5,
Sunday = 6
}

View File

@@ -1,25 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Discord
{
/// <summary>
/// Represents the privacy level of a guild scheduled event.
/// </summary>
public enum GuildScheduledEventPrivacyLevel
{
/// <summary>
/// The scheduled event is public and available in discovery.
/// </summary>
[Obsolete("This event type isn't supported yet! check back later.", true)]
Public = 1,
/// <summary>
/// The scheduled event is only accessible to guild members.
/// </summary>
Private = 2,
}
}