diff options
author | Trygve Aaberge <trygveaa@gmail.com> | 2018-06-07 14:25:45 +0200 |
---|---|---|
committer | Trygve Aaberge <trygveaa@gmail.com> | 2018-06-07 14:45:55 +0200 |
commit | 3cd3d096d6ca8bd4963b41f8ec5eb7fec201516d (patch) | |
tree | 71be6d8cfab2f90e1b744f3b29ca8c2c50681794 /wee_slack.py | |
parent | eb9a1b306a0df2410ace180178c6c9737d03d73d (diff) | |
download | wee-slack-3cd3d096d6ca8bd4963b41f8ec5eb7fec201516d.tar.gz |
Handle get_sender being called before users.info
When messages were loaded before the user info were fetched for an
external user, this would crash.
Diffstat (limited to 'wee_slack.py')
-rw-r--r-- | wee_slack.py | 26 |
1 files changed, 10 insertions, 16 deletions
diff --git a/wee_slack.py b/wee_slack.py index b0516d8..62719a4 100644 --- a/wee_slack.py +++ b/wee_slack.py @@ -2080,33 +2080,27 @@ class SlackMessage(object): def get_sender(self): name = "" name_plain = "" - if 'user' in self.message_json: - if self.message_json['user'] == self.team.myidentifier: - u = self.team.users[self.team.myidentifier] - else: - u = self.team.users.get(self.message_json['user']) - name = "{}".format(u.formatted_name()) - name_plain = "{}".format(u.formatted_name(enable_color=False)) - if u.is_external: + 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)) + if user.is_external: name += config.external_user_suffix name_plain += config.external_user_suffix elif 'username' in self.message_json: - u = self.message_json["username"] + username = self.message_json["username"] if self.message_json.get("subtype") == "bot_message": - name = "{} :]".format(u) - name_plain = "{}".format(u) + name = "{} :]".format(username) + name_plain = "{}".format(username) else: - name = "-{}-".format(u) - name_plain = "{}".format(u) + name = "-{}-".format(username) + name_plain = "{}".format(username) elif 'service_name' in self.message_json: name = "-{}-".format(self.message_json["service_name"]) name_plain = "{}".format(self.message_json["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)) - else: - name = "" - name_plain = "" return (name, name_plain) def add_reaction(self, reaction, user): |