Skip to content

Commit

Permalink
apply new fix
Browse files Browse the repository at this point in the history
  • Loading branch information
BobDotCom committed Jan 17, 2023
1 parent d7eaa02 commit 2ddab49
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 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,26 +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):
file.fp.seek(0)
self._files[self._files.index(file)] = discord.File(
file.fp, # type: ignore
filename=file.filename,
description=file.description,
spoiler=file.spoiler,
)
else:
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 2ddab49

Please sign in to comment.