aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py36
1 files changed, 33 insertions, 3 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 7613769..4593e65 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -13,6 +13,8 @@ import HTMLParser
import sys
import traceback
import collections
+import ssl
+
from websocket import create_connection,WebSocketConnectionClosedException
# hack to make tests possible.. better way?
@@ -58,6 +60,12 @@ SLACK_API_TRANSLATOR = {
NICK_GROUP_HERE = "0|Here"
NICK_GROUP_AWAY = "1|Away"
+sslopt_ca_certs = {}
+if hasattr(ssl, "get_default_verify_paths") and callable(ssl.get_default_verify_paths):
+ ssl_defaults = ssl.get_default_verify_paths()
+ if ssl_defaults.cafile is not None:
+ sslopt_ca_certs = {'ca_certs': ssl_defaults.cafile}
+
def dbg(message, fout=False, main_buffer=False):
"""
send debug output to the slack-debug buffer and optionally write to a file.
@@ -139,6 +147,7 @@ class SlackServer(object):
self.communication_counter = 0
self.message_buffer = {}
self.ping_hook = None
+ self.alias = None
self.identifier = None
self.connect_to_slack()
@@ -167,7 +176,7 @@ class SlackServer(object):
channels.append(channel, channel.get_aliases())
def get_aliases(self):
- aliases = [self.identifier, self.token, self.buffer]
+ aliases = filter(None, [self.identifier, self.token, self.buffer, self.alias])
return aliases
def find(self, name, attribute):
@@ -211,6 +220,7 @@ class SlackServer(object):
alias = w.config_get_plugin("server_alias.{}".format(login_data["team"]["domain"]))
if alias:
self.server_buffer_name = alias
+ self.alias = alias
else:
self.server_buffer_name = self.domain
@@ -256,12 +266,14 @@ class SlackServer(object):
def create_local_buffer(self):
if not w.buffer_search("", self.server_buffer_name):
self.buffer = w.buffer_new(self.server_buffer_name, "buffer_input_cb", "", "", "")
+ if w.config_string(w.config_get('irc.look.server_buffer')) == 'merge_with_core':
+ w.buffer_merge(self.buffer, w.buffer_search_main())
w.buffer_set(self.buffer, "nicklist", "1")
def create_slack_websocket(self, data):
web_socket_url = data['url']
try:
- self.ws = create_connection(web_socket_url)
+ self.ws = create_connection(web_socket_url, sslopt=sslopt_ca_certs)
self.ws_hook = w.hook_fd(self.ws.sock._sock.fileno(), 1, 0, 0, "slack_websocket_cb", self.identifier)
self.ws.sock.setblocking(0)
return True
@@ -991,6 +1003,23 @@ def slack_buffer_required(f):
@slack_buffer_required
+def msg_command_cb(data, current_buffer, args):
+ dbg("msg_command_cb")
+ aargs = args.split(None, 2)
+ who = aargs[1]
+
+ command_talk(current_buffer, who)
+
+ if len(aargs) > 2:
+ message = aargs[2]
+ server = servers.find(current_domain_name())
+ if server:
+ channel = server.channels.find(who)
+ channel.send_message(message)
+ return w.WEECHAT_RC_OK_EAT
+
+
+@slack_buffer_required
def command_upload(current_buffer, args):
"""
Uploads a file to the current buffer
@@ -1019,7 +1048,7 @@ def command_talk(current_buffer, args):
server = servers.find(current_domain_name())
if server:
channel = server.channels.find(args)
- if channel:
+ if not channel:
channel.open()
else:
user = server.users.find(args)
@@ -2225,6 +2254,7 @@ if __name__ == "__main__":
w.hook_command_run('/part', 'part_command_cb', '')
w.hook_command_run('/leave', 'part_command_cb', '')
w.hook_command_run('/topic', 'topic_command_cb', '')
+ w.hook_command_run('/msg', 'msg_command_cb', '')
w.hook_command_run("/input complete_next", "complete_next_cb", "")
w.hook_completion("nicks", "complete @-nicks for slack",
"nick_completion_cb", "")