Integrated the scheduler
This commit is contained in:
parent
7f054a6d93
commit
9af6d5cb7c
@ -7,6 +7,8 @@ from typing import List, Union
|
||||
|
||||
try:
|
||||
import pyrogram
|
||||
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||
from apscheduler.schedulers.background import BackgroundScheduler
|
||||
from pyrogram.client import Client
|
||||
from pyrogram.errors import BadRequest
|
||||
from pyrogram.handlers.message_handler import MessageHandler
|
||||
@ -40,7 +42,9 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PyroClient(Client):
|
||||
def __init__(self):
|
||||
def __init__(
|
||||
self, scheduler: Union[AsyncIOScheduler, BackgroundScheduler, None] = None
|
||||
):
|
||||
with open("config.json", "r", encoding="utf-8") as f:
|
||||
self.config: dict = loads(f.read())
|
||||
super().__init__(
|
||||
@ -70,7 +74,9 @@ class PyroClient(Client):
|
||||
self.in_all_locales = self.bot_locale.in_all_locales
|
||||
self.in_every_locale = self.bot_locale.in_every_locale
|
||||
|
||||
async def start(self, scheduler):
|
||||
self.scheduler: Union[AsyncIOScheduler, BackgroundScheduler, None] = scheduler
|
||||
|
||||
async def start(self):
|
||||
await super().start()
|
||||
|
||||
self.start_time = time()
|
||||
@ -89,14 +95,17 @@ class PyroClient(Client):
|
||||
text=f"Bot started PID `{getpid()}`",
|
||||
)
|
||||
|
||||
scheduler.add_job(
|
||||
if self.scheduler is None:
|
||||
return
|
||||
|
||||
self.scheduler.add_job(
|
||||
self.register_commands,
|
||||
trigger="date",
|
||||
run_date=datetime.now() + timedelta(seconds=5),
|
||||
kwargs={"command_sets": await self.collect_commands()},
|
||||
)
|
||||
|
||||
scheduler.start()
|
||||
self.scheduler.start()
|
||||
except BadRequest:
|
||||
logger.warning("Unable to send message to report chat.")
|
||||
|
||||
|
@ -25,8 +25,8 @@ classifiers = [
|
||||
dependencies = ["aiofiles~=23.1.0"]
|
||||
|
||||
[project.optional-dependencies]
|
||||
pycord = ["py-cord>=2.0.0"]
|
||||
pyrogram = ["pyrogram>=2.0.0"]
|
||||
pycord = ["py-cord~=2.4.1"]
|
||||
pyrogram = ["pyrogram~=2.0.106", "apscheduler~=3.10.1"]
|
||||
speed = ["ujson~=5.8.0"]
|
||||
|
||||
[project.urls]
|
||||
|
Loading…
Reference in New Issue
Block a user