Complete overhaul seems to be done
This commit is contained in:
@@ -32,6 +32,7 @@ from pyrogram.types import (
|
||||
BotCommandScopeDefault,
|
||||
Message,
|
||||
)
|
||||
from pytimeparse.timeparse import timeparse
|
||||
from ujson import dumps, loads
|
||||
|
||||
from classes.commandset import CommandSet
|
||||
@@ -50,6 +51,7 @@ from modules.api_client import (
|
||||
from modules.database import col_submitted
|
||||
from modules.http_client import http_session
|
||||
from modules.scheduler import scheduler
|
||||
from modules.sender import send_content
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -89,6 +91,8 @@ class PyroClient(Client):
|
||||
self.in_all_locales = self.bot_locale.in_all_locales
|
||||
self.in_every_locale = self.bot_locale.in_every_locale
|
||||
|
||||
self.sender_session = ClientSession()
|
||||
|
||||
async def start(self):
|
||||
await super().start()
|
||||
|
||||
@@ -189,6 +193,25 @@ class PyroClient(Client):
|
||||
kwargs={"command_sets": await self.collect_commands()},
|
||||
)
|
||||
|
||||
if self.config["mode"]["post"]:
|
||||
if self.config["posting"]["use_interval"]:
|
||||
scheduler.add_job(
|
||||
send_content,
|
||||
"interval",
|
||||
seconds=timeparse(self.config["posting"]["interval"]),
|
||||
args=[self, self.sender_session],
|
||||
)
|
||||
else:
|
||||
for entry in self.config["posting"]["time"]:
|
||||
dt_obj = datetime.strptime(entry, "%H:%M")
|
||||
scheduler.add_job(
|
||||
send_content,
|
||||
"cron",
|
||||
hour=dt_obj.hour,
|
||||
minute=dt_obj.minute,
|
||||
args=[self, self.sender_session],
|
||||
)
|
||||
|
||||
scheduler.start()
|
||||
except BadRequest:
|
||||
logger.warning("Unable to send message to report chat.")
|
||||
@@ -208,6 +231,7 @@ class PyroClient(Client):
|
||||
except BadRequest:
|
||||
logger.warning("Unable to send message to report chat.")
|
||||
await http_session.close()
|
||||
await self.sender_session.close()
|
||||
await super().stop()
|
||||
logger.warning("Bot stopped with PID %s.", getpid())
|
||||
|
||||
|
Reference in New Issue
Block a user