Improving class
This commit is contained in:
parent
03ebeafdd4
commit
d40a17e668
@ -1,8 +1,9 @@
|
|||||||
from app import isAnAdmin
|
from app import isAnAdmin
|
||||||
from typing import List, Union
|
from typing import Any, List, Union
|
||||||
from pyrogram.types import User, ChatMember, ChatPrivileges, Chat
|
from pyrogram.types import User, ChatMember, ChatPrivileges, Chat
|
||||||
from pyrogram.client import Client
|
from pyrogram.client import Client
|
||||||
from modules.database import col_users, col_context, col_warnings, col_applications, col_sponsorships
|
from modules.database import col_users, col_context, col_warnings, col_applications, col_sponsorships
|
||||||
|
from modules.logging import logWrite
|
||||||
from modules.utils import configGet
|
from modules.utils import configGet
|
||||||
|
|
||||||
class UserNotFoundError(Exception):
|
class UserNotFoundError(Exception):
|
||||||
@ -42,7 +43,12 @@ class HoloUser():
|
|||||||
|
|
||||||
self.db_id = holo_user["_id"]
|
self.db_id = holo_user["_id"]
|
||||||
|
|
||||||
|
self.link = holo_user["link"]
|
||||||
self.label = holo_user["label"]
|
self.label = holo_user["label"]
|
||||||
|
self.name = holo_user["tg_name"]
|
||||||
|
self.phone = holo_user["tg_phone"]
|
||||||
|
self.locale = holo_user["tg_locale"]
|
||||||
|
self.username = holo_user["tg_username"]
|
||||||
|
|
||||||
async def set_label(self, app: Client, chat: Chat, label: str):
|
async def set_label(self, app: Client, chat: Chat, label: str):
|
||||||
"""Set label in destination group
|
"""Set label in destination group
|
||||||
@ -67,4 +73,17 @@ class HoloUser():
|
|||||||
if (not await isAnAdmin(self.id)) and (chat.id == configGet("admin_group")):
|
if (not await isAnAdmin(self.id)) and (chat.id == configGet("admin_group")):
|
||||||
await app.promote_chat_member(configGet("destination_group"), self.id, privileges=ChatPrivileges(
|
await app.promote_chat_member(configGet("destination_group"), self.id, privileges=ChatPrivileges(
|
||||||
can_manage_chat=False
|
can_manage_chat=False
|
||||||
))
|
))
|
||||||
|
|
||||||
|
def set(self, key: str, value: Any) -> None:
|
||||||
|
"""Set attribute data and save it into database
|
||||||
|
|
||||||
|
### Args:
|
||||||
|
* `key` (`str`): Attribute to be changed
|
||||||
|
* `value` (`Any`): Value to set
|
||||||
|
"""
|
||||||
|
if not hasattr(self, key):
|
||||||
|
raise AttributeError()
|
||||||
|
setattr(self, key, value)
|
||||||
|
col_users.update_one(filter={"_id": self.db_id}, update={ "$set": { key: value } }, upsert=True)
|
||||||
|
logWrite(f"Set attribute {key} of user {self.id} to {value}")
|
Reference in New Issue
Block a user