Skip to content

Commit

Permalink
feat: add name param to download_file method (#167)
Browse files Browse the repository at this point in the history
  • Loading branch information
rrrrs09 committed Sep 9, 2021
1 parent be2f496 commit 4d0d827
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
12 changes: 10 additions & 2 deletions botx/bots/mixins/requests/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ async def upload_file( # noqa: WPS211
credentials=credentials,
)

async def download_file(
async def download_file( # noqa: WPS211
self: BotXMethodCallProtocol,
credentials: SendingCredentials,
file_id: UUID,
group_chat_id: UUID,
*,
file_name: Optional[str] = None,
is_preview: bool = False,
) -> File:
"""Download file from the chat.
Expand All @@ -64,16 +65,23 @@ async def download_file(
credentials: credentials for making request.
file_id: ID of the file.
group_chat_id: ID of the chat that accepts the file.
file_name: file name to be assigned instead of default name.
is_preview: get preview or file.
Returns:
Downloaded file.
"""
return await self.call_method(
file = await self.call_method(
DownloadFile(
file_id=file_id,
group_chat_id=group_chat_id,
is_preview=is_preview,
),
credentials=credentials,
)

if file_name:
ext = file.file_name.split(".", maxsplit=1)[1]
file.file_name = "{name}.{ext}".format(name=file_name, ext=ext)

return file
7 changes: 7 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.23.2 (Sep 09, 2021)

### Added

* Add `file_name` param to `download_file` method to provide ability to change the returned file name.


## 0.23.1 (Aug 30, 2021)

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "botx"
version = "0.23.1"
version = "0.23.2"
description = "A little python framework for building bots for eXpress"
license = "MIT"
authors = [
Expand Down
11 changes: 11 additions & 0 deletions tests/test_bots/test_mixins/test_requests/test_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,14 @@ async def test_download_file(client, message):
)

assert isinstance(client.requests[0], DownloadFile)


async def test_custom_filename(client, message):
file = await client.bot.download_file(
message.credentials,
file_id=uuid4(),
group_chat_id=uuid4(),
file_name="myname",
)

assert file.file_name == "myname.txt"

1 comment on commit 4d0d827

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎉 Published on https://pybotx.netlify.app as production
🚀 Deployed on https://6139d3d485f956ca8d1623ac--pybotx.netlify.app

Please sign in to comment.