feat: add realtime capturing
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
from userbot.modules.contacts.cache import ContactCache
|
||||
|
||||
__all__ = ["ContactCache"]
|
||||
@@ -0,0 +1,20 @@
|
||||
from pyrogram import Client
|
||||
|
||||
from utils.logging import logger
|
||||
|
||||
|
||||
class ContactCache:
|
||||
def __init__(self, client: Client) -> None:
|
||||
self._client = client
|
||||
self.ids: set[int] = set()
|
||||
|
||||
async def refresh(self) -> None:
|
||||
contacts = await self._client.get_contacts()
|
||||
self.ids = {user.id for user in contacts}
|
||||
logger.info(f"[green]Contacts cached:[/] {len(self.ids)}")
|
||||
|
||||
def mark(self, user_id: int, *, is_contact: bool) -> None:
|
||||
if is_contact:
|
||||
self.ids.add(user_id)
|
||||
else:
|
||||
self.ids.discard(user_id)
|
||||
Reference in New Issue
Block a user