mirror of
https://github.com/MrSedan/neuro-reply-bot-reworked.git
synced 2026-01-14 21:49:42 +03:00
Moved from aioschedule to APSchedule
This commit is contained in:
@@ -1,3 +1,7 @@
|
|||||||
venv
|
venv
|
||||||
.env.example
|
.env.example
|
||||||
Dockerfile
|
Dockerfile
|
||||||
|
.vscode
|
||||||
|
LICENSE
|
||||||
|
Dockerfile.dev
|
||||||
|
.gitignore
|
||||||
@@ -7,4 +7,6 @@ API_URL="http://localhost:3000"
|
|||||||
REDIS_HOST="localhost"
|
REDIS_HOST="localhost"
|
||||||
REDIS_PORT=6379
|
REDIS_PORT=6379
|
||||||
REDIS_PASSWORD=123
|
REDIS_PASSWORD=123
|
||||||
REDIS_DB=0
|
REDIS_DB=0
|
||||||
|
|
||||||
|
LOGGING_LVL=WARNING
|
||||||
@@ -4,6 +4,6 @@ WORKDIR /app
|
|||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
RUN pip install -r requirements.txt
|
RUN pip install --no-cache-dir -U -r requirements.txt
|
||||||
|
|
||||||
CMD [ "python", "main.py" ]
|
CMD [ "python", "main.py" ]
|
||||||
@@ -10,7 +10,7 @@ from .handler import MessageHandlerABC
|
|||||||
|
|
||||||
class PostCommand(MessageHandlerABC):
|
class PostCommand(MessageHandlerABC):
|
||||||
filter = Command('post')
|
filter = Command('post')
|
||||||
async def _command(self, message: types.Message):
|
async def _command(self, message: types.Message | None = None):
|
||||||
settings = neuroTypes.BotSettings.get_instance()
|
settings = neuroTypes.BotSettings.get_instance()
|
||||||
try:
|
try:
|
||||||
post = await neuroapi.post.get_post_to_post()
|
post = await neuroapi.post.get_post_to_post()
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
import logging
|
||||||
from typing import Coroutine
|
from typing import Coroutine
|
||||||
|
|
||||||
import aioschedule as schedule
|
|
||||||
from aiogram import Bot, types
|
from aiogram import Bot, types
|
||||||
from aiogram.filters import Command
|
from aiogram.filters import Command
|
||||||
|
from apscheduler.schedulers.asyncio import AsyncIOScheduler
|
||||||
|
|
||||||
from neuroapi import neuroapi
|
from neuroapi import neuroapi
|
||||||
|
from neuroapi.config import GlobalConfig
|
||||||
from neuroapi.types import BotSettings
|
from neuroapi.types import BotSettings
|
||||||
|
|
||||||
from .handler import MessageHandlerABC
|
from .handler import MessageHandlerABC
|
||||||
@@ -18,28 +20,25 @@ class UpdateSettingsCommand(MessageHandlerABC):
|
|||||||
|
|
||||||
async def settings_and_schedule_checker(self):
|
async def settings_and_schedule_checker(self):
|
||||||
await self._auto_update_settings()
|
await self._auto_update_settings()
|
||||||
while 1:
|
|
||||||
await schedule.run_pending()
|
|
||||||
await asyncio.sleep(1)
|
|
||||||
|
|
||||||
async def _auto_update_settings(self):
|
async def _auto_update_settings(self):
|
||||||
self.settings = await neuroapi.bot_settings.get()
|
self.settings = await neuroapi.bot_settings.get()
|
||||||
schedule.clear()
|
self.scheduler.remove_all_jobs()
|
||||||
schedule.every().minute.do(self._auto_update_settings)
|
self.scheduler.add_job(self._auto_update_settings, 'interval', seconds=60)
|
||||||
|
|
||||||
# TODO: Сделать в бэке и в боте, чтоб дни тоже можно было в настройках хранить
|
# TODO: Сделать в бэке и в боте, чтоб дни тоже можно было в настройках хранить
|
||||||
for i in self.settings.message_times:
|
for i in self.settings.message_times:
|
||||||
schedule.every().monday.at(i).do(self.post, None)
|
self.scheduler.add_job(self.post, 'cron', day_of_week='mon-sun', hour=i.split(':')[0], minute=i.split(':')[1])
|
||||||
schedule.every().tuesday.at(i).do(self.post, None)
|
logging.debug(self.scheduler.get_jobs())
|
||||||
schedule.every().wednesday.at(i).do(self.post, None)
|
|
||||||
schedule.every().thursday.at(i).do(self.post, None)
|
|
||||||
schedule.every().friday.at(i).do(self.post, None)
|
|
||||||
schedule.every().sunday.at(i).do(self.post, None)
|
|
||||||
|
|
||||||
def __init__(self, bot: Bot, post_command: Coroutine, *args) -> None:
|
def __init__(self, bot: Bot, post_command: Coroutine, *args) -> None:
|
||||||
super().__init__(bot)
|
super().__init__(bot)
|
||||||
self.post = post_command
|
self.post = post_command
|
||||||
asyncio.create_task(self.settings_and_schedule_checker())
|
config = GlobalConfig()
|
||||||
|
logging.debug(config)
|
||||||
|
self.scheduler = AsyncIOScheduler(event_loop=asyncio.get_event_loop())
|
||||||
|
self.scheduler.add_job(self.settings_and_schedule_checker, 'interval', seconds=60)
|
||||||
|
self.scheduler.start()
|
||||||
|
|
||||||
async def _command(self, mes: types.Message):
|
async def _command(self, mes: types.Message):
|
||||||
self.settings = await neuroapi.bot_settings.get_update()
|
self.settings = await neuroapi.bot_settings.get_update()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
aiogram==3.3.0
|
aiogram==3.3.0
|
||||||
aioschedule @ https://github.com/AleksHeller/python-aioschedule/archive/refs/heads/master.zip
|
APScheduler==3.10.4
|
||||||
requests==2.31.0
|
requests==2.31.0
|
||||||
python-dateutil==2.8.2
|
python-dateutil==2.8.2
|
||||||
aiohttp==3.9.3
|
aiohttp==3.9.3
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
time = ["12:00", "14:00", "16:00", "18:00"]
|
|
||||||
Reference in New Issue
Block a user