Added comments

This commit is contained in:
2024-02-15 16:58:37 +03:00
parent 19cf282e08
commit dba5c60080
42 changed files with 388 additions and 11 deletions

View File

@@ -14,21 +14,25 @@ from .handler import MessageHandlerABC
class UpdateSettingsCommand(MessageHandlerABC):
"""Command to update settings manually or by timer"""
settings: BotSettings
post: Coroutine
post: Coroutine # async post command method to post posts to channel by timer
filter = Command('update_settings')
async def settings_and_schedule_checker(self):
await self._auto_update_settings()
async def _auto_update_settings(self):
"""
An asynchronous function that updates settings and schedules jobs.
"""
self.settings = await neuroapi.bot_settings.get()
self.scheduler.remove_all_jobs()
self.scheduler.add_job(self._auto_update_settings, 'interval', seconds=60)
self.scheduler.add_job(self._auto_update_settings, 'interval', seconds=60) # Auto updating settings
# TODO: Сделать в бэке и в боте, чтоб дни тоже можно было в настройках хранить
for i in self.settings.message_times:
self.scheduler.add_job(self.post, 'cron', day_of_week='mon-sun', hour=i.split(':')[0], minute=i.split(':')[1])
self.scheduler.add_job(self.post, 'cron', day_of_week='mon-sun', hour=i.split(':')[0], minute=i.split(':')[1]) # Auto posting
logging.debug(self.scheduler.get_jobs())
def __init__(self, bot: Bot, post_command: Coroutine, *args) -> None:
@@ -41,6 +45,7 @@ class UpdateSettingsCommand(MessageHandlerABC):
self.scheduler.start()
async def _command(self, mes: types.Message):
"""Clearing server cache and returning actual settings"""
self.settings = await neuroapi.bot_settings.get_update()
await mes.answer('Настройки обновлены')