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

@@ -7,6 +7,7 @@ from .handler import MessageHandlerABC
class DeleteCommand(MessageHandlerABC):
"""Command to delete posts"""
filter = Command('delete')
async def _command(self, message: Message):
text = message.text.split()

View File

@@ -7,6 +7,7 @@ from .handler import MessageHandlerABC
class DeletedPostsCommand(MessageHandlerABC):
"""Command to show deleted posts"""
filter = Command('deleted')
async def _command(self, message: Message):
try:

View File

@@ -7,6 +7,7 @@ from .handler import MessageHandlerABC
class EditCommand(MessageHandlerABC):
"""Command to edit posts"""
filter = Command('edit')
async def _command(self, message: types.Message):

View File

@@ -11,6 +11,7 @@ from .handler import MessageHandlerABC
class ForwardMessageCommand(MessageHandlerABC):
"""Command to forward messages from users to admins. Also checking if they're in the channel"""
filter = F.chat.type == 'private'
async def _command(self, message: types.Message):
self.settings = BotSettings.get_instance()

View File

@@ -6,6 +6,7 @@ from aiogram.filters import Filter
class MessageHandlerABC(ABC):
"""Base class for all message handlers"""
bot: Bot
def __init__(self, bot: Bot, *args: Any, **kwargs: Dict[str, Any]) -> None:
@@ -14,13 +15,16 @@ class MessageHandlerABC(ABC):
@abstractmethod
def _command(self, *args, **kwargs):
"""Handler for the command"""
raise NotImplementedError
@property
def handler(self) -> Coroutine[None, None, None]:
"""Command handler method"""
return self._command
@property
@abstractmethod
def filter(self) -> Filter:
"""Filter for the command"""
raise NotImplementedError

View File

@@ -10,6 +10,7 @@ from .handler import MessageHandlerABC
class InfoCommand(MessageHandlerABC):
"""Command to show info about posts"""
filter = Command('info')
async def _command(self, message: types.Message):

View File

@@ -9,6 +9,7 @@ from .handler import MessageHandlerABC
class NewPostCommand(MessageHandlerABC):
"""Command to add new posts with media groups"""
filter = NewPostFilter()
async def _command(self, message: types.Message, album: List[types.Message]):
sorted_album = sorted(album, key=lambda x: x.message_id)
@@ -20,6 +21,7 @@ class NewPostCommand(MessageHandlerABC):
class NewPostSoloCommand(MessageHandlerABC):
"""Command to add new posts without media groups"""
filter = NewSoloPostFilter()
async def _command(self, message: types.Message):
await neuroapi.image.add(str(message.from_user.id), message.photo[-1].file_id, message.has_media_spoiler, message.message_id, message.caption, None, message.caption_entities, message)

View File

@@ -9,6 +9,7 @@ from .handler import MessageHandlerABC
class PostCommand(MessageHandlerABC):
"""Command to post posts manually or by timer"""
filter = Command('post')
async def _command(self, message: types.Message | None = None):
settings = neuroTypes.BotSettings.get_instance()

View File

@@ -9,6 +9,7 @@ from .handler import MessageHandlerABC
class PreviewCommand(MessageHandlerABC):
"""Command to preview posts like it posted to channel"""
filter = Command('preview')
async def _command(self, message: Message):
text = message.text.split()

View File

@@ -6,6 +6,7 @@ from .handler import MessageHandlerABC
class ReplyToUserCommand(MessageHandlerABC):
"""Send reply to user from admins"""
filter = ReplyToUser()
async def _command(self, message: types.Message):
if message.reply_to_message.forward_from is None:

View File

@@ -7,6 +7,7 @@ from .handler import MessageHandlerABC
class RestoreCommand(MessageHandlerABC):
"""Command to restore deleted posts"""
filter = Command('restore')
async def _command(self, message: Message):
try:

View File

@@ -7,6 +7,7 @@ from .handler import MessageHandlerABC
class SettingsCommand(MessageHandlerABC):
"""Command to show active settings"""
filter = Command('settings')
async def _command(self, message: types.Message):
self.settings = BotSettings.get_instance()

View File

@@ -5,6 +5,7 @@ from .handler import MessageHandlerABC
class StartCommand(MessageHandlerABC):
"""Command to get start message"""
filter = CommandStart()
async def _command(self, message: types.Message):

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('Настройки обновлены')