Skip to content

Commit

Permalink
add event recurrence rules
Browse files Browse the repository at this point in the history
squashed so it’s slightly easier to keep track of our patches
  • Loading branch information
DA-344 authored and odrling committed Sep 25, 2024
1 parent 0888b3e commit 7f80910
Show file tree
Hide file tree
Showing 6 changed files with 540 additions and 10 deletions.
19 changes: 19 additions & 0 deletions discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@
'EntitlementType',
'EntitlementOwnerType',
'PollLayoutType',
'ScheduledEventRecurrenceFrequency',
'ScheduledEventRecurrenceWeekday',
)


Expand Down Expand Up @@ -835,6 +837,23 @@ class ReactionType(Enum):
burst = 1


class ScheduledEventRecurrenceFrequency(Enum):
yearly = 0
monthly = 1
weekly = 2
daily = 3


class ScheduledEventRecurrenceWeekday(Enum):
monday = 0
tuesday = 1
wednesday = 2
thursday = 3
friday = 4
saturday = 5
sunday = 6


def create_unknown_value(cls: Type[E], val: Any) -> E:
value_cls = cls._enum_value_cls_ # type: ignore # This is narrowed below
name = f'unknown_{val}'
Expand Down
16 changes: 15 additions & 1 deletion discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
from .asset import Asset
from .flags import SystemChannelFlags
from .integrations import Integration, PartialIntegration, _integration_factory
from .scheduled_event import ScheduledEvent
from .scheduled_event import ScheduledEvent, ScheduledEventRecurrenceRule
from .stage_instance import StageInstance
from .threads import Thread, ThreadMember
from .sticker import GuildSticker
Expand Down Expand Up @@ -3038,6 +3038,7 @@ async def create_scheduled_event(
description: str = ...,
image: bytes = ...,
reason: Optional[str] = ...,
recurrence_rule: Optional[ScheduledEventRecurrenceRule] = ...,
) -> ScheduledEvent:
...

Expand All @@ -3054,6 +3055,7 @@ async def create_scheduled_event(
description: str = ...,
image: bytes = ...,
reason: Optional[str] = ...,
recurrence_rule: Optional[ScheduledEventRecurrenceRule] = ...,
) -> ScheduledEvent:
...

Expand All @@ -3069,6 +3071,7 @@ async def create_scheduled_event(
description: str = ...,
image: bytes = ...,
reason: Optional[str] = ...,
recurrence_rule: Optional[ScheduledEventRecurrenceRule] = ...,
) -> ScheduledEvent:
...

Expand All @@ -3084,6 +3087,7 @@ async def create_scheduled_event(
description: str = ...,
image: bytes = ...,
reason: Optional[str] = ...,
recurrence_rule: Optional[ScheduledEventRecurrenceRule] = ...,
) -> ScheduledEvent:
...

Expand All @@ -3100,6 +3104,7 @@ async def create_scheduled_event(
description: str = MISSING,
image: bytes = MISSING,
reason: Optional[str] = None,
recurrence_rule: Optional[ScheduledEventRecurrenceRule] = MISSING,
) -> ScheduledEvent:
r"""|coro|
Expand Down Expand Up @@ -3146,6 +3151,9 @@ async def create_scheduled_event(
Required if the ``entity_type`` is :attr:`EntityType.external`.
reason: Optional[:class:`str`]
The reason for creating this scheduled event. Shows up on the audit log.
recurrence_rule: Optional[:class:`ScheduledEventRecurrenceRule`]
The recurrence rule this event will follow. If this is ``None`` then this is
a one-time event.
Raises
-------
Expand Down Expand Up @@ -3240,6 +3248,12 @@ async def create_scheduled_event(
)
payload['scheduled_end_time'] = end_time.isoformat()

if recurrence_rule is not MISSING:
if recurrence_rule is not None:
payload['recurrence_rule'] = recurrence_rule._to_dict()
else:
payload['recurrence_rule'] = None

if metadata:
payload['entity_metadata'] = metadata

Expand Down
2 changes: 2 additions & 0 deletions discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -2020,6 +2020,7 @@ def create_guild_scheduled_event(
'description',
'entity_type',
'image',
'recurrence_rule',
)
payload = {k: v for k, v in payload.items() if k in valid_keys}

Expand Down Expand Up @@ -2073,6 +2074,7 @@ def edit_scheduled_event(
'description',
'entity_type',
'image',
'recurrence_rule',
)
payload = {k: v for k, v in payload.items() if k in valid_keys}

Expand Down
Loading

0 comments on commit 7f80910

Please sign in to comment.