aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md8
-rw-r--r--wee_slack.py29
2 files changed, 36 insertions, 1 deletions
diff --git a/README.md b/README.md
index 5442ae7..b3b5aaa 100644
--- a/README.md
+++ b/README.md
@@ -12,7 +12,8 @@ A WeeChat native client for Slack.com. Provides supplemental features only avail
Features
--------
- * **New** Emoji reactions!
+ * **New** Upload to slack capabilities!
+ * Emoji reactions!
* Edited messages work just like the official clients, where the original message changes and has (edited) appended.
* Unfurled urls dont generate a new message, but replace the original with more info as it is received.
* Regex style message editing (s/oldtext/newtext/)
@@ -169,6 +170,11 @@ Set all read markers to a specific time:
/slack setallreadmarkers (time in epoch)
```
+Upload a file to the current slack buffer:
+```
+/slack upload [file_path]
+```
+
Debug mode:
```
/slack debug
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 = {}