Improved docs and typing
This commit is contained in:
@@ -9,7 +9,20 @@ class CallbackLanguage:
|
||||
|
||||
@classmethod
|
||||
def from_callback(cls, callback: CallbackQuery):
|
||||
"""Parse callback query and extract language data from it.
|
||||
|
||||
### Args:
|
||||
* callback (`CallbackQuery`): Callback query got from user interaction.
|
||||
|
||||
### Raises:
|
||||
* `ValueError`: Raised when callback provided is not a language one.
|
||||
|
||||
### Returns:
|
||||
* `CallbackLanguage`: Parsed callback query.
|
||||
"""
|
||||
action, language = str(callback.data).split(":")
|
||||
|
||||
if action.lower() != "language":
|
||||
raise ValueError("Callback provided is not a language callback")
|
||||
|
||||
return cls(language)
|
||||
|
@@ -11,10 +11,10 @@ class PyroClient(LibPyroClient):
|
||||
"""Find User by it's ID or User object.
|
||||
|
||||
### Args:
|
||||
* user (`Union[int, User]`): ID or User object to extract ID from
|
||||
* user (`Union[int, User]`): ID or User object to extract ID from.
|
||||
|
||||
### Returns:
|
||||
* `PyroUser`: PyroUser object
|
||||
* `PyroUser`: User in database representation.
|
||||
"""
|
||||
|
||||
return (
|
||||
|
@@ -21,6 +21,18 @@ class PyroUser:
|
||||
|
||||
@classmethod
|
||||
async def find(cls, id: int, locale: Union[str, None] = None):
|
||||
"""Find user in database and create new record if user does not exist.
|
||||
|
||||
### Args:
|
||||
* id (`int`): User's Telegram ID
|
||||
* locale (`Union[str, None]`, *optional*): User's locale. Defaults to `None`.
|
||||
|
||||
### Raises:
|
||||
* `RuntimeError`: Raised when user entry after insertion could not be found.
|
||||
|
||||
### Returns:
|
||||
* `PyroUser`: User with its database data.
|
||||
"""
|
||||
db_entry = await col_users.find_one({"id": id})
|
||||
|
||||
if db_entry is None:
|
||||
@@ -33,10 +45,10 @@ class PyroUser:
|
||||
return cls(**db_entry)
|
||||
|
||||
async def update_locale(self, locale: Union[str, None]) -> None:
|
||||
"""Change user's locale stored in the database
|
||||
"""Change user's locale stored in the database.
|
||||
|
||||
### Args:
|
||||
* locale (`Union[str, None]`): New locale to be set
|
||||
* locale (`Union[str, None]`): New locale to be set.
|
||||
"""
|
||||
logger.debug("%s's locale has been set to %s", self.id, locale)
|
||||
await col_users.update_one({"_id": self._id}, {"$set": {"locale": locale}})
|
||||
|
Reference in New Issue
Block a user