diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2020-04-18 16:21:34 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2020-05-30 21:11:27 +0200 |
commit | 3d1214aff0e54a010eb1262d7952e96d77243412 (patch) | |
tree | a8e3e2d038cda23486c230f20938fe69c791fd4e | |
parent | 3eaa7a3890073f6ffd94805878b39e5013db423b (diff) | |
download | wee-slack-3d1214aff0e54a010eb1262d7952e96d77243412.tar.gz |
Make sender and sender_plain into properties
-rw-r--r-- | wee_slack.py | 46 |
1 files changed, 28 insertions, 18 deletions
diff --git a/wee_slack.py b/wee_slack.py index 04ec4e7..635dfe2 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -2450,8 +2450,6 @@ class SlackMessage(object): self.message_json = message_json self.submessages = [] self.hash = None - senders = self.get_sender() - self.sender, self.sender_plain = senders[0], senders[1] self.ts = SlackTS(message_json['ts']) self.subscribed = message_json.get("subscribed", False) self.last_read = SlackTS(message_json.get("last_read", SlackTS())) @@ -2527,31 +2525,43 @@ class SlackMessage(object): self.message_json["text"] = new_text dbg(self.message_json) - def get_sender(self): - name = "" - name_plain = "" + def get_sender(self, plain): user = self.team.users.get(self.message_json.get('user')) if user: - name = "{}".format(user.formatted_name()) - name_plain = "{}".format(user.formatted_name(enable_color=False)) + name = "{}".format(user.formatted_name(enable_color=not plain)) if user.is_external: name += config.external_user_suffix - name_plain += config.external_user_suffix + return name elif 'username' in self.message_json: username = self.message_json["username"] - if self.message_json.get("subtype") == "bot_message": - name = "{} :]".format(username) - name_plain = "{}".format(username) + if plain: + return username + elif self.message_json.get("subtype") == "bot_message": + return "{} :]".format(username) else: - name = "-{}-".format(username) - name_plain = "{}".format(username) + return "-{}-".format(username) elif 'service_name' in self.message_json: - name = "-{}-".format(self.message_json["service_name"]) - name_plain = "{}".format(self.message_json["service_name"]) + service_name = self.message_json["service_name"] + if plain: + return service_name + else: + return "-{}-".format(service_name) elif self.message_json.get('bot_id') in self.team.bots: - name = "{} :]".format(self.team.bots[self.message_json["bot_id"]].formatted_name()) - name_plain = "{}".format(self.team.bots[self.message_json["bot_id"]].formatted_name(enable_color=False)) - return (name, name_plain) + bot = self.team.bots[self.message_json["bot_id"]] + name = bot.formatted_name(enable_color=not plain) + if plain: + return name + else: + return "{} :]".format(name) + return "" + + @property + def sender(self): + return self.get_sender(False) + + @property + def sender_plain(self): + return self.get_sender(True) def get_reaction(self, reaction_name): for reaction in self.message_json.get("reactions", []): |