Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
Do not crash with deleted files when fetching history
Browse files Browse the repository at this point in the history
Fixes: #454
  • Loading branch information
ltworf committed Mar 20, 2024
1 parent be566a9 commit d2ff329
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,13 @@ class Response(NamedTuple):
error: Optional[str] = None


@dataclass
class DeletedFile:
file_access: Literal['file_not_found']

@dataclass
class File:
file_access: Literal['visible']
id: str
url_private: str
size: int
Expand Down Expand Up @@ -295,7 +300,7 @@ class HistoryBotMessage:
bot_id: Optional[str]
username: str = 'bot'
ts: float = 0
files: list[File] = field(default_factory=list)
files: list[File | DeletedFile] = field(default_factory=list)
thread_ts: Optional[str] = None
attachments: list[dict[str, Any]] = field(default_factory=list)

Expand All @@ -306,7 +311,7 @@ class HistoryMessage:
user: str
text: str
ts: float
files: list[File] = field(default_factory=list)
files: list[File | DeletedFile] = field(default_factory=list)
thread_ts: Optional[str] = None


Expand Down Expand Up @@ -520,7 +525,7 @@ async def _history(self) -> None:
text=msg.text,
user=msg.user,
thread_ts=msg.thread_ts,
files=msg.files,
files=[i for i in msg.files if isinstance(i, File)],
ts=msg.ts,
))
elif isinstance(msg, HistoryBotMessage):
Expand Down Expand Up @@ -820,7 +825,7 @@ async def get_thread(self, thread_ts: str, original_channel: str) -> MessageThre
user = (await self.get_user(msg.user)).name if isinstance(msg, HistoryMessage) else 'bot'

# Top message is a file
if msg.text == '' and msg.files:
if msg.text == '' and msg.files and isinstance(msg.files[0], File):
f = msg.files[0]
original_txt = f'{f.title} {f.mimetype} {f.url_private}'
else:
Expand Down

0 comments on commit d2ff329

Please sign in to comment.