|
41 | 41 | from .errors import ValidationError |
42 | 42 | from .iterators import ScheduledEventSubscribersIterator |
43 | 43 | from .mixins import Hashable |
44 | | -from .utils import warn_deprecated |
| 44 | +from .object import Object |
| 45 | +from .utils import warn_deprecated, deprecated |
45 | 46 |
|
46 | 47 | __all__ = ( |
47 | 48 | "ScheduledEvent", |
| 49 | + "ScheduledEventLocation", |
48 | 50 | "ScheduledEventEntityMetadata", |
49 | 51 | "ScheduledEventRecurrenceRule", |
50 | 52 | "ScheduledEventRecurrenceNWeekday", |
51 | 53 | ) |
52 | 54 |
|
53 | 55 | if TYPE_CHECKING: |
54 | 56 | from .abc import Snowflake |
| 57 | + from .channel import StageChannel, VoiceChannel |
55 | 58 | from .guild import Guild |
56 | 59 | from .member import Member |
57 | 60 | from .state import ConnectionState |
58 | 61 | from .types.scheduled_events import ScheduledEvent as ScheduledEventPayload |
59 | 62 | from .types.scheduled_events import ( |
60 | 63 | ScheduledEventRecurrenceRule as ScheduledEventRecurrenceRulePayload, |
61 | 64 | ) |
| 65 | +else: |
| 66 | + ConnectionState = None |
| 67 | + StageChannel = None |
| 68 | + VoiceChannel = None |
62 | 69 |
|
63 | 70 | MISSING = utils.MISSING |
64 | 71 |
|
65 | 72 |
|
| 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 | + |
66 | 142 | class ScheduledEventEntityMetadata: |
67 | 143 | """Represents a scheduled event's entity metadata. |
68 | 144 |
|
@@ -477,7 +553,6 @@ class ScheduledEvent(Hashable): |
477 | 553 | "status", |
478 | 554 | "creator_id", |
479 | 555 | "creator", |
480 | | - "location", |
481 | 556 | "guild", |
482 | 557 | "_state", |
483 | 558 | "_image", |
@@ -560,11 +635,59 @@ def __repr__(self) -> str: |
560 | 635 | f"channel_id={self.channel_id}>" |
561 | 636 | ) |
562 | 637 |
|
| 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 | + |
563 | 653 | @property |
564 | 654 | def created_at(self) -> datetime.datetime: |
565 | 655 | """Returns the scheduled event's creation time in UTC.""" |
566 | 656 | return utils.snowflake_time(self.id) |
567 | 657 |
|
| 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 | + |
568 | 691 | @property |
569 | 692 | def interested(self) -> int | None: |
570 | 693 | """An alias to :attr:`.user_count`""" |
@@ -604,10 +727,14 @@ async def edit( |
604 | 727 | name: str = MISSING, |
605 | 728 | description: str = MISSING, |
606 | 729 | status: ScheduledEventStatus = MISSING, |
| 730 | + location: ( |
| 731 | + str | int | VoiceChannel | StageChannel | ScheduledEventLocation |
| 732 | + ) = MISSING, |
607 | 733 | entity_type: ScheduledEventEntityType = MISSING, |
608 | 734 | scheduled_start_time: datetime.datetime = MISSING, |
609 | 735 | scheduled_end_time: datetime.datetime = MISSING, |
610 | 736 | image: bytes | None = MISSING, |
| 737 | + cover: bytes | None = MISSING, |
611 | 738 | privacy_level: ScheduledEventPrivacyLevel = MISSING, |
612 | 739 | entity_metadata: ScheduledEventEntityMetadata | None = MISSING, |
613 | 740 | recurrence_rule: ScheduledEventRecurrenceRule | None = MISSING, |
@@ -659,6 +786,11 @@ async def edit( |
659 | 786 | The reason to show in the audit log. |
660 | 787 | image: Optional[:class:`bytes`] |
661 | 788 | 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. |
662 | 794 |
|
663 | 795 | Returns |
664 | 796 | ------- |
@@ -704,6 +836,19 @@ async def edit( |
704 | 836 | else: |
705 | 837 | payload["recurrence_rule"] = recurrence_rule |
706 | 838 |
|
| 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 | + |
707 | 852 | if image is not MISSING: |
708 | 853 | if image is None: |
709 | 854 | payload["image"] = None |
|
0 commit comments