2022-06-20 13:55:14 +00:00
|
|
|
import contextlib
|
2022-05-23 12:40:30 +00:00
|
|
|
from os import sep, remove, mkdir
|
|
|
|
from os.path import exists
|
2022-06-26 12:59:36 +00:00
|
|
|
from typing import List, Optional, Union
|
2022-06-20 13:55:14 +00:00
|
|
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
|
|
|
from httpx import AsyncClient
|
|
|
|
|
|
|
|
from pyrogram import Client
|
2022-05-23 12:40:30 +00:00
|
|
|
from pyrogram.types import Message
|
2022-06-26 12:59:36 +00:00
|
|
|
|
|
|
|
from pyromod.utils.conversation import Conversation
|
2022-06-30 06:49:03 +00:00
|
|
|
from pyromod.utils.errors import AlreadyInConversationError, TimeoutConversationError, ListenerCanceled
|
2022-06-26 12:59:36 +00:00
|
|
|
|
2022-05-23 12:40:30 +00:00
|
|
|
from sqlitedict import SqliteDict
|
|
|
|
|
|
|
|
# init folders
|
|
|
|
if not exists("data"):
|
|
|
|
mkdir("data")
|
|
|
|
sqlite = SqliteDict(f"data{sep}data.sqlite", autocommit=True)
|
|
|
|
|
|
|
|
|
|
|
|
def get_sudo_list():
|
|
|
|
return sqlite.get("sudo_list", [])
|
|
|
|
|
|
|
|
|
|
|
|
def _status_sudo():
|
|
|
|
return sqlite.get("sudo_enable", False)
|
|
|
|
|
|
|
|
|
|
|
|
def safe_remove(name: str) -> None:
|
2022-06-20 13:55:14 +00:00
|
|
|
with contextlib.suppress(FileNotFoundError):
|
2022-05-23 12:40:30 +00:00
|
|
|
remove(name)
|
2022-06-20 13:55:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Client(Client): # noqa
|
|
|
|
job: Optional[AsyncIOScheduler] = None
|
2022-05-23 12:40:30 +00:00
|
|
|
|
2022-06-26 12:59:36 +00:00
|
|
|
async def listen(self, chat_id, filters=None, timeout=None) -> Optional[Message]:
|
|
|
|
return
|
|
|
|
|
|
|
|
async def ask(self, chat_id, text, filters=None, timeout=None, *args, **kwargs) -> Optional[Message]:
|
|
|
|
return
|
|
|
|
|
|
|
|
def cancel_listener(self, chat_id):
|
|
|
|
""" Cancel the conversation with the given chat_id. """
|
|
|
|
return
|
|
|
|
|
|
|
|
def cancel_all_listeners(self):
|
|
|
|
""" Cancel all conversations. """
|
|
|
|
return
|
|
|
|
|
|
|
|
def conversation(self, chat_id: Union[int, str],
|
|
|
|
once_timeout: int = 60, filters=None) -> Optional[Conversation]:
|
|
|
|
""" Initialize a conversation with the given chat_id. """
|
|
|
|
return
|
|
|
|
|
2022-05-23 12:40:30 +00:00
|
|
|
|
|
|
|
class Message(Message): # noqa
|
|
|
|
arguments: str
|
|
|
|
parameter: List
|
|
|
|
|
2022-05-25 11:26:50 +00:00
|
|
|
def obtain_message(self) -> Optional[str]:
|
|
|
|
""" Obtains a message from either the reply message or command arguments. """
|
|
|
|
return
|
|
|
|
|
|
|
|
def obtain_user(self) -> Optional[int]:
|
|
|
|
""" Obtains a user from either the reply message or command arguments. """
|
|
|
|
return
|
|
|
|
|
2022-06-20 13:55:14 +00:00
|
|
|
async def delay_delete(self, delete_seconds: int = 60) -> Optional[bool]:
|
|
|
|
return
|
|
|
|
|
2022-05-25 11:26:50 +00:00
|
|
|
async def safe_delete(self, revoke: bool = True) -> None:
|
|
|
|
return
|