aboutsummaryrefslogtreecommitdiffstats
path: root/slack
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2023-01-15 02:51:03 +0100
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 11:32:53 +0100
commit0f891a587492d46ffe13ce950350ff6324b64ddf (patch)
tree42f96f50fb9cf0e6f76361cb807f5287cf5d337b /slack
parent38d2e4154b31d1a95084c53eabf09af03c323a19 (diff)
downloadwee-slack-0f891a587492d46ffe13ce950350ff6324b64ddf.tar.gz
Use display name or real name
Diffstat (limited to 'slack')
-rw-r--r--slack/config.py12
-rw-r--r--slack/slack_user.py12
2 files changed, 20 insertions, 4 deletions
diff --git a/slack/config.py b/slack/config.py
index a1ab999..d4a36bd 100644
--- a/slack/config.py
+++ b/slack/config.py
@@ -38,8 +38,8 @@ class SlackConfigSectionColor:
self.reaction_suffix = WeeChatOption(
self._section,
"reaction_suffix",
- "text color for the [:wave:(@user)] suffix on messages that have "
- "reactions attached to them.",
+ "text color for the [:wave:(@user)] suffix on messages that have"
+ " reactions attached to them.",
WeeChatColor("darkgray"),
)
@@ -79,6 +79,14 @@ class SlackConfigSectionWorkspace:
30,
)
+ self.use_real_names = self._create_option(
+ "use_real_names",
+ "use real names as the nicks for all users. When this is"
+ " false, display names will be used if set, with a fallback"
+ " to the real name if display name is not set",
+ False,
+ )
+
def _create_option(
self,
name: str,
diff --git a/slack/slack_user.py b/slack/slack_user.py
index 8fcd445..e5d066b 100644
--- a/slack/slack_user.py
+++ b/slack/slack_user.py
@@ -16,8 +16,9 @@ class SlackUser:
return self.workspace.api
@property
- def nick(self):
- return self._info["name"]
+ def nick(self) -> str:
+ nick = self._nick_from_profile()
+ return nick.replace(" ", "")
async def init(self):
info = await self._api.fetch_users_info(self)
@@ -25,3 +26,10 @@ class SlackUser:
# TODO: Handle error
raise Exception("Failed fetching user info")
self._info = info["user"]
+
+ def _nick_from_profile(self) -> str:
+ if self.workspace.config.use_real_names.value:
+ return self._info["real_name"]
+
+ display_name = self._info["profile"].get("display_name")
+ return display_name or self._info["real_name"]