Skip to content

Commit

Permalink
fix: Rename 'cover' to 'image' in relation to ScheduledEvent (Pycord-…
Browse files Browse the repository at this point in the history
…Development#2496)

* fix: Rename 'cover' to 'image' in relation to ScheduledEvent

* docs: Typo

* style(pre-commit): auto fixes from pre-commit.com hooks

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Icebluewolf and pre-commit-ci[bot] authored Jul 12, 2024
1 parent ed1f73c commit c342e92
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 12 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ possible (see our [Version Guarantees] for more info).

These changes are available on the `master` branch, but have not yet been released.

### Changed

- Renamed `cover` property of `ScheduledEvent` and `cover` argument of
`ScheduledEvent.edit` to `image`.
([#2496](https://github.com/Pycord-Development/pycord/pull/2496))

## [2.6.0] - 2024-07-09

### Added
Expand Down
2 changes: 1 addition & 1 deletion discord/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def _from_user_banner(cls, state, user_id: int, banner_hash: str) -> Asset:
)

@classmethod
def _from_scheduled_event_cover(
def _from_scheduled_event_image(
cls, state, event_id: int, cover_hash: str
) -> Asset:
return cls(
Expand Down
6 changes: 3 additions & 3 deletions discord/audit_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,12 @@ def _transform_avatar(entry: AuditLogEntry, data: str | None) -> Asset | None:
return Asset._from_avatar(entry._state, entry._target_id, data) # type: ignore


def _transform_scheduled_event_cover(
def _transform_scheduled_event_image(
entry: AuditLogEntry, data: str | None
) -> Asset | None:
if data is None:
return None
return Asset._from_scheduled_event_cover(entry._state, entry._target_id, data)
return Asset._from_scheduled_event_image(entry._state, entry._target_id, data)


def _guild_hash_transformer(
Expand Down Expand Up @@ -274,7 +274,7 @@ class AuditLogChanges:
_enum_transformer(enums.ScheduledEventLocationType),
),
"command_id": ("command_id", _transform_snowflake),
"image_hash": ("cover", _transform_scheduled_event_cover),
"image_hash": ("image", _transform_scheduled_event_image),
"trigger_type": (None, _enum_transformer(enums.AutoModTriggerType)),
"event_type": (None, _enum_transformer(enums.AutoModEventType)),
"actions": (None, _transform_actions),
Expand Down
45 changes: 37 additions & 8 deletions discord/scheduled_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
ScheduledEventStatus,
try_enum,
)
from .errors import ValidationError
from .errors import InvalidArgument, ValidationError
from .iterators import ScheduledEventSubscribersIterator
from .mixins import Hashable
from .object import Object
from .utils import warn_deprecated

__all__ = (
"ScheduledEvent",
Expand Down Expand Up @@ -180,7 +181,7 @@ class ScheduledEvent(Hashable):
"location",
"guild",
"_state",
"_cover",
"_image",
"subscriber_count",
)

Expand All @@ -198,7 +199,7 @@ def __init__(
self.guild: Guild = guild
self.name: str = data.get("name")
self.description: str | None = data.get("description", None)
self._cover: str | None = data.get("image", None)
self._image: str | None = data.get("image", None)
self.start_time: datetime.datetime = datetime.datetime.fromisoformat(
data.get("scheduled_start_time")
)
Expand Down Expand Up @@ -254,13 +255,24 @@ def url(self) -> str:

@property
def cover(self) -> Asset | None:
"""
Returns the scheduled event cover image asset, if available.
.. deprecated:: 2.7
Use the :attr:`image` property instead.
"""
warn_deprecated("cover", "image", "2.7")
return self.image

@property
def image(self) -> Asset | None:
"""Returns the scheduled event cover image asset, if available."""
if self._cover is None:
if self._image is None:
return None
return Asset._from_scheduled_event_cover(
return Asset._from_scheduled_event_image(
self._state,
self.id,
self._cover,
self._image,
)

async def edit(
Expand All @@ -276,6 +288,7 @@ async def edit(
start_time: datetime.datetime = MISSING,
end_time: datetime.datetime = MISSING,
cover: bytes | None = MISSING,
image: bytes | None = MISSING,
privacy_level: ScheduledEventPrivacyLevel = ScheduledEventPrivacyLevel.guild_only,
) -> ScheduledEvent | None:
"""|coro|
Expand Down Expand Up @@ -310,9 +323,14 @@ async def edit(
so there is no need to change this parameter.
reason: Optional[:class:`str`]
The reason to show in the audit log.
image: Optional[:class:`bytes`]
The cover image of the scheduled event.
cover: Optional[:class:`bytes`]
The cover image of the scheduled event.
.. deprecated:: 2.7
Use the `image` argument instead.
Returns
-------
Optional[:class:`.ScheduledEvent`]
Expand Down Expand Up @@ -341,8 +359,19 @@ async def edit(
payload["privacy_level"] = int(privacy_level)

if cover is not MISSING:
if cover is not None:
payload["image"] = utils._bytes_to_base64_data(cover)
warn_deprecated("cover", "image", "2.7")
if image is not MISSING:
raise InvalidArgument(
"cannot pass both `image` and `cover` to `ScheduledEvent.edit`"
)
else:
image = cover

if image is not MISSING:
if image is None:
payload["image"] = None
else:
payload["image"] = utils._bytes_to_base64_data(image)

if location is not MISSING:
if not isinstance(
Expand Down
6 changes: 6 additions & 0 deletions docs/api/audit_logs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -524,5 +524,11 @@ this goal, it must make use of a couple of data classes that aid in this goal.

:type: :class:`str`

.. attribute:: image

The cover image of a :class:`ScheduledEvent`.

:type: :class:`str`

.. this is currently missing the following keys: reason and application_id
I'm not sure how to about porting these
3 changes: 3 additions & 0 deletions docs/api/enums.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1413,6 +1413,7 @@ of :class:`enum.Enum`.
- :attr:`~discord.ScheduledEvent.location`
- :attr:`~discord.ScheduledEvent.status`
- :attr:`~discord.ScheduledEventLocation.type`
- :attr:`~discord.ScheduledEvent.image`

.. versionadded:: 2.0

Expand All @@ -1433,6 +1434,7 @@ of :class:`enum.Enum`.
- :attr:`~discord.ScheduledEvent.location`
- :attr:`~discord.ScheduledEvent.status`
- :attr:`~discord.ScheduledEventLocation.type`
- :attr:`~discord.ScheduledEvent.image`

.. versionadded:: 2.0

Expand All @@ -1453,6 +1455,7 @@ of :class:`enum.Enum`.
- :attr:`~discord.ScheduledEvent.location`
- :attr:`~discord.ScheduledEvent.status`
- :attr:`~discord.ScheduledEventLocation.type`
- :attr:`~discord.ScheduledEvent.image`

.. versionadded:: 2.0

Expand Down

0 comments on commit c342e92

Please sign in to comment.