aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
authorRyan Huber <rhuber@gmail.com>2016-09-28 10:48:07 -0700
committerRyan Huber <rhuber@gmail.com>2016-09-28 10:48:07 -0700
commit48e969c638c2ef22124f83806bc8c3a0a1d08bfe (patch)
tree2d7f6011d5d51c1d275942ff8136fb7408039eec /wee_slack.py
parente561bc54d36d897d6c46e328141100d8ee80a1b4 (diff)
downloadwee-slack-48e969c638c2ef22124f83806bc8c3a0a1d08bfe.tar.gz
pep8 errything
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py169
1 files changed, 107 insertions, 62 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 68c8284..48d487d 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -2,6 +2,7 @@
#
from functools import wraps
+
import time
import json
import os
@@ -15,7 +16,7 @@ import traceback
import collections
import ssl
-from websocket import create_connection,WebSocketConnectionClosedException
+from websocket import create_connection, WebSocketConnectionClosedException
# hack to make tests possible.. better way?
try:
@@ -66,12 +67,13 @@ if hasattr(ssl, "get_default_verify_paths") and callable(ssl.get_default_verify_
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.
"""
message = "DEBUG: {}".format(message)
- #message = message.encode('utf-8', 'replace')
+ # message = message.encode('utf-8', 'replace')
if fout:
file('/tmp/debug.log', 'a+').writelines(message + '\n')
if main_buffer:
@@ -92,7 +94,7 @@ class SearchList(list):
def find(self, name):
if name in self.hashtable:
return self.hashtable[name]
- #this is a fallback to __eq__ if the item isn't in the hashtable already
+ # this is a fallback to __eq__ if the item isn't in the hashtable already
if self.count(name) > 0:
self.update_hashtable()
return self[self.index(name)]
@@ -219,7 +221,7 @@ class SlackServer(object):
def connect_to_slack(self):
t = time.time()
- #Double check that we haven't exceeded a long wait to connect and try again.
+ # Double check that we haven't exceeded a long wait to connect and try again.
if self.connecting and self.should_connect():
self.connecting = False
if not self.connecting:
@@ -262,7 +264,7 @@ class SlackServer(object):
resend = self.message_buffer.pop(message_id)
dbg("Resent failed message.")
self.send_to_websocket(resend)
- #sleep to prevent being disconnected by websocket server
+ # sleep to prevent being disconnected by websocket server
time.sleep(1)
else:
self.message_buffer.pop(message_id)
@@ -360,7 +362,8 @@ class SlackServer(object):
w.prnt_date_tags(self.buffer, 0, tags, "{}\t{}".format(user, message))
else:
pass
- #w.prnt("", "%s\t%s" % (user, message))
+ # w.prnt("", "%s\t%s" % (user, message))
+
def buffer_input_cb(b, buffer, data):
channel = channels.find(buffer)
@@ -369,7 +372,7 @@ def buffer_input_cb(b, buffer, data):
reaction = re.match("(\d*)(\+|-):(.*):", data)
if not reaction and not data.startswith('s/'):
channel.send_message(data)
- #channel.buffer_prnt(channel.server.nick, data)
+ # channel.buffer_prnt(channel.server.nick, data)
elif reaction:
if reaction.group(2) == "+":
channel.send_add_reaction(int(reaction.group(1) or 1), reaction.group(3))
@@ -478,8 +481,8 @@ class Channel(object):
w.buffer_set(self.channel_buffer, "nicklist", "1")
- #create nicklists for the current channel if they don't exist
- #if they do, use the existing pointer
+ # create nicklists for the current channel if they don't exist
+ # if they do, use the existing pointer
here = w.nicklist_search_group(self.channel_buffer, '', NICK_GROUP_HERE)
if not here:
here = w.nicklist_add_group(self.channel_buffer, '', NICK_GROUP_HERE, "weechat.color.nicklist_group", 1)
@@ -490,15 +493,15 @@ class Channel(object):
if user:
user = self.members_table[user]
nick = w.nicklist_search_nick(self.channel_buffer, "", user.name)
- #since this is a change just remove it regardless of where it is
+ # since this is a change just remove it regardless of where it is
w.nicklist_remove_nick(self.channel_buffer, nick)
- #now add it back in to whichever..
+ # now add it back in to whichever..
if user.presence == 'away':
w.nicklist_add_nick(self.channel_buffer, afk, user.name, user.color_name, "", "", 1)
else:
w.nicklist_add_nick(self.channel_buffer, here, user.name, user.color_name, "", "", 1)
- #if we didn't get a user, build a complete list. this is expensive.
+ # if we didn't get a user, build a complete list. this is expensive.
else:
try:
for user in self.members:
@@ -589,13 +592,13 @@ class Channel(object):
async_slack_api_request(self.server.domain, self.server.token, SLACK_API_TRANSLATOR[self.type]["join"], {"user": users.find(self.name).identifier})
def close(self, update_remote=True):
- #remove from cache so messages don't reappear when reconnecting
+ # remove from cache so messages don't reappear when reconnecting
if self.active:
self.active = False
self.current_short_name = ""
self.detach_buffer()
if update_remote:
- t = time.time()
+ # t = time.time()
async_slack_api_request(self.server.domain, self.server.token, SLACK_API_TRANSLATOR[self.type]["leave"], {"channel": self.identifier})
def closed(self):
@@ -620,7 +623,7 @@ class Channel(object):
return typing
def mark_read(self, update_remote=True):
- t = time.time()
+ # t = time.time()
if self.channel_buffer:
w.buffer_set(self.channel_buffer, "unread", "")
@@ -662,8 +665,8 @@ class Channel(object):
tags = ",irc_smart_filter"
else:
tags = ",notify_message,log1,irc_privmsg"
- #don't write these to local log files
- #tags += ",no_log"
+ # don't write these to local log files
+ # tags += ",no_log"
time_int = int(time_float)
if self.channel_buffer:
prefix_same_nick = w.config_string(w.config_get('weechat.look.prefix_same_nick'))
@@ -685,10 +688,10 @@ class Channel(object):
self.last_active_user = None
name = nick_prefix + name + nick_suffix
name = name.decode('utf-8')
- #colorize nicks in each line
+ # colorize nicks in each line
chat_color = w.config_string(w.config_get('weechat.color.chat'))
if type(message) is not unicode:
- message = message.decode('UTF-8', 'replace')
+ message = message.decode('UTF-8', 'replace')
curr_color = w.color(chat_color)
if colorize_nicks and colorize_messages and self.server.users.find(user):
curr_color = self.server.users.find(user).color
@@ -734,12 +737,12 @@ class Channel(object):
self.messages[message_index].change_text(text)
text = render_message(self.messages[message_index].message_json, True)
- #if there is only one message with this timestamp, modify it directly.
- #we do this because time resolution in weechat is less than slack
+ # if there is only one message with this timestamp, modify it directly.
+ # we do this because time resolution in weechat is less than slack
int_time = int(float(ts))
if self.messages.count(str(int_time)) == 1:
modify_buffer_line(self.channel_buffer, text + suffix, int_time)
- #otherwise redraw the whole buffer, which is expensive
+ # otherwise redraw the whole buffer, which is expensive
else:
self.buffer_redraw()
return True
@@ -794,7 +797,7 @@ class Channel(object):
if self.active:
for message in message_cache[self.identifier]:
process_message(json.loads(message), True)
- if self.last_received != None:
+ if self.last_received is not None:
async_slack_api_request(self.server.domain, self.server.token, SLACK_API_TRANSLATOR[self.type]["history"], {"channel": self.identifier, "oldest": self.last_received, "count": BACKLOG_SIZE})
else:
async_slack_api_request(self.server.domain, self.server.token, SLACK_API_TRANSLATOR[self.type]["history"], {"channel": self.identifier, "count": BACKLOG_SIZE})
@@ -806,6 +809,7 @@ class GroupChannel(Channel):
super(GroupChannel, self).__init__(server, name, identifier, active, last_read, prepend_name, members, topic)
self.type = "group"
+
class MpdmChannel(Channel):
def __init__(self, server, name, identifier, active, last_read=0, prepend_name="", members=[], topic=""):
@@ -813,6 +817,7 @@ class MpdmChannel(Channel):
super(MpdmChannel, self).__init__(server, name, identifier, active, last_read, prepend_name, members, topic)
self.type = "group"
+
class DmChannel(Channel):
def __init__(self, server, name, identifier, active, last_read=0, prepend_name=""):
@@ -835,6 +840,7 @@ class DmChannel(Channel):
def update_nicklist(self, user=None):
pass
+
class User(object):
def __init__(self, server, name, identifier, presence="away", deleted=False, is_bot=False):
@@ -923,6 +929,7 @@ class User(object):
def create_dm_channel(self):
async_slack_api_request(self.server.domain, self.server.token, "im.open", {"user": self.identifier})
+
class Bot(object):
def __init__(self, server, name, identifier, deleted=False):
@@ -959,12 +966,13 @@ class Bot(object):
print_color = ""
return print_color + prepend + self.name
+
class Message(object):
def __init__(self, message_json):
self.message_json = message_json
self.ts = message_json['ts']
- #split timestamp into time and counter
+ # split timestamp into time and counter
self.ts_time, self.ts_counter = message_json['ts'].split('.')
def change_text(self, new_text):
@@ -1003,6 +1011,8 @@ class Message(object):
return self.ts < other.ts
# Only run this function if we're in a slack buffer, else ignore
+
+
def slack_buffer_or_ignore(f):
@wraps(f)
def wrapper(current_buffer, *args, **kwargs):
@@ -1021,7 +1031,7 @@ def slack_command_cb(data, current_buffer, args):
function_name, args = a[0], None
try:
- command = cmds[function_name](current_buffer, args)
+ cmds[function_name](current_buffer, args)
except KeyError:
w.prnt("", "Command not found: " + function_name)
return w.WEECHAT_RC_OK
@@ -1030,8 +1040,8 @@ def slack_command_cb(data, current_buffer, args):
@slack_buffer_or_ignore
def me_command_cb(data, current_buffer, args):
if channels.find(current_buffer):
- channel = channels.find(current_buffer)
- nick = channel.server.nick
+ # channel = channels.find(current_buffer)
+ # nick = channel.server.nick
message = "_{}_".format(args)
buffer_input_cb("", current_buffer, message)
return w.WEECHAT_RC_OK
@@ -1048,6 +1058,7 @@ def join_command_cb(data, current_buffer, args):
else:
return w.WEECHAT_RC_OK
+
@slack_buffer_or_ignore
def part_command_cb(data, current_buffer, args):
if channels.find(current_buffer) or servers.find(current_buffer):
@@ -1073,12 +1084,13 @@ def slack_buffer_required(f):
return f(current_buffer, *args, **kwargs)
return wrapper
+
def command_register(current_buffer, args):
- CLIENT_ID="2468770254.51917335286"
- CLIENT_SECRET="dcb7fe380a000cba0cca3169a5fe8d70" #this is not really a secret
+ CLIENT_ID = "2468770254.51917335286"
+ CLIENT_SECRET = "dcb7fe380a000cba0cca3169a5fe8d70" # this is not really a secret
if not args:
message = """
-#### Retrieving a Slack token via OAUTH ####
+# ### Retrieving a Slack token via OAUTH ####
1) Paste this into a browser: https://slack.com/oauth/authorize?client_id=2468770254.51917335286&scope=client
2) Select the team you wish to access from wee-slack in your browser.
@@ -1092,10 +1104,10 @@ def command_register(current_buffer, args):
w.prnt(current_buffer, message)
else:
aargs = args.split(None, 2)
- if len(aargs) <> 1:
+ if len(aargs) != 1:
w.prnt(current_buffer, "ERROR: invalid args to register")
else:
- #w.prnt(current_buffer, "https://slack.com/api/oauth.access?client_id={}&client_secret={}&code={}".format(CLIENT_ID, CLIENT_SECRET, aargs[0]))
+ # w.prnt(current_buffer, "https://slack.com/api/oauth.access?client_id={}&client_secret={}&code={}".format(CLIENT_ID, CLIENT_SECRET, aargs[0]))
ret = urllib.urlopen("https://slack.com/api/oauth.access?client_id={}&client_secret={}&code={}".format(CLIENT_ID, CLIENT_SECRET, aargs[0])).read()
d = json.loads(ret)
if d["ok"] == True:
@@ -1141,6 +1153,7 @@ def command_upload(current_buffer, args):
post_data["file"] = args
async_slack_api_upload_request(token, "files.upload", post_data)
+
def command_talk(current_buffer, args):
"""
Open a chat with the specified user
@@ -1164,6 +1177,7 @@ def command_talk(current_buffer, args):
else:
return False
+
def command_join(current_buffer, args):
"""
Join the specified channel
@@ -1177,7 +1191,7 @@ def command_join(current_buffer, args):
w.prnt(current_buffer, "You are connected to multiple Slack instances, please execute /join from a server buffer. i.e. (domain).slack.com")
return
channel = servers.find(domain).channels.find(args)
- if channel != None:
+ if channel is not None:
servers.find(domain).channels.find(args).open()
else:
w.prnt(current_buffer, "Channel not found.")
@@ -1243,6 +1257,7 @@ def command_setallreadmarkers(current_buffer, args):
for channel in channels:
channel.mark_read()
+
def command_changetoken(current_buffer, args):
w.config_set_plugin('slack_api_token', args)
@@ -1283,13 +1298,16 @@ def command_markread(current_buffer, args):
if servers.find(domain).channels.find(channel):
servers.find(domain).channels.find(channel).mark_read()
+
def command_flushcache(current_buffer, args):
global message_cache
message_cache = collections.defaultdict(list)
- cache_write_cb("","")
+ cache_write_cb("", "")
+
def command_cachenow(current_buffer, args):
- cache_write_cb("","")
+ cache_write_cb("", "")
+
def command_neveraway(current_buffer, args):
global never_away
@@ -1345,11 +1363,11 @@ def command_nick(current_buffer, args):
def command_help(current_buffer, args):
- help_cmds = { k[8:]: v.__doc__ for k, v in globals().items() if k.startswith("command_") }
+ help_cmds = {k[8:]: v.__doc__ for k, v in globals().items() if k.startswith("command_")}
if args:
try:
- help_cmds = {args: help_cmds[args]}
+ help_cmds = {args: help_cmds[args]}
except KeyError:
w.prnt("", "Command not found: " + args)
return
@@ -1361,6 +1379,7 @@ def command_help(current_buffer, args):
# Websocket handling methods
+
def command_openweb(current_buffer, args):
trigger = w.config_get_plugin('trigger_value')
if trigger != "0":
@@ -1371,13 +1390,14 @@ def command_openweb(current_buffer, args):
w.buffer_set(channel.channel_buffer, "title", "{}:{}".format(trigger, url))
w.hook_timer(1000, 0, 1, "command_openweb", json.dumps({"topic": topic, "buffer": current_buffer}))
else:
- #TODO: fix this dirty hack because i don't know the right way to send multiple args.
+ # TODO: fix this dirty hack because i don't know the right way to send multiple args.
args = current_buffer
data = json.loads(args)
channel_buffer = channels.find(data["buffer"]).channel_buffer
w.buffer_set(channel_buffer, "title", data["topic"])
return w.WEECHAT_RC_OK
+
@slack_buffer_or_ignore
def topic_command_cb(data, current_buffer, args):
n = len(args.split())
@@ -1391,6 +1411,7 @@ def topic_command_cb(data, current_buffer, args):
else:
return w.WEECHAT_RC_ERROR
+
def command_topic(current_buffer, args):
"""
Change the topic of a channel
@@ -1418,7 +1439,6 @@ def command_topic(current_buffer, args):
return False
-
def slack_websocket_cb(server, fd):
try:
data = servers.find(server).ws.recv()
@@ -1448,6 +1468,7 @@ def slack_websocket_cb(server, fd):
w.bar_item_update("slack_typing_notice")
return w.WEECHAT_RC_OK
+
def process_reply(message_json):
global unfurl_ignore_alt_text
@@ -1465,6 +1486,7 @@ def process_reply(message_json):
channels.find(item["channel"]).buffer_prnt(item["user"], text, item["ts"])
dbg("REPLY {}".format(item))
+
def process_pong(message_json):
pass
@@ -1488,9 +1510,11 @@ def process_team_join(message_json):
server.add_user(User(server, item["name"], item["id"], item["presence"]))
server.buffer_prnt("New user joined: {}".format(item["name"]))
+
def process_manual_presence_change(message_json):
process_presence_change(message_json)
+
def process_presence_change(message_json):
server = servers.find(message_json["_server"])
identifier = message_json.get("user", server.nick)
@@ -1593,7 +1617,7 @@ def process_group_joined(message_json):
server.add_channel(GroupChannel(server, item["name"], item["id"], item["is_open"], item["last_read"], "#", item["members"], item["topic"]["value"]))
-def process_group_archive(message_json):
+def process_group_archive(message_json):
channel = server.channels.find(message_json["channel"])
channel.detach_buffer()
@@ -1655,9 +1679,11 @@ def process_bot_integration(message_json):
# todo: does this work?
+
def process_error(message_json):
pass
+
def process_reaction_added(message_json):
if message_json["item"].get("type") == "message":
channel = channels.find(message_json["item"]["channel"])
@@ -1665,6 +1691,7 @@ def process_reaction_added(message_json):
else:
dbg("Reaction to item type not supported: " + str(message_json))
+
def process_reaction_removed(message_json):
if message_json["item"].get("type") == "message":
channel = channels.find(message_json["item"]["channel"])
@@ -1672,6 +1699,7 @@ def process_reaction_removed(message_json):
else:
dbg("Reaction to item type not supported: " + str(message_json))
+
def create_reaction_string(reactions):
count = 0
if not isinstance(reactions, list):
@@ -1692,41 +1720,43 @@ def create_reaction_string(reactions):
reaction_string = ''
return reaction_string
+
def modify_buffer_line(buffer, new_line, time):
time = int(float(time))
# get a pointer to this buffer's lines
own_lines = w.hdata_pointer(w.hdata_get('buffer'), buffer, 'own_lines')
if own_lines:
- #get a pointer to the last line
+ # get a pointer to the last line
line_pointer = w.hdata_pointer(w.hdata_get('lines'), own_lines, 'last_line')
- #hold the structure of a line and of line data
+ # hold the structure of a line and of line data
struct_hdata_line = w.hdata_get('line')
struct_hdata_line_data = w.hdata_get('line_data')
while line_pointer:
- #get a pointer to the data in line_pointer via layout of struct_hdata_line
+ # get a pointer to the data in line_pointer via layout of struct_hdata_line
data = w.hdata_pointer(struct_hdata_line, line_pointer, 'data')
if data:
date = w.hdata_time(struct_hdata_line_data, data, 'date')
- prefix = w.hdata_string(struct_hdata_line_data, data, 'prefix')
+ # prefix = w.hdata_string(struct_hdata_line_data, data, 'prefix')
if int(date) == int(time):
- #w.prnt("", "found matching time date is {}, time is {} ".format(date, time))
+ # w.prnt("", "found matching time date is {}, time is {} ".format(date, time))
w.hdata_update(struct_hdata_line_data, data, {"message": new_line})
break
else:
pass
- #move backwards one line and try again - exit the while if you hit the end
+ # move backwards one line and try again - exit the while if you hit the end
line_pointer = w.hdata_move(struct_hdata_line, line_pointer, -1)
return w.WEECHAT_RC_OK
+
def render_message(message_json, force=False):
global unfurl_ignore_alt_text
- #If we already have a rendered version in the object, just return that.
+ # If we already have a rendered version in the object, just return that.
if not force and message_json.get("_rendered_text", ""):
return message_json["_rendered_text"]
else:
- server = servers.find(message_json["_server"])
+ # server = servers.find(message_json["_server"])
if "fallback" in message_json:
text = message_json["fallback"]
@@ -1767,7 +1797,7 @@ def process_message(message_json, cache=True):
server = servers.find(message_json["_server"])
channel = channels.find(message_json["channel"])
- #do not process messages in unexpected channels
+ # do not process messages in unexpected channels
if not channel.active:
channel.open(False)
dbg("message came for closed channel {}".format(channel.name))
@@ -1778,7 +1808,7 @@ def process_message(message_json, cache=True):
name = get_user(message_json, server)
name = name.encode('utf-8')
- #special case with actions.
+ # special case with actions.
if text.startswith("_") and text.endswith("_"):
text = text[1:-1]
if name != channel.server.nick:
@@ -1791,7 +1821,6 @@ def process_message(message_json, cache=True):
suffix = ' (edited)'
channel.buffer_prnt(name, text + suffix, time)
-
if cache:
channel.cache_message(message_json)
@@ -1892,6 +1921,7 @@ def resolve_ref(ref):
# Something else, just return as-is
return ref
+
def unfurl_ref(ref, ignore_alt_text=False):
id = ref.split('|')[0]
display_text = ref
@@ -1908,6 +1938,7 @@ def unfurl_ref(ref, ignore_alt_text=False):
display_text = resolve_ref(ref)
return display_text
+
def unfurl_refs(text, ignore_alt_text=False):
"""
input : <@U096Q7CQM|someuser> has joined the channel
@@ -1977,18 +2008,20 @@ def buffer_list_update_cb(data, remaining_calls):
now = time.time()
if buffer_list_update and previous_buffer_list_update + 1 < now:
- gray_check = False
- if len(servers) > 1:
- gray_check = True
+ # gray_check = False
+ # if len(servers) > 1:
+ # gray_check = True
for channel in channels:
channel.rename()
buffer_list_update = False
return w.WEECHAT_RC_OK
+
def buffer_list_update_next():
global buffer_list_update
buffer_list_update = True
+
def hotlist_cache_update_cb(data, remaining_calls):
# this keeps the hotlist dupe up to date for the buffer switch, but is prob technically a race condition. (meh)
global hotlist
@@ -2010,7 +2043,7 @@ def buffer_switch_cb(signal, sig_type, data):
if channels.find(previous_buffer):
channels.find(previous_buffer).mark_read()
- channel_name = current_buffer_name()
+ # channel_name = current_buffer_name()
previous_buffer = data
return w.WEECHAT_RC_OK
@@ -2028,6 +2061,7 @@ def typing_notification_cb(signal, sig_type, data):
typing_timer = now
return w.WEECHAT_RC_OK
+
def slack_ping_cb(data, remaining):
"""
Periodic websocket ping to detect broken connection.
@@ -2055,7 +2089,7 @@ def slack_never_away_cb(data, remaining):
for server in servers:
identifier = server.channels.find("slackbot").identifier
request = {"type": "typing", "channel": identifier}
- #request = {"type":"typing","channel":"slackbot"}
+ # request = {"type":"typing","channel":"slackbot"}
server.send_to_websocket(request, expect_reply=False)
return w.WEECHAT_RC_OK
@@ -2117,15 +2151,18 @@ def complete_next_cb(data, buffer, command):
# Slack specific requests
# 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 = 'url:https://{}/api/{}?{}'.format(domain, request, urllib.urlencode(post_data))
context = pickle.dumps({"request": request, "token": token, "post_data": post_data})
- params = { 'useragent': 'wee_slack {}'.format(SCRIPT_VERSION) }
+ params = {'useragent': 'wee_slack {}'.format(SCRIPT_VERSION)}
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)
@@ -2134,9 +2171,11 @@ def async_slack_api_upload_request(token, request, post_data, priority=False):
context = pickle.dumps({"request": request, "token": token, "post_data": post_data})
w.hook_process(command, 20000, "url_processor_cb", context)
+
# funny, right?
big_data = {}
+
def url_processor_cb(data, command, return_code, out, err):
global big_data
data = pickle.loads(data)
@@ -2164,7 +2203,7 @@ def url_processor_cb(data, command, return_code, out, err):
channel = data["post_data"]["channel"]
token = data["token"]
if "messages" in my_json:
- messages = my_json["messages"].reverse()
+ # messages = my_json["messages"].reverse()
for message in my_json["messages"]:
message["_server"] = servers.find(token).domain
message["channel"] = servers.find(token).channels.find(channel).identifier
@@ -2179,6 +2218,7 @@ def url_processor_cb(data, command, return_code, out, err):
return w.WEECHAT_RC_OK
+
def cache_write_cb(data, remaining):
cache_file = open("{}/{}".format(WEECHAT_HOME, CACHE_NAME), 'w')
cache_file.write(CACHE_VERSION + "\n")
@@ -2188,6 +2228,7 @@ def cache_write_cb(data, remaining):
cache_file.write("{}\n".format(json.dumps(message.message_json)))
return w.WEECHAT_RC_OK
+
def cache_load():
global message_cache
try:
@@ -2216,7 +2257,7 @@ def current_domain_name():
if servers.find(buffer):
return servers.find(buffer).domain
else:
- #number = w.buffer_get_integer(buffer, "number")
+ # number = w.buffer_get_integer(buffer, "number")
name = w.buffer_get_string(buffer, "name")
name = ".".join(name.split(".")[:-1])
return name
@@ -2224,7 +2265,7 @@ def current_domain_name():
def current_buffer_name(short=False):
buffer = w.current_buffer()
- #number = w.buffer_get_integer(buffer, "number")
+ # number = w.buffer_get_integer(buffer, "number")
name = w.buffer_get_string(buffer, "name")
if short:
try:
@@ -2244,7 +2285,7 @@ def create_slack_buffer():
global slack_buffer
slack_buffer = w.buffer_new("slack", "", "", "closed_slack_buffer_cb", "")
w.buffer_set(slack_buffer, "notify", "0")
- #w.buffer_set(slack_buffer, "display", "1")
+ # w.buffer_set(slack_buffer, "display", "1")
return w.WEECHAT_RC_OK
@@ -2288,13 +2329,16 @@ def config_changed_cb(data, option, value):
return w.WEECHAT_RC_OK
+
def quit_notification_cb(signal, sig_type, data):
stop_talking_to_slack()
+
def script_unloaded():
stop_talking_to_slack()
return w.WEECHAT_RC_OK
+
def stop_talking_to_slack():
"""
Prevents a race condition where quitting closes buffers
@@ -2306,6 +2350,7 @@ def stop_talking_to_slack():
cache_write_cb("", "")
return w.WEECHAT_RC_OK
+
def scrolled_cb(signal, sig_type, data):
try:
if w.window_get_integer(data, "scrolling") == 1:
@@ -2425,6 +2470,6 @@ if __name__ == "__main__":
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", "")
+ "nick_completion_cb", "")
w.bar_item_new('slack_typing_notice', 'typing_bar_item_cb', '')
# END attach to the weechat hooks we need