diff options
author | Ryan Huber <rhuber@gmail.com> | 2014-10-27 20:59:23 -0700 |
---|---|---|
committer | Ryan Huber <rhuber@gmail.com> | 2014-10-27 20:59:23 -0700 |
commit | 86a03c068fbdefcbfff503a6a9e1cf279d1bfce8 (patch) | |
tree | a3d1023f1fd117ed71e9527ff1481be7163edff0 /wee_slack.py | |
parent | c3fd361137b7ed71cbdaa53686584a8e462d88eb (diff) | |
download | wee-slack-86a03c068fbdefcbfff503a6a9e1cf279d1bfce8.tar.gz |
colorized internally now, without plugin
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 78 |
1 files changed, 16 insertions, 62 deletions
diff --git a/wee_slack.py b/wee_slack.py index 62c4272..8e1529e 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -56,7 +56,7 @@ class Meta(list): def __str__(self): string = '' for each in self.search_list.get_all(self.attribute): - string += str(each) + string += str(each) + ' ' return string def __repr__(self): self.search_list.get_all(self.attribute) @@ -247,9 +247,9 @@ class SlackThing(object): self.identifier = identifier self.channel_buffer = None def __str__(self): - return "Name: %s Id: %s CB: %s" % (self.name, self.identifier, self.channel_buffer) + return self.name def __repr__(self): - return "Name: %s Id: %s CB: %s" % (self.name, self.identifier, self.channel_buffer) + return self.name def input(b, c, data): channel = channels.find(c) @@ -277,10 +277,6 @@ class Channel(SlackThing): return True else: return False - def __str__(self): - return "Name: %s Id: %s Buffer: %s Active: %s" % (self.name, self.identifier, self.channel_buffer, self.active) - def __repr__(self): - return "Name: %s Id: %s Buffer: %s Active: %s" % (self.name, self.identifier, self.channel_buffer, self.active) def create_buffer(self): channel_buffer = w.buffer_search("", "%s.%s" % (self.server.domain, self.name)) if channel_buffer: @@ -305,9 +301,9 @@ class Channel(SlackThing): for user in self.members: user = self.server.users.find(user) if user.presence == 'away': - w.nicklist_add_nick(self.channel_buffer, "", user.name, w.info_get('irc_nick_color_name', user.name), " ", "", 1) + w.nicklist_add_nick(self.channel_buffer, "", user.name, user.color(), " ", "", 1) else: - w.nicklist_add_nick(self.channel_buffer, "", user.name, w.info_get('irc_nick_color_name', user.name), "+", "", 1) + w.nicklist_add_nick(self.channel_buffer, "", user.name, user.color(), "+", "", 1) def fullname(self): return "%s.%s" % (self.server.domain, self.name) def has_user(self, name): @@ -381,11 +377,13 @@ class Channel(SlackThing): new_name = self.name #w.buffer_set(self.weechat_buffer, "short_name", new_name) w.buffer_set(self.channel_buffer, "short_name", new_name) - def buffer_prnt(self, user='unknown user', message='no message', time=0, backlog=False): + def buffer_prnt(self, user='unknown user', message='no message', time=0): + if self.server.users.find(user) and user != self.server.nick: + user = self.server.users.find(user).colorized_name() set_read_marker = False time = float(time) message = message.encode('ascii', 'ignore') - if backlog == True or (time != 0 and self.last_read >= time): + if time != 0 and self.last_read >= time: tags = "no_highlight,notify_none,logger_backlog_end" set_read_marker = True elif message.find(self.server.nick) > -1: @@ -394,7 +392,6 @@ class Channel(SlackThing): tags = "notify_message" time = int(float(time)) if self.channel_buffer: - w.prnt_date_tags(self.channel_buffer, time, tags, "%s\t%s %s" % (user, time, self.last_read)) w.prnt_date_tags(self.channel_buffer, time, tags, "%s\t%s" % (user, message)) if set_read_marker: self.mark_read(False) @@ -424,27 +421,6 @@ class DmChannel(Channel): else: new_name = self.name w.buffer_set(self.channel_buffer, "short_name", color + new_name) - def buffer_prnt(self, user='unknown user', message='no message', time=0, backlog=False): - set_read_marker = False - time = float(time) - message = message.encode('ascii', 'ignore') - if backlog == True or (time != 0 and self.last_read > time): - tags = "no_highlight,notify_none,logger_backlog_end" - set_read_marker = True - elif user == self.server.nick: - tags = "" - elif message.find(self.server.nick) > -1: - tags = "notify_highlight" - else: - tags = "notify_private,notify_message" - time = int(float(time)) - if self.channel_buffer: - w.prnt_date_tags(self.channel_buffer, time, tags, "%s\t%s" % (user, message)) - if set_read_marker: - self.mark_read(False) - else: - dbg("failed to print something..") - pass class User(SlackThing): def __init__(self, server, name, identifier, presence="away"): @@ -453,9 +429,9 @@ class User(SlackThing): self.presence = presence self.server = server if self.presence == 'away': - self.nicklist_pointer = w.nicklist_add_nick(server.buffer, "", self.name, w.info_get('irc_nick_color_name', self.name), " ", "", 0) + self.nicklist_pointer = w.nicklist_add_nick(server.buffer, "", self.name, self.color(), " ", "", 0) else: - self.nicklist_pointer = w.nicklist_add_nick(server.buffer, "", self.name, w.info_get('irc_nick_color_name', self.name), "+", "", 1) + self.nicklist_pointer = w.nicklist_add_nick(server.buffer, "", self.name, self.color(), "+", "", 1) # w.nicklist_add_nick(server.buffer, "", self.colorized_name(), "", "", "", 1) def __eq__(self, compare_str): if compare_str == self.name or compare_str == self.identifier: @@ -476,6 +452,8 @@ class User(SlackThing): channel.update_nicklist() w.nicklist_nick_set(self.server.buffer, self.nicklist_pointer, "prefix", " ") w.nicklist_nick_set(self.server.buffer, self.nicklist_pointer, "visible", "0") + def color(self): + return w.info_get('irc_nick_color_name', self.name) def colorized_name(self): color = w.info_get('irc_nick_color', self.name) def_color = w.color('default') @@ -599,7 +577,6 @@ def slack_websocket_cb(data, fd): message_json['myserver'] = server except: return w.WEECHAT_RC_OK - #dbg(message_json) #dispatch here if message_json.has_key("type"): function_name = message_json["type"] @@ -757,35 +734,12 @@ def process_message(message_json): else: name = "unknown name" - color = w.info_get('irc_nick_color', name) - def_color = w.color('default') - name = "%s%s%s" % (color, name, def_color) + #color = w.info_get('irc_nick_color', name) + #def_color = w.color('default') + #name = "%s%s%s" % (color, name, def_color) server.channels.find(channel).buffer_prnt(name, text, time) -# except: -# dbg("BROKE! %s" % (message_json), True) - -# if message_json.has_key("user") and message_json.has_key("text"): -## channel = server.channels.find(message_json["channel"]) -# channel.unset_typing(server.users.find(message_json["user"]).name) -# user = server.users.find(message_json["user"]) -# if user.name != channel.server.nick: -# user = user.colorized_name() -# else: -# user = user.name -# if message_json.has_key("attachments"): -# if message_json.has_key("username"): -# for message in message_json["attachments"]: -# if message.has_key("service_name"): -# name = message["service_name"] -# try: -# server.channels.find(channel).buffer_prnt("-%s-" % name, str(message["fallback"]), time) -# except: -# server.channels.find(channel).buffer_prnt('unknown user', str(message_json), time) -# else: -# server.channels.find(channel).buffer_prnt('unknown user', str(message_json), time) - def process_message_changed(message_json): if message_json["type"] != "message": #dbg("message changed: " + str(message_json)) |