aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2015-10-18 22:16:55 +0200
committerTrygve Aaberge <trygveaa@gmail.com>2015-10-18 22:29:34 +0200
commit9f44b42909fad03a59fa63ed5bade76ca6bf29fb (patch)
tree1939d93d12729079fd184c6adae31ddc6981b864 /wee_slack.py
parent2d50c4e59ae603706840ea42ec1e718c62232458 (diff)
downloadwee-slack-9f44b42909fad03a59fa63ed5bade76ca6bf29fb.tar.gz
Use weechat for requests instead of curl
Weechat has (since version 0.3.7) a builtin method for plugins to download from URLs. This commit replaces the use of the curl command with this. There are two main reasons for doing this: - When using an external command, the arguments are visible to all users of the machine, including the token for connecting to Slack. - It removes the need to depend on curl.
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/wee_slack.py b/wee_slack.py
index db4b178..0eb8eff 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -1707,14 +1707,13 @@ def complete_next_cb(data, buffer, command):
# Slack specific requests
-# NOTE: switched to async/curl because sync slowed down the UI
+# NOTE: switched to async because sync slowed down the UI
def async_slack_api_request(domain, token, request, post_data, priority=False):
if not STOP_TALKING_TO_SLACK:
post_data["token"] = token
url = 'https://{}/api/{}'.format(domain, request)
- command = 'curl -A "wee_slack {}" -s --data "{}" {}'.format(SCRIPT_VERSION, urllib.urlencode(post_data), url)
context = pickle.dumps({"request": request, "token": token, "post_data": post_data})
- w.hook_process(command, 20000, "url_processor_cb", context)
+ w.hook_process("url:{}?{}".format(url, urllib.urlencode(post_data)), 20000, "url_processor_cb", context)
# funny, right?
big_data = {}
@@ -1730,8 +1729,8 @@ def url_processor_cb(data, command, return_code, out, err):
try:
my_json = json.loads(big_data[identifier])
except:
- dbg("curl failed, doing again...")
- dbg("curl length: {} identifier {}\n{}".format(len(big_data[identifier]), identifier, data))
+ dbg("request failed, doing again...")
+ dbg("response length: {} identifier {}\n{}".format(len(big_data[identifier]), identifier, data))
my_json = False
big_data.pop(identifier, None)