v0.1.2 #60
@ -91,6 +91,7 @@ class PyroClient(LibPyroClient):
|
||||
]
|
||||
|
||||
async def check_updates(self) -> None:
|
||||
"""Check for updates and send a message to the owner if newer version was found"""
|
||||
if await self.updater.check_updates(
|
||||
self.__version__, self.config["strings"]["url_updater"]
|
||||
):
|
||||
|
@ -88,8 +88,7 @@ class PyroUser:
|
||||
### Args:
|
||||
* locale (`Union[str, None]`): New locale to be set.
|
||||
"""
|
||||
|
||||
logger.debug("%s's locale has been set to %s", self.id, locale)
|
||||
logger.info("%s's locale has been set to %s", self.id, locale)
|
||||
|
||||
await col_users.update_one({"_id": self._id}, {"$set": {"locale": locale}})
|
||||
|
||||
@ -98,7 +97,15 @@ class PyroUser:
|
||||
return self.locale
|
||||
|
||||
async def update_state(self, enabled: bool = False) -> bool:
|
||||
logger.debug("%s's state has been set to %s", self.id, enabled)
|
||||
"""Update user's state (enabled/disabled)
|
||||
|
||||
### Args:
|
||||
* enabled (`bool`, *optional*): Whether the user is enabled. Defaults to `False`.
|
||||
|
||||
### Returns:
|
||||
* `bool`: User's current state
|
||||
"""
|
||||
logger.info("%s's state has been set to %s", self.id, enabled)
|
||||
|
||||
await col_users.update_one({"_id": self._id}, {"$set": {"enabled": enabled}})
|
||||
|
||||
@ -106,8 +113,16 @@ class PyroUser:
|
||||
|
||||
return self.enabled
|
||||
|
||||
async def update_location(self, location_id: int = 0) -> Location:
|
||||
logger.debug("%s's location has been set to %s", self.id, location_id)
|
||||
async def update_location(self, location_id: int) -> Location:
|
||||
"""Update user's location and move their time to the new timezone (if the user had a location set previously)
|
||||
|
||||
### Args:
|
||||
* location_id (`int`): ID of the location
|
||||
|
||||
### Returns:
|
||||
`Location`: New location
|
||||
"""
|
||||
logger.info("%s's location has been set to %s", self.id, location_id)
|
||||
|
||||
await col_users.update_one(
|
||||
{"_id": self._id}, {"$set": {"location": location_id}}
|
||||
@ -136,7 +151,15 @@ class PyroUser:
|
||||
return self.location
|
||||
|
||||
async def update_offset(self, offset: int = 1) -> int:
|
||||
logger.debug("%s's offset has been set to %s", self.id, offset)
|
||||
"""Update the offset of the reminder (in days)
|
||||
|
||||
### Args:
|
||||
* offset (`int`, *optional*): Offset in days. Defaults to `1`.
|
||||
|
||||
### Returns:
|
||||
* `int`: Offset in days
|
||||
"""
|
||||
logger.info("%s's offset has been set to %s", self.id, offset)
|
||||
|
||||
await col_users.update_one({"_id": self._id}, {"$set": {"offset": offset}})
|
||||
|
||||
@ -145,7 +168,16 @@ class PyroUser:
|
||||
return offset
|
||||
|
||||
async def update_time(self, hour: int = 16, minute: int = 0) -> Tuple[int, int]:
|
||||
logger.debug("%s's time has been set to %s h. %s m.", self.id, hour, minute)
|
||||
"""Update the time of the reminder (hour and minute, for UTC timezone)
|
||||
|
||||
### Args:
|
||||
* hour (`int`, *optional*): Hour of the reminder. Defaults to `16`.
|
||||
* minute (`int`, *optional*): Minute of the reminder. Defaults to `0`.
|
||||
|
||||
### Returns:
|
||||
* `Tuple[int, int]`: Hour and minute of the reminder
|
||||
"""
|
||||
logger.info("%s's time has been set to %s h. %s m.", self.id, hour, minute)
|
||||
|
||||
await col_users.update_one(
|
||||
{"_id": self._id}, {"$set": {"time_hour": hour, "time_minute": minute}}
|
||||
@ -157,16 +189,27 @@ class PyroUser:
|
||||
return self.time_hour, self.time_minute
|
||||
|
||||
async def delete(self) -> None:
|
||||
logger.debug("%s's data has been deleted", self.id)
|
||||
"""Delete the database record of the user"""
|
||||
logger.info("%s's data has been deleted", self.id)
|
||||
|
||||
await col_users.delete_one({"_id": self._id})
|
||||
|
||||
async def checkout(self) -> Mapping[str, Any]:
|
||||
logger.debug("%s's data has been checked out", self.id)
|
||||
"""Checkout the user's database record
|
||||
|
||||
### Raises:
|
||||
* `KeyError`: Database record of the user was not found
|
||||
|
||||
### Returns:
|
||||
* `Mapping[str, Any]`: Database record
|
||||
"""
|
||||
logger.info("%s's data has been checked out", self.id)
|
||||
|
||||
db_entry = await col_users.find_one({"_id": self._id})
|
||||
|
||||
if db_entry is None:
|
||||
raise KeyError(
|
||||
f"DB record with id {self._id} of user {self.id} is not found"
|
||||
f"DB record with id {self._id} of user {self.id} was not found"
|
||||
)
|
||||
|
||||
del db_entry["_id"] # type: ignore
|
||||
|
Reference in New Issue
Block a user