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

Commit

Permalink
Merge pull request #455 from ltworf/deleted_files
Browse files Browse the repository at this point in the history
Do not crash when encountering deleted files
  • Loading branch information
ltworf authored Mar 20, 2024
2 parents 84cf61d + d2ff329 commit 8fb5924
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
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

0 comments on commit 8fb5924

Please sign in to comment.