mirror of
https://github.com/stoatchat/python-client-sdk.git
synced 2026-07-15 12:55:36 -04:00
Add docs
This commit is contained in:
@@ -96,6 +96,10 @@ API Reference
|
||||
:members:
|
||||
:inherited-members:
|
||||
|
||||
.. autoclass:: UserPermissions
|
||||
:members:
|
||||
:inherited-members:
|
||||
|
||||
.. autoclass:: PermissionsOverwrite
|
||||
:members:
|
||||
:inherited-members:
|
||||
|
||||
@@ -119,17 +119,62 @@ class Member(User):
|
||||
await self.state.http.edit_member(self.server.id, self.id, None, {"timeout": ends_at.isoformat()})
|
||||
|
||||
def get_permissions(self) -> Permissions:
|
||||
"""Gets the permissions for the member in the server
|
||||
|
||||
Returns
|
||||
--------
|
||||
:class:`Permissions`
|
||||
The members permissions
|
||||
"""
|
||||
return calculate_permissions(self, self.server)
|
||||
|
||||
def get_channel_permissions(self, channel: Channel):
|
||||
"""Gets the permissions for the member in the server taking into account the channel as well
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
channel: :class:`Channel`
|
||||
The channel to calculate permissions with
|
||||
|
||||
Returns
|
||||
--------
|
||||
:class:`Permissions`
|
||||
The members permissions
|
||||
"""
|
||||
return calculate_permissions(self, channel)
|
||||
|
||||
def has_permissions(self, **permissions: bool) -> bool:
|
||||
"""Computes if the member has the specified permissions
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
permissions: :class:`bool`
|
||||
The permissions to check, this also accepted `False` if you need to check if the member does not have the permission
|
||||
|
||||
Returns
|
||||
--------
|
||||
:class:`bool`
|
||||
Whether or not they have the permissions
|
||||
"""
|
||||
calculated_perms = self.get_permissions()
|
||||
|
||||
return all([getattr(calculated_perms, key, False) == value for key, value in permissions.items()])
|
||||
|
||||
def has_channel_permissions(self, channel: Channel, **permissions: bool) -> bool:
|
||||
"""Computes if the member has the specified permissions, taking into account the channel as well
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
channel: :class:`Channel`
|
||||
The channel to calculate permissions with
|
||||
permissions: :class:`bool`
|
||||
The permissions to check, this also accepted `False` if you need to check if the member does not have the permission
|
||||
|
||||
Returns
|
||||
--------
|
||||
:class:`bool`
|
||||
Whether or not they have the permissions
|
||||
"""
|
||||
calculated_perms = self.get_channel_permissions(channel)
|
||||
|
||||
return all([getattr(calculated_perms, key, False) == value for key, value in permissions.items()])
|
||||
|
||||
@@ -10,6 +10,8 @@ from .types.permissions import Overwrite
|
||||
__all__ = ("Permissions", "PermissionsOverwrite", "UserPermissions")
|
||||
|
||||
class UserPermissions(Flags):
|
||||
"""Permissions for users"""
|
||||
|
||||
@Flag
|
||||
def access() -> int:
|
||||
return 1 << 0
|
||||
@@ -31,6 +33,8 @@ class UserPermissions(Flags):
|
||||
return cls(access=True, view_profile=True, send_message=True, invite=True)
|
||||
|
||||
class Permissions(Flags):
|
||||
"""Server permissions for members and roles"""
|
||||
|
||||
@Flag
|
||||
def manage_channel() -> int:
|
||||
return 1 << 0
|
||||
@@ -156,6 +160,8 @@ class Permissions(Flags):
|
||||
return cls.default_view_only() | cls(react=True, manage_channel=True)
|
||||
|
||||
class PermissionsOverwrite:
|
||||
"""A permissions overwrite in a channel"""
|
||||
|
||||
def __init__(self, allow: Permissions, deny: Permissions):
|
||||
self._allow = allow
|
||||
self._deny = deny
|
||||
|
||||
+26
-7
@@ -45,8 +45,8 @@ class User(Messageable, Ulid):
|
||||
The users id
|
||||
bot: :class:`bool`
|
||||
Whether or not the user is a bot
|
||||
owner: Optional[:class:`User`]
|
||||
The bot's owner if the user is a bot
|
||||
owner_id: Optional[:class:`str`]
|
||||
The bot's owner id if the user is a bot
|
||||
badges: :class:`UserBadges`
|
||||
The users badges
|
||||
online: :class:`bool`
|
||||
@@ -114,6 +114,13 @@ class User(Messageable, Ulid):
|
||||
self.masquerade_name: Optional[str] = None
|
||||
|
||||
def get_permissions(self) -> UserPermissions:
|
||||
"""Gets the permissions for the user
|
||||
|
||||
Returns
|
||||
--------
|
||||
:class:`UserPermissions`
|
||||
The users permissions
|
||||
"""
|
||||
permissions = UserPermissions()
|
||||
|
||||
if self.relationship in [RelationshipType.friend, RelationshipType.user]:
|
||||
@@ -136,6 +143,18 @@ class User(Messageable, Ulid):
|
||||
return permissions
|
||||
|
||||
def has_permissions(self, **permissions: bool) -> bool:
|
||||
"""Computes if the user has the specified permissions
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
permissions: :class:`bool`
|
||||
The permissions to check, this also accepted `False` if you need to check if the user does not have the permission
|
||||
|
||||
Returns
|
||||
--------
|
||||
:class:`bool`
|
||||
Whether or not they have the permissions
|
||||
"""
|
||||
perms = self.get_permissions()
|
||||
|
||||
return all([getattr(perms, key, False) == value for key, value in permissions.items()])
|
||||
@@ -148,13 +167,13 @@ class User(Messageable, Ulid):
|
||||
return self.id
|
||||
|
||||
@property
|
||||
def owner(self) -> Optional[User]:
|
||||
owner_id = self.owner_id
|
||||
def owner(self) -> User:
|
||||
""":class:`User` the owner of the bot account"""
|
||||
|
||||
if not owner_id:
|
||||
return
|
||||
if not self.owner_id:
|
||||
raise LookupError
|
||||
|
||||
return self.state.get_user(owner_id)
|
||||
return self.state.get_user(self.owner_id)
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
|
||||
Reference in New Issue
Block a user