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

Do not crash when encountering deleted files #455

Merged
merged 2 commits into from
Mar 20, 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 CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
1.29
* Do not crash when encountering deleted files

1.28
* Do not crash on errors with last known timestamp
Expand Down
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
Loading