Skip to content

Commit 8c85a05

Browse files
committed
revert breaking change
1 parent 9d1d5d7 commit 8c85a05

File tree

2 files changed

+153
-3
lines changed

2 files changed

+153
-3
lines changed

discord/enums.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from enum import IntEnum
3131
from typing import TYPE_CHECKING, Any, ClassVar, TypeVar, Union
3232

33+
3334
__all__ = (
3435
"Enum",
3536
"ChannelType",
@@ -62,7 +63,7 @@
6263
"ScheduledEventStatus",
6364
"ScheduledEventPrivacyLevel",
6465
"ScheduledEventEntityType",
65-
"ScheduledEventEntityType",
66+
"ScheduledEventLocationType",
6667
"ScheduledEventRecurrenceFrequency",
6768
"ScheduledEventRecurrenceWeekday",
6869
"ScheduledEventRecurrenceMonth",
@@ -970,6 +971,10 @@ def __int__(self):
970971
return self.value
971972

972973

974+
class ScheduledEventLocationType(ScheduledEventEntityType):
975+
"""Scheduled event location type (deprecated alias for ScheduledEventEntityType)"""
976+
977+
973978
class ScheduledEventRecurrenceFrequency(Enum):
974979
"""Scheduled event recurrence frequency"""
975980

discord/scheduled_events.py

Lines changed: 147 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,104 @@
4141
from .errors import ValidationError
4242
from .iterators import ScheduledEventSubscribersIterator
4343
from .mixins import Hashable
44-
from .utils import warn_deprecated
44+
from .object import Object
45+
from .utils import warn_deprecated, deprecated
4546

4647
__all__ = (
4748
"ScheduledEvent",
49+
"ScheduledEventLocation",
4850
"ScheduledEventEntityMetadata",
4951
"ScheduledEventRecurrenceRule",
5052
"ScheduledEventRecurrenceNWeekday",
5153
)
5254

5355
if TYPE_CHECKING:
5456
from .abc import Snowflake
57+
from .channel import StageChannel, VoiceChannel
5558
from .guild import Guild
5659
from .member import Member
5760
from .state import ConnectionState
5861
from .types.scheduled_events import ScheduledEvent as ScheduledEventPayload
5962
from .types.scheduled_events import (
6063
ScheduledEventRecurrenceRule as ScheduledEventRecurrenceRulePayload,
6164
)
65+
else:
66+
ConnectionState = None
67+
StageChannel = None
68+
VoiceChannel = None
6269

6370
MISSING = utils.MISSING
6471

6572

73+
class ScheduledEventLocation:
74+
"""Represents a scheduled event's location.
75+
76+
Setting the ``value`` to its corresponding type will set the location type automatically:
77+
78+
+------------------------+-----------------------------------------------+
79+
| Type of Input | Location Type |
80+
+========================+===============================================+
81+
| :class:`StageChannel` | :attr:`ScheduledEventEntityType.stage_instance` |
82+
| :class:`VoiceChannel` | :attr:`ScheduledEventEntityType.voice` |
83+
| :class:`str` | :attr:`ScheduledEventEntityType.external` |
84+
+------------------------+-----------------------------------------------+
85+
86+
.. deprecated:: 2.7
87+
Use :class:`ScheduledEventEntityMetadata` instead.
88+
89+
.. versionadded:: 2.0
90+
91+
Attributes
92+
----------
93+
value: Union[:class:`str`, :class:`StageChannel`, :class:`VoiceChannel`, :class:`Object`]
94+
The actual location of the scheduled event.
95+
type: :class:`ScheduledEventEntityType`
96+
The type of location.
97+
"""
98+
99+
__slots__ = (
100+
"_state",
101+
"value",
102+
)
103+
104+
def __init__(
105+
self,
106+
*,
107+
state: ConnectionState | None = None,
108+
value: str | int | StageChannel | VoiceChannel | None = None,
109+
) -> None:
110+
warn_deprecated("ScheduledEventLocation", "ScheduledEventEntityMetadata", "2.7")
111+
self._state: ConnectionState | None = state
112+
self.value: str | StageChannel | VoiceChannel | Object | None
113+
if value is None:
114+
self.value = None
115+
elif isinstance(value, int):
116+
self.value = (
117+
self._state.get_channel(id=int(value)) or Object(id=int(value))
118+
if self._state
119+
else Object(id=int(value))
120+
)
121+
else:
122+
self.value = value
123+
124+
def __repr__(self) -> str:
125+
return f"<ScheduledEventLocation value={self.value!r} type={self.type}>"
126+
127+
def __str__(self) -> str:
128+
return str(self.value) if self.value else ""
129+
130+
@property
131+
def type(self) -> ScheduledEventEntityType:
132+
"""The type of location."""
133+
if isinstance(self.value, str):
134+
return ScheduledEventEntityType.external
135+
elif self.value.__class__.__name__ == "StageChannel":
136+
return ScheduledEventEntityType.stage_instance
137+
elif self.value.__class__.__name__ == "VoiceChannel":
138+
return ScheduledEventEntityType.voice
139+
return ScheduledEventEntityType.voice
140+
141+
66142
class ScheduledEventEntityMetadata:
67143
"""Represents a scheduled event's entity metadata.
68144
@@ -477,7 +553,6 @@ class ScheduledEvent(Hashable):
477553
"status",
478554
"creator_id",
479555
"creator",
480-
"location",
481556
"guild",
482557
"_state",
483558
"_image",
@@ -560,11 +635,59 @@ def __repr__(self) -> str:
560635
f"channel_id={self.channel_id}>"
561636
)
562637

638+
@property
639+
@deprecated(instead="entity_metadata.location", since="2.7", removed="3.0")
640+
def location(self) -> ScheduledEventLocation | None:
641+
"""
642+
Returns the location of the event.
643+
"""
644+
if self.channel_id is None:
645+
self.location = ScheduledEventLocation(
646+
state=self._state, value=self.entity_metadata.location
647+
)
648+
else:
649+
self.location = ScheduledEventLocation(
650+
state=self._state, value=self.channel_id
651+
)
652+
563653
@property
564654
def created_at(self) -> datetime.datetime:
565655
"""Returns the scheduled event's creation time in UTC."""
566656
return utils.snowflake_time(self.id)
567657

658+
@property
659+
@deprecated(instead="scheduled_start_time", since="2.7", removed="3.0")
660+
def start_time(self) -> datetime.datetime:
661+
"""
662+
Returns the scheduled start time of the event.
663+
664+
.. deprecated:: 2.7
665+
Use :attr:`scheduled_start_time` instead.
666+
"""
667+
return self.scheduled_start_time
668+
669+
@property
670+
@deprecated(instead="scheduled_end_time", since="2.7", removed="3.0")
671+
def end_time(self) -> datetime.datetime | None:
672+
"""
673+
Returns the scheduled end time of the event.
674+
675+
.. deprecated:: 2.7
676+
Use :attr:`scheduled_end_time` instead.
677+
"""
678+
return self.scheduled_end_time
679+
680+
@property
681+
@deprecated(instead="user_count", since="2.7", removed="3.0")
682+
def subscriber_count(self) -> int | None:
683+
"""
684+
Returns the number of users subscribed to the event.
685+
686+
.. deprecated:: 2.7
687+
Use :attr:`user_count` instead.
688+
"""
689+
return self.user_count
690+
568691
@property
569692
def interested(self) -> int | None:
570693
"""An alias to :attr:`.user_count`"""
@@ -604,10 +727,14 @@ async def edit(
604727
name: str = MISSING,
605728
description: str = MISSING,
606729
status: ScheduledEventStatus = MISSING,
730+
location: (
731+
str | int | VoiceChannel | StageChannel | ScheduledEventLocation
732+
) = MISSING,
607733
entity_type: ScheduledEventEntityType = MISSING,
608734
scheduled_start_time: datetime.datetime = MISSING,
609735
scheduled_end_time: datetime.datetime = MISSING,
610736
image: bytes | None = MISSING,
737+
cover: bytes | None = MISSING,
611738
privacy_level: ScheduledEventPrivacyLevel = MISSING,
612739
entity_metadata: ScheduledEventEntityMetadata | None = MISSING,
613740
recurrence_rule: ScheduledEventRecurrenceRule | None = MISSING,
@@ -659,6 +786,11 @@ async def edit(
659786
The reason to show in the audit log.
660787
image: Optional[:class:`bytes`]
661788
The cover image of the scheduled event.
789+
cover: Optional[:class:`bytes`]
790+
The cover image of the scheduled event.
791+
792+
.. deprecated:: 2.7
793+
Use ``image`` instead.
662794
663795
Returns
664796
-------
@@ -704,6 +836,19 @@ async def edit(
704836
else:
705837
payload["recurrence_rule"] = recurrence_rule
706838

839+
if cover is not MISSING:
840+
warn_deprecated("cover", "image", "2.7", "3.0")
841+
if image is MISSING:
842+
image = cover
843+
844+
if location is not MISSING:
845+
warn_deprecated("location", "entity_metadata", "2.7", "3.0")
846+
if entity_metadata is MISSING:
847+
if not isinstance(location, (ScheduledEventLocation)):
848+
location = ScheduledEventLocation(state=self._state, value=location)
849+
if location.type == ScheduledEventEntityType.external:
850+
entity_metadata = ScheduledEventEntityMetadata(str(location))
851+
707852
if image is not MISSING:
708853
if image is None:
709854
payload["image"] = None

0 commit comments

Comments
 (0)