aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorJosip Janzic <josip@jjanzic.com>2018-10-21 23:40:39 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2019-02-15 00:06:02 +0100
commite0598897a0d87fe391d5f4e2ad145b33921c6773 (patch)
tree097529bf999c039423ec4fa4254c3f26edcfe580 /wee_slack.py
parent9c178fb3346550f547e9198dbaca05f871ff85f5 (diff)
downloadwee-slack-e0598897a0d87fe391d5f4e2ad145b33921c6773.tar.gz
Add option to download files locally
Useful when running wee-slack without a open session in a browser/app.
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 74027a5..babbccf 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -2617,6 +2617,23 @@ def process_message(message_json, eventrouter, store=True, **kwargs):
channel.store_message(message, team)
dbg("NORMAL REPLY {}".format(message_json))
+ download_location = config.get_string('files_download_location')
+ if not download_location:
+ return
+
+ for f in message_json.get('files', []):
+ if f.get('mode', '') == 'tombstone':
+ continue
+
+ file_name = '{}_{}.{}'.format(f['id'], f['title'], f['filetype'])
+ weechat.hook_process_hashtable(
+ "url:" + f['url_private'],
+ {
+ 'file_out': os.path.join(download_location, file_name),
+ 'httpheader': 'Authorization: Bearer ' + team.token
+ },
+ config.slack_timeout, "", "")
+
def subprocess_thread_message(message_json, eventrouter, channel, team):
# print ("THREADED: " + str(message_json))
@@ -4066,6 +4083,9 @@ class PluginConfig(object):
'external_user_suffix': Setting(
default='*',
desc='The suffix appended to nicks to indicate external users.'),
+ 'files_download_location': Setting(
+ default='',
+ desc='If set, file attachments will be downloaded to this location.'),
'group_name_prefix': Setting(
default='&',
desc='The prefix of buffer names for groups (private channels).'),