richfromm / slack2discord

A Discord client that imports Slack-exported JSON chat history to Discord channel(s).
GNU General Public License v3.0
8 stars 3 forks source link

Add support for files attached to messages #18

Closed richfromm closed 2 years ago

richfromm commented 2 years ago

Files are accounted for during parsing with a list of (new) MessageFile objects added to ParsedMessage objects.

A new step is added between parsing and running the Discord client, which is to download all of the files from Slack to the local filesystem via the (new) SlackDownloader (see downloader.py). Files by default go to a uniquely named timestamp dir (to second level accuracy) in a subdir of a downloads subdir relative to the slack2discord.py script. This can be overridden with a new optional arg, --downloads_dir.

This introduces a new library dependency, requests.

The downloads all happen serially, in a blocking manner. This could be made faster using aiohttp to do asynchronous downloading of multiple files simultaneously, but that is way out of the current scope.

Messages with attached files (whether or not there is any message text present) appear to empirically lack sufficient information for us to properly get the poster's name via the JSON representing just the message. (See SlackParser.get_name()) We end up falling back to the user property, which is just a user id from which we strip the leading U. This is okay for now, but less than ideal. A better plan would be to use the file users.json in the top level of the Slack export to look up user name info based on Slack user id. This will come next, but is out of the current scope.