diff options
author | Ryan Huber <rhuber@gmail.com> | 2015-11-17 09:32:19 -0800 |
---|---|---|
committer | Ryan Huber <rhuber@gmail.com> | 2015-11-17 09:32:19 -0800 |
commit | d04ef011b7f02f5d0d1dd7f561d5ed732f9e8ecc (patch) | |
tree | 04119291e430cdba62b33fc57bafaae466259917 /wee_slack.py | |
parent | 3136eddce90e97f886e9eb9cb76014d969dd2857 (diff) | |
parent | c79e62cc8f2579fee4f7345dd5b79617d3a5eb6b (diff) | |
download | wee-slack-d04ef011b7f02f5d0d1dd7f561d5ed732f9e8ecc.tar.gz |
Merge pull request #108 from kenyonj/jk-add-upload-option
Add upload capability to slack buffer
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/wee_slack.py b/wee_slack.py index 812c94c..2d2fb2b 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -4,6 +4,7 @@ from functools import wraps import time import json +import os import pickle import sha import re @@ -904,6 +905,26 @@ def slack_buffer_required(f): @slack_buffer_required +def command_upload(current_buffer, args): + """ + Uploads a file to the current buffer + /slack upload [file_path] + """ + post_data = {} + channel = current_buffer_name(short=True) + domain = current_domain_name() + token = servers.find(domain).token + + if servers.find(domain).channels.find(channel): + channel_identifier = servers.find(domain).channels.find(channel).identifier + + if channel_identifier: + post_data["token"] = token + post_data["channels"] = channel_identifier + post_data["file"] = args + async_slack_api_upload_request(token, "files.upload", post_data) + +@slack_buffer_required def command_talk(current_buffer, args): """ Open a chat with the specified user @@ -1734,6 +1755,14 @@ def async_slack_api_request(domain, token, request, post_data, priority=False): dbg("URL: {} context: {} params: {}".format(url, context, params)) w.hook_process_hashtable(url, params, 20000, "url_processor_cb", context) +def async_slack_api_upload_request(token, request, post_data, priority=False): + if not STOP_TALKING_TO_SLACK: + url = 'https://slack.com/api/{}'.format(request) + file_path = os.path.expanduser(post_data["file"]) + command = 'curl -F file=@{} -F channels={} -F token={} {}'.format(file_path, post_data["channels"], token, url) + context = pickle.dumps({"request": request, "token": token, "post_data": post_data}) + w.hook_process(command, 20000, "url_processor_cb", context) + # funny, right? big_data = {} |