From 2d5cffc322ea483a835c2352105155de9eb0c546 Mon Sep 17 00:00:00 2001 From: Ryan Huber Date: Thu, 13 Apr 2017 19:39:51 +0000 Subject: topic is user's status --- wee_slack.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'wee_slack.py') diff --git a/wee_slack.py b/wee_slack.py index d5acd59..6460da6 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -1368,6 +1368,7 @@ class SlackDMChannel(SlackChannel): self.type = 'im' self.update_color() self.set_name(self.slack_name) + self.slack_topic = {"value": users[dmuser].profile.get("status_text")} def set_name(self, slack_name): self.name = slack_name def create_buffer(self): @@ -1635,6 +1636,8 @@ class SlackUser(object): # colourization. self.color_name = w.info_get('nick_color_name', self.name.encode('utf-8')) self.color = w.color(self.color_name) + def update_status(self, status_text): + self.profile["status_text"] = status_text def formatted_name(self, prepend="", enable_color=True): if enable_color: return self.color + prepend + self.name @@ -1922,6 +1925,17 @@ def process_pref_change(message_json, eventrouter, **kwargs): else: 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_text")) + dmchannel = team.get_channel_map()[user["name"]] + team.channels[dmchannel].render_topic(topic=team.users[user["id"]].profile["status_text"]) + def process_user_typing(message_json, eventrouter, **kwargs): channel = kwargs["channel"] team = kwargs["team"] -- cgit From 6bf0107db63908e97c74503a447f358c64acc2d5 Mon Sep 17 00:00:00 2001 From: V13Axel Date: Thu, 13 Apr 2017 16:31:50 -0400 Subject: Add in emoji to status as dm topic --- wee_slack.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'wee_slack.py') diff --git a/wee_slack.py b/wee_slack.py index 6460da6..ff3b394 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -1368,7 +1368,7 @@ class SlackDMChannel(SlackChannel): self.type = 'im' self.update_color() self.set_name(self.slack_name) - self.slack_topic = {"value": users[dmuser].profile.get("status_text")} + self.slack_topic = {"value": "[{}] {}".format(users[dmuser].profile.get("status_emoji"), users[dmuser].profile.get("status_text"))} def set_name(self, slack_name): self.name = slack_name def create_buffer(self): @@ -1636,7 +1636,8 @@ class SlackUser(object): # colourization. self.color_name = w.info_get('nick_color_name', self.name.encode('utf-8')) self.color = w.color(self.color_name) - def update_status(self, status_text): + 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: @@ -1932,9 +1933,9 @@ def process_user_change(message_json, eventrouter, **kwargs): user = message_json['user'] profile = user.get("profile") team = kwargs["team"] - team.users[user["id"]].update_status(profile.get("status_text")) + team.users[user["id"]].update_status(profile.get("status_emoji"), profile.get("status_text")) dmchannel = team.get_channel_map()[user["name"]] - team.channels[dmchannel].render_topic(topic=team.users[user["id"]].profile["status_text"]) + team.channels[dmchannel].render_topic(topic="[{}] {}".format(team.users[user["id"]].profile["status_emoji"], team.users[user["id"]].profile["status_text"])) def process_user_typing(message_json, eventrouter, **kwargs): channel = kwargs["channel"] -- cgit From ca280d7024bb75db4e1a893b1e1d7089b7a1746c Mon Sep 17 00:00:00 2001 From: V13Axel Date: Mon, 17 Apr 2017 21:03:35 -0400 Subject: Move formatting to its own function --- wee_slack.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'wee_slack.py') diff --git a/wee_slack.py b/wee_slack.py index ff3b394..5cfdeb4 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -1368,7 +1368,7 @@ class SlackDMChannel(SlackChannel): self.type = 'im' self.update_color() self.set_name(self.slack_name) - self.slack_topic = {"value": "[{}] {}".format(users[dmuser].profile.get("status_emoji"), users[dmuser].profile.get("status_text"))} + self.slack_topic = {"value": create_user_status_string(users[dmuser].profile)} def set_name(self, slack_name): self.name = slack_name def create_buffer(self): @@ -1935,7 +1935,7 @@ def process_user_change(message_json, eventrouter, **kwargs): team = kwargs["team"] team.users[user["id"]].update_status(profile.get("status_emoji"), profile.get("status_text")) dmchannel = team.get_channel_map()[user["name"]] - team.channels[dmchannel].render_topic(topic="[{}] {}".format(team.users[user["id"]].profile["status_emoji"], team.users[user["id"]].profile["status_text"])) + team.channels[dmchannel].render_topic(topic=create_user_status_string(profile)) def process_user_typing(message_json, eventrouter, **kwargs): channel = kwargs["channel"] @@ -2401,6 +2401,11 @@ def resolve_ref(ref): # Something else, just return as-is return ref +def create_user_status_string(profile): + status_emoji = profile.get("status_emoji") if profile.get("status_emoji") else "None" + status_text = profile.get("status_text") if profile.get("status_text") else "None" + return "[{}] {}".format(status_emoji, status_text) + def create_reaction_string(reactions): count = 0 if not isinstance(reactions, list): -- cgit