aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorEric Wang <gnawrice@gmail.com>2018-04-03 11:22:11 -0700
committerTrygve Aaberge <trygveaa@gmail.com>2018-06-07 14:45:55 +0200
commit54a61626cc438287f00bcd209571619562538ccd (patch)
tree4104c2c9918bd2079da12a4061c39d3dcf5789fc /wee_slack.py
parent69a19eae35eac1e9960b7a33c589cf22cd7d4aea (diff)
downloadwee-slack-54a61626cc438287f00bcd209571619562538ccd.tar.gz
Replace Slack links with direct links to shared files
The current links in shared file messages only show a thumbnail and require an extra click to get to the actual shared file, which is a minor annoyance. Links from external members in shared channels are also from their team's Slack subdomain, so they're inaccessible if you're not a member of their team. The direct links are from the files.slack.com subdomain though and visible to all, and the official Slack client uses them to show those files.
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/wee_slack.py b/wee_slack.py
index f6448ce..7ba22ab 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -2051,6 +2051,15 @@ class SlackMessage(object):
if message_json.get('subtype') == 'me_message' and not message_json['text'].startswith(self.sender):
message_json['text'] = self.sender + ' ' + self.message_json['text']
+ # Replace Slack link with direct link to shared file (required if
+ # shared by an external user since only the direct link is accessible)
+ if message_json.get('subtype') == 'file_share':
+ message_json['text'] = re.sub(
+ r'<http.+\|',
+ r'<{}|'.format(message_json['file']['url_private']),
+ message_json['text']
+ )
+
def __hash__(self):
return hash(self.ts)