diff --git a/BotCode/routers/commands/user_cmd/help_cmd.py b/BotCode/routers/commands/user_cmd/help_cmd.py index a9306b0..5156676 100644 --- a/BotCode/routers/commands/user_cmd/help_cmd.py +++ b/BotCode/routers/commands/user_cmd/help_cmd.py @@ -2,6 +2,8 @@ # Работа с командой /help, для вывода помощи пользователю from BotLibrary import CommandHandler +from BotCode.keyboards import get_start_kb + # Создание команды /help с нужными параметрами help_cmd = CommandHandler( @@ -9,5 +11,7 @@ help_cmd = CommandHandler( description="Получить помощь", keywords=["help", "info", "помощь", "инфо", "информация", "рудз", "штащ", "byaj", "gjvjom", "byajhvfwbz"], callbackdata="keywords", + keyboard=get_start_kb, text_msg="Привет! Это команда помощи. Тут ты можешь узнать, как пользоваться ботом.", + media="gif", path_to_media="https://t.me/c/2442589033/74653" ) diff --git a/BotCode/routers/commands/user_cmd/start_cmd.py b/BotCode/routers/commands/user_cmd/start_cmd.py index 0172a52..e9b2670 100644 --- a/BotCode/routers/commands/user_cmd/start_cmd.py +++ b/BotCode/routers/commands/user_cmd/start_cmd.py @@ -13,4 +13,5 @@ start_cmd = CommandHandler( callbackdata="keywords", text_msg="Старт!", keyboard=get_start_kb, + media="file", path_to_media="https://gdb.voanews.com/455403fe-91ea-4abe-8d29-3862282ec56b_cx0_cy9_cw0_w408_r1_s.jpg", ) diff --git a/BotLibrary/samples/user_cmd_class.py b/BotLibrary/samples/user_cmd_class.py index 9561222..6fa2bd9 100644 --- a/BotLibrary/samples/user_cmd_class.py +++ b/BotLibrary/samples/user_cmd_class.py @@ -5,6 +5,7 @@ from aiogram import Router, types, F from aiogram.enums import ChatAction from aiogram.filters import Command +from BotLibrary import valid_url from ProjectsFiles import BotVar from BotLibrary.validators import username from BotLibrary.loggers import Logs @@ -55,6 +56,8 @@ class CommandHandler: async def handler(self, message: types.Message): """Основной хэндлер команды.""" try: + url : bool = valid_url(self.path_to_media) + Logs.info(log_type=self.log_type, user=username(message), text=f"использовал(а) команду /{self.name}") if self.media == "message": await message.reply( @@ -70,46 +73,115 @@ class CommandHandler: ) else: if self.media == "photo": - await message.reply_photo( - photo="https://vos-mo.ru/upload/iblock/329/g0s939ge8o1n8xp7rcqnw9kkz9mcfrg2/risunok.jpg", - caption=self.text_msg) + if url: + await message.reply_photo(photo=self.path_to_media, + caption=self.text_msg, + reply_markup=self.keyboard() if self.keyboard else None, + parse_mode=self.parse_mode, + disable_notification=self.disable_notification) + else: + await message.reply_photo(photo=types.FSInputFile(path=self.path_to_media), + caption=self.text_msg, + reply_markup=self.keyboard() if self.keyboard else None, + parse_mode=self.parse_mode, + disable_notification=self.disable_notification) + if self.chat_action: await message.bot.send_chat_action( chat_id=message.chat.id, action=ChatAction.UPLOAD_PHOTO, ) - if self.media == "gif": - await message.reply_animation( - animation="https://vos-mo.ru/upload/iblock/329/g0s939ge8o1n8xp7rcqnw9kkz9mcfrg2/risunok.jpg") + elif self.media == "gif": + if url: + await message.reply_animation(animation=self.path_to_media, + caption=self.text_msg, + reply_markup=self.keyboard() if self.keyboard else None, + parse_mode=self.parse_mode, + disable_notification=self.disable_notification) + else: + await message.reply_animation(animation=types.FSInputFile(path=self.path_to_media), + caption=self.text_msg, + reply_markup=self.keyboard() if self.keyboard else None, + parse_mode=self.parse_mode, + disable_notification=self.disable_notification) if self.chat_action: await message.bot.send_chat_action( chat_id=message.chat.id, action=ChatAction.UPLOAD_VIDEO, ) - if self.media == "video": + + elif self.media == "video": + if url: + await message.reply_video(video=self.path_to_media, + caption=self.text_msg, + reply_markup=self.keyboard() if self.keyboard else None, + parse_mode=self.parse_mode, + disable_notification=self.disable_notification) + else: + await message.reply_video(video=types.FSInputFile(path=self.path_to_media), + caption=self.text_msg, + reply_markup=self.keyboard() if self.keyboard else None, + parse_mode=self.parse_mode, + disable_notification=self.disable_notification) if self.chat_action: await message.bot.send_chat_action( chat_id=message.chat.id, action=ChatAction.UPLOAD_VIDEO, ) - if self.media == "videonote": + elif self.media == "videonote": + if url: + await message.reply_video_note(video_note=self.path_to_media, + caption=self.text_msg, + reply_markup=self.keyboard() if self.keyboard else None, + parse_mode=self.parse_mode, + disable_notification=self.disable_notification) + else: + await message.reply_video_note(video_note=types.FSInputFile(path=self.path_to_media), + caption=self.text_msg, + reply_markup=self.keyboard() if self.keyboard else None, + parse_mode=self.parse_mode, + disable_notification=self.disable_notification) if self.chat_action: await message.bot.send_chat_action( chat_id=message.chat.id, action=ChatAction.UPLOAD_VIDEO_NOTE, ) - if self.media == "audio": + elif self.media == "audio": + if url: + await message.reply_audio(audio=self.path_to_media, + caption=self.text_msg, + reply_markup=self.keyboard() if self.keyboard else None, + parse_mode=self.parse_mode, + disable_notification=self.disable_notification) + else: + await message.reply_audio(audio=types.FSInputFile(path=self.path_to_media), + caption=self.text_msg, + reply_markup=self.keyboard() if self.keyboard else None, + parse_mode=self.parse_mode, + disable_notification=self.disable_notification) if self.chat_action: await message.bot.send_chat_action( chat_id=message.chat.id, action=ChatAction.UPLOAD_VOICE, ) - if self.media == "file": + elif self.media == "file": + if url: + await message.reply_document(document=self.path_to_media, + caption=self.text_msg, + reply_markup=self.keyboard() if self.keyboard else None, + parse_mode=self.parse_mode, + disable_notification=self.disable_notification) + else: + await message.reply_document(document=types.FSInputFile(path=self.path_to_media), + caption=self.text_msg, + reply_markup=self.keyboard() if self.keyboard else None, + parse_mode=self.parse_mode, + disable_notification=self.disable_notification) if self.chat_action: await message.bot.send_chat_action( chat_id=message.chat.id, diff --git a/BotLibrary/validators/__init__.py b/BotLibrary/validators/__init__.py index 6707043..a45718c 100644 --- a/BotLibrary/validators/__init__.py +++ b/BotLibrary/validators/__init__.py @@ -4,3 +4,4 @@ # Экспортирование модулей во внешние слои проекта from .email_valid import * from .username import * +from .url_valid import * diff --git a/BotLibrary/validators/url_valid.py b/BotLibrary/validators/url_valid.py new file mode 100644 index 0000000..9729dcb --- /dev/null +++ b/BotLibrary/validators/url_valid.py @@ -0,0 +1,24 @@ +# BotLibrary/validators/url_valid.py +# Валидатор ссылок на регулярных выражениях + +import re + +# Настройка экспорта из этого модуля +__all__ = ("valid_url",) + + +# Функция определения является ли строка ссылкой +def valid_url(url: str) -> bool: + """ + Проверяет, является ли строка валидной ссылкой (URL). + + :param url: Строка для проверки. + :return: True, если строка является валидным URL, иначе False. + """ + url_pattern = re.compile( + r'^(https?://)?' # Протокол (http или https, необязателен) + r'([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}' # Домен + r'(:\d+)?' # Порт (необязателен) + r'(/[-a-zA-Z0-9@:%_+.~#?&//=]*)?$' # Путь, параметры и фрагменты + ) + return bool(url_pattern.match(url)) diff --git a/ProjectsFiles/configs/.env b/ProjectsFiles/configs/.env index ff89f56..c4a15e3 100644 --- a/ProjectsFiles/configs/.env +++ b/ProjectsFiles/configs/.env @@ -2,9 +2,9 @@ # Файл-хранилище всех секретных токенов и ключей # Токены от ботов телеграмма -BOT_TOKEN=8076305634:AAGNoo4N-WVP9mbeD76G7SLClSsySw23nGw -BOT1_TOKEN=ТОКЕН_БОТА1 -BOT2_TOKEN=ТОКЕН_БОТА2 +BOT_TOKEN=7193685715:AAHFEnFreZGLQcHj8_wdWYJ2FLPrB-A-hzY +BOT1_TOKEN=8076305634:AAGNoo4N-WVP9mbeD76G7SLClSsySw23nGw +BOT2_TOKEN= # Ключи от API API_KEY=КЛЮЧ_ОТ_СТОРОННЕГО_API diff --git a/ProjectsFiles/media/Avatar/bot_avatar.png b/ProjectsFiles/media/Avatar/bot_avatar.png new file mode 100644 index 0000000..c8ba74c Binary files /dev/null and b/ProjectsFiles/media/Avatar/bot_avatar.png differ diff --git a/ProjectsFiles/media/Avatar/console_avatar.png b/ProjectsFiles/media/Avatar/console_avatar.png new file mode 100644 index 0000000..c8ba74c Binary files /dev/null and b/ProjectsFiles/media/Avatar/console_avatar.png differ