Skip to content

Commit

Permalink
fix: users by email are now exposed through plugin interface
Browse files Browse the repository at this point in the history
  • Loading branch information
DonDebonair committed Aug 13, 2023
1 parent 1aa40b6 commit 840495b
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions machine/plugins/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@ def users(self) -> dict[str, User]:
"""
return self._client.users

@property
def users_by_email(self) -> dict[str, User]:
"""Dictionary of all users in the Slack workspace by email
**Note**: not every user might have an email address in their profile, so this
dictionary might not contain all users in the Slack workspace
:return: a dictionary of all users in the Slack workspace, where the key is the email and
the value is a [`User`][machine.models.user.User] object
"""
return self._client.users

@property
def channels(self) -> dict[str, Channel]:
"""List of all channels in the Slack workspace
Expand Down Expand Up @@ -101,6 +113,22 @@ def find_channel_by_name(self, channel_name: str) -> Channel | None:
return c
return None

def get_user_by_id(self, user_id: str) -> User | None:
"""Get a user by their ID.
:param user_id: The ID of the user to retrieve.
:return: The user if found, None otherwise.
"""
return self.users.get(user_id)

def get_user_by_email(self, email: str) -> User | None:
"""Get a user by their email address.
:param email: The email address of the user to retrieve.
:return: The user if found, None otherwise.
"""
return self._client.get_user_by_email(email)

@property
def bot_info(self) -> dict[str, Any]:
"""Information about the bot user in Slack
Expand Down

0 comments on commit 840495b

Please sign in to comment.