Skip to content

Commit

Permalink
fix: images sending as 0 bytes in paginator if sent as io.BytesIO (#…
Browse files Browse the repository at this point in the history
…1881)

Signed-off-by: Yaakov Schlachter <[email protected]>
Signed-off-by: BobDotCom <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Lala Sabathil <[email protected]>
Co-authored-by: BobDotCom <[email protected]>
Co-authored-by: plun1331 <[email protected]>
  • Loading branch information
5 people authored Jan 18, 2023
1 parent 321c491 commit 3941b31
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ These changes are available on the `master` branch, but have not yet been releas

### Fixed

- Fixed a bug in `Page.update_files` where file objects stored in memory were causing an
`AttributeError`. ([#1869](https://github.com/Pycord-Development/pycord/pull/1869))
- Fixed bugs in `Page.update_files` where file objects stored in memory were causing an
`AttributeError`, and `io.BytesIO` files didn't send properly more than once.
([#1869](https://github.com/Pycord-Development/pycord/pull/1869) &
[#1881](https://github.com/Pycord-Development/pycord/pull/1881))

## [2.3.2] - 2022-12-03

Expand Down
18 changes: 6 additions & 12 deletions discord/ext/pages/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"""
from __future__ import annotations

from io import BufferedReader
from typing import List

import discord
Expand Down Expand Up @@ -169,19 +168,14 @@ async def callback(self, interaction: discord.Interaction | None = None):
"""

def update_files(self) -> list[discord.File] | None:
"""Re-opens and reads new file contents for local files if they were updated.
Typically used when the page is changed.
"""Updates :class:`discord.File` objects so that they can be sent multiple
times. This is called internally each time the page is sent.
"""
for file in self._files:
if not isinstance(file.fp, BufferedReader):
continue
with open(file.fp.name, "rb") as fp: # type: ignore
self._files[self._files.index(file)] = discord.File(
fp, # type: ignore
filename=file.filename,
description=file.description,
spoiler=file.spoiler,
)
if file.fp.closed and (fn := getattr(file.fp, "name", None)):
file.fp = open(fn, "rb")
file.reset()
file.fp.close = lambda: None
return self._files

@property
Expand Down

0 comments on commit 3941b31

Please sign in to comment.