From 978cc753a7af0bcfed73cc3a7b7336275152ca2d Mon Sep 17 00:00:00 2001 From: Brendan Thompson Date: Sun, 23 Oct 2022 15:28:48 -0700 Subject: [PATCH 1/2] Ensure deleted files aren't added to messages --- slack2discord/parser.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/slack2discord/parser.py b/slack2discord/parser.py index 2ed34a6..dc99ff5 100644 --- a/slack2discord/parser.py +++ b/slack2discord/parser.py @@ -477,7 +477,8 @@ def parse_message(self, message, filename, channel_msgs_dict): if 'files' in message: for file in message['files']: - parsed_message.add_file(file) + if file['mode'] != 'tombstone': + parsed_message.add_file(file) if 'replies' in message: # this is the head of a thread From 3d5c3de428911be7f2582a4a9acc07917d00c611 Mon Sep 17 00:00:00 2001 From: Rich Fromm Date: Mon, 6 Feb 2023 11:31:05 -0800 Subject: [PATCH 2/2] Minor changes with respect to handling deleted files * Log a warning if deleted file is encountered. But still just pass over it, since we don't even know the name, it's not worth noting this state in Discord. * If the date deleted is included in the Slack export (empirically this seems to be the case, but none of this is documented), include that in the warning log. * Change the polarity of the check. Since the various file modes aren't documented, just skip over this on "tombstone", assume anything else is a normal attachment. Empirically, I've seen both "hosted" and "snippet". --- slack2discord/parser.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/slack2discord/parser.py b/slack2discord/parser.py index dc99ff5..460aaf6 100644 --- a/slack2discord/parser.py +++ b/slack2discord/parser.py @@ -477,7 +477,16 @@ def parse_message(self, message, filename, channel_msgs_dict): if 'files' in message: for file in message['files']: - if file['mode'] != 'tombstone': + if file.get('mode') == 'tombstone': + # File was deleted from Slack, just log this, + # don't bother mentioning this state in the Discord import. + if 'date_deleted' in file: + logger.warning("Attached file was deleted at" + f" {SlackParser.format_time(file['date_deleted'])}. Ignoring.") + else: + logger.warning(f"Attached file was deleted. Ignoring.") + else: + # Normal attached file case parsed_message.add_file(file) if 'replies' in message: