Migrate to async_pymongo
This commit is contained in:
@@ -18,17 +18,19 @@ class PyroClient(PyroClient):
|
||||
* `PyroUser`: PyroUser object
|
||||
"""
|
||||
if (
|
||||
col_users.find_one({"id": user.id if isinstance(user, User) else user})
|
||||
await col_users.find_one(
|
||||
{"id": user.id if isinstance(user, User) else user}
|
||||
)
|
||||
is None
|
||||
):
|
||||
col_users.insert_one(
|
||||
await col_users.insert_one(
|
||||
{
|
||||
"id": user.id if isinstance(user, User) else user,
|
||||
"locale": user.language_code if isinstance(user, User) else None,
|
||||
}
|
||||
)
|
||||
|
||||
db_record = col_users.find_one(
|
||||
db_record = await col_users.find_one(
|
||||
{"id": user.id if isinstance(user, User) else user}
|
||||
)
|
||||
|
||||
|
@@ -1,15 +1,17 @@
|
||||
from dataclasses import dataclass
|
||||
from typing import Union
|
||||
|
||||
from attrs import define
|
||||
from bson import ObjectId
|
||||
|
||||
from modules.database import col_users
|
||||
|
||||
|
||||
@define
|
||||
@dataclass
|
||||
class PyroUser:
|
||||
"""Dataclass of DB entry of a user"""
|
||||
|
||||
__slots__ = ("_id", "id", "locale")
|
||||
|
||||
_id: ObjectId
|
||||
id: int
|
||||
locale: Union[str, None]
|
||||
@@ -20,4 +22,4 @@ class PyroUser:
|
||||
### Args:
|
||||
* locale (`str`): New locale to be set
|
||||
"""
|
||||
col_users.update_one({"_id": self._id}, {"$set": {"locale": locale}})
|
||||
await col_users.update_one({"_id": self._id}, {"$set": {"locale": locale}})
|
||||
|
Reference in New Issue
Block a user