aboutsummaryrefslogtreecommitdiffstats
path: root/wee_slack.py
diff options
context:
space:
mode:
Diffstat (limited to 'wee_slack.py')
-rw-r--r--wee_slack.py41
1 files changed, 35 insertions, 6 deletions
diff --git a/wee_slack.py b/wee_slack.py
index 6b69096..97a602f 100644
--- a/wee_slack.py
+++ b/wee_slack.py
@@ -1060,6 +1060,12 @@ class SlackTeam(object):
def buffer_prnt(self, data):
w.prnt_date_tags(self.channel_buffer, SlackTS().major, tag("team"), data)
+ def find_channel_by_members(self, members, channel_type=None):
+ for channel in self.channels.itervalues():
+ if channel.get_members() == members and (
+ channel_type is None or channel.type == channel_type):
+ return channel
+
def get_channel_map(self):
return {v.slack_name: k for k, v in self.channels.iteritems()}
@@ -1633,6 +1639,7 @@ class SlackDMChannel(SlackChannel):
self.type = 'im'
self.update_color()
self.set_name(self.slack_name)
+ self.topic = create_user_status_string(users[dmuser].profile)
def set_name(self, slack_name):
self.name = slack_name
@@ -1942,6 +1949,10 @@ class SlackUser(object):
self.color_name = get_nick_color_name(self.name)
self.color = w.color(self.color_name)
+ def update_status(self, status_emoji, status_text):
+ self.profile["status_emoji"] = status_emoji
+ self.profile["status_text"] = status_text
+
def formatted_name(self, prepend="", enable_color=True):
if enable_color:
return self.color + prepend + self.name
@@ -2295,6 +2306,19 @@ def process_pref_change(message_json, eventrouter, **kwargs):
dbg("Preference change not implemented: {}\n".format(message_json['name']))
+def process_user_change(message_json, eventrouter, **kwargs):
+ """
+ Currently only used to update status, but lots here we could do.
+ """
+ user = message_json['user']
+ profile = user.get("profile")
+ team = kwargs["team"]
+ team.users[user["id"]].update_status(profile.get("status_emoji"), profile.get("status_text"))
+ dmchannel = team.find_channel_by_members({user["id"]}, channel_type='im')
+ if dmchannel:
+ dmchannel.set_topic(create_user_status_string(profile))
+
+
def process_user_typing(message_json, eventrouter, **kwargs):
channel = kwargs["channel"]
team = kwargs["team"]
@@ -2821,6 +2845,16 @@ def resolve_ref(ref):
return ref
+def create_user_status_string(profile):
+ real_name = profile.get("real_name")
+ status_emoji = profile.get("status_emoji")
+ status_text = profile.get("status_text")
+ if status_emoji or status_text:
+ return "{} | {} {}".format(real_name, status_emoji, status_text)
+ else:
+ return real_name
+
+
def create_reaction_string(reactions):
count = 0
if not isinstance(reactions, list):
@@ -3193,12 +3227,7 @@ def command_talk(data, current_buffer, args):
else:
channel_type = 'im'
- # Try finding the channel by type and members
- for channel in team.channels.itervalues():
- if (channel.type == channel_type and
- channel.get_members() == users):
- chan = channel
- break
+ chan = team.find_channel_by_members(users, channel_type=channel_type)
# If the DM or MPDM doesn't exist, create it
if not chan: