From be566a9ea9702c98622f101cdffa5b5501b76b60 Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Wed, 20 Mar 2024 15:31:41 +0100 Subject: [PATCH 1/2] CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 640bbab..f435482 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,5 @@ 1.29 +* Do not crash when encountering deleted files 1.28 * Do not crash on errors with last known timestamp From d2ff3292ff9cab7258ceb4ba9cf332007a1dd1bc Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Wed, 20 Mar 2024 15:30:59 +0100 Subject: [PATCH 2/2] Do not crash with deleted files when fetching history Fixes: #454 --- slack.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/slack.py b/slack.py index 07aa049..f0cad5d 100644 --- a/slack.py +++ b/slack.py @@ -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 @@ -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) @@ -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 @@ -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): @@ -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: