aboutsummaryrefslogtreecommitdiffstats
path: root/slack/slack_user.py
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2023-01-19 23:05:25 +0100
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 11:32:53 +0100
commitd2bb9263f0062275b92024ccdba68d5439521b5d (patch)
treedd9b46727d5a3fc8e1b1c232419504772305e928 /slack/slack_user.py
parentd6b4f505d53e69ecb39d518a89d8d0013e22ad51 (diff)
downloadwee-slack-d2bb9263f0062275b92024ccdba68d5439521b5d.tar.gz
Add support for completing nicks
This uses Slacks edgeapi which only works for session tokens, but has the benefit of being able to complete nicks without all users being loaded. So need to add some completion for the loaded users for when using OAuth tokens as well.
Diffstat (limited to 'slack/slack_user.py')
-rw-r--r--slack/slack_user.py28
1 files changed, 16 insertions, 12 deletions
diff --git a/slack/slack_user.py b/slack/slack_user.py
index b895872..439bbdd 100644
--- a/slack/slack_user.py
+++ b/slack/slack_user.py
@@ -19,6 +19,21 @@ def nick_color(nick: str) -> str:
return weechat.info_get("nick_color_name", nick)
+# TODO: Probably need to do some mapping here based on the existing users, in case some has been changed to avoid duplicate names
+def _name_from_user_info(workspace: SlackWorkspace, info: SlackUserInfo) -> str:
+ display_name = info["profile"].get("display_name")
+ if display_name and not workspace.config.use_real_names.value:
+ return display_name
+
+ return info["profile"].get("display_name") or info.get("real_name") or info["name"]
+
+
+def name_from_user_info_without_spaces(
+ workspace: SlackWorkspace, info: SlackUserInfo
+) -> str:
+ return _name_from_user_info(workspace, info).replace(" ", "")
+
+
def format_bot_nick(nick: str, colorize: bool = False) -> str:
nick = nick.replace(" ", "")
@@ -66,19 +81,8 @@ class SlackUser:
return nick
- def _name_from_profile(self) -> str:
- display_name = self._info["profile"].get("display_name")
- if display_name and not self.workspace.config.use_real_names.value:
- return display_name
-
- return (
- self._info["profile"].get("display_name")
- or self._info.get("real_name")
- or self._info["name"]
- )
-
def _name_without_spaces(self) -> str:
- return self._name_from_profile().replace(" ", "")
+ return name_from_user_info_without_spaces(self.workspace, self._info)
def _nick_color(self) -> str:
if self.id == self.workspace.my_user.id: