Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Scheduled event recurrence rule #3023

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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,
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Discord
{
Expand Down Expand Up @@ -59,5 +55,10 @@ public class GuildScheduledEventsProperties
/// 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; }
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Discord
Expand Down Expand Up @@ -90,6 +88,11 @@ public interface IGuildScheduledEvent : IEntity<ulong>
/// </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>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Discord;

public enum RecurrenceFrequency
{
Yearly = 0,

Monthly = 1,

Weekly = 2,

Daily = 3
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace Discord;

public enum RecurrenceRuleWeekday
{
Monday = 0,

Tuesday = 1,

Wednesday = 2,

Thursday = 3,

Friday = 4,

Saturday = 5,

Sunday = 6
}

This file was deleted.

Loading
Loading