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

Add title and description fields to Attachment #1945

Merged
merged 3 commits into from
Jun 26, 2024
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
1 change: 1 addition & 0 deletions changes/1945.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add `title` and `description` fields to `Attachment`.
2 changes: 2 additions & 0 deletions hikari/impl/entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2968,6 +2968,8 @@ def _deserialize_message_attachment(self, payload: data_binding.JSONObject) -> m
return message_models.Attachment(
id=snowflakes.Snowflake(payload["id"]),
filename=payload["filename"],
title=payload.get("title"),
description=payload.get("description"),
media_type=payload.get("content_type"),
size=int(payload["size"]),
url=payload["url"],
Expand Down
12 changes: 11 additions & 1 deletion hikari/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,17 @@ class Attachment(snowflakes.Unique, files.WebResource):
"""The source URL of file."""

filename: str = attrs.field(hash=False, eq=False, repr=True)
"""The name of the file."""
"""The filename of the file."""

title: typing.Optional[str] = attrs.field(hash=False, eq=False, repr=True)
"""The title of the file.

This will be the original filename of the attachment if it contained
non-unicode characters.
"""

description: typing.Optional[str] = attrs.field(hash=False, eq=False, repr=True)
"""The description of the file."""

media_type: typing.Optional[str] = attrs.field(hash=False, eq=False, repr=True)
"""The media type of the file."""
Expand Down
10 changes: 10 additions & 0 deletions tests/hikari/impl/test_entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -5650,6 +5650,8 @@ def attachment_payload(self):
return {
"id": "690922406474154014",
"filename": "IMG.jpg",
"title": "IMGA",
"description": "description",
"content_type": "image/png",
"size": 660521,
"url": "https://somewhere.com/attachments/123/456/IMG.jpg",
Expand Down Expand Up @@ -5719,6 +5721,8 @@ def test__deserialize_message_attachment(self, entity_factory_impl, attachment_p

assert attachment.id == 690922406474154014
assert attachment.filename == "IMG.jpg"
assert attachment.title == "IMGA"
assert attachment.description == "description"
assert attachment.size == 660521
assert attachment.media_type == "image/png"
assert attachment.url == "https://somewhere.com/attachments/123/456/IMG.jpg"
Expand All @@ -5741,6 +5745,8 @@ def test__deserialize_message_attachment_with_null_fields(self, entity_factory_i
assert isinstance(attachment, message_models.Attachment)

def test__deserialize_message_attachment_with_unset_fields(self, entity_factory_impl, attachment_payload):
del attachment_payload["title"]
del attachment_payload["description"]
del attachment_payload["content_type"]
del attachment_payload["height"]
del attachment_payload["width"]
Expand All @@ -5750,6 +5756,8 @@ def test__deserialize_message_attachment_with_unset_fields(self, entity_factory_

attachment = entity_factory_impl._deserialize_message_attachment(attachment_payload)

assert attachment.title is None
assert attachment.description is None
assert attachment.media_type is None
assert attachment.height is None
assert attachment.width is None
Expand Down Expand Up @@ -5967,6 +5975,8 @@ def test_deserialize_message(
attachment = message.attachments[0]
assert attachment.id == 690922406474154014
assert attachment.filename == "IMG.jpg"
assert attachment.title == "IMGA"
assert attachment.description == "description"
assert attachment.size == 660521
assert attachment.url == "https://somewhere.com/attachments/123/456/IMG.jpg"
assert attachment.proxy_url == "https://media.somewhere.com/attachments/123/456/IMG.jpg"
Expand Down
2 changes: 2 additions & 0 deletions tests/hikari/test_messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def test_str_operator(self):
attachment = messages.Attachment(
id=123,
filename="super_cool_file.cool",
title="other title",
description="description!",
media_type="image/png",
height=222,
width=555,
Expand Down
Loading