0.7.2 теперь сборщик команд имеет все типы

This commit is contained in:
Verum
2025-02-24 05:57:04 +07:00
parent d10a405c59
commit 899ff5aaac
8 changed files with 115 additions and 13 deletions

View File

@@ -2,6 +2,8 @@
# Работа с командой /help, для вывода помощи пользователю # Работа с командой /help, для вывода помощи пользователю
from BotLibrary import CommandHandler from BotLibrary import CommandHandler
from BotCode.keyboards import get_start_kb
# Создание команды /help с нужными параметрами # Создание команды /help с нужными параметрами
help_cmd = CommandHandler( help_cmd = CommandHandler(
@@ -9,5 +11,7 @@ help_cmd = CommandHandler(
description="Получить помощь", description="Получить помощь",
keywords=["help", "info", "помощь", "инфо", "информация", "рудз", "штащ", "byaj", "gjvjom", "byajhvfwbz"], keywords=["help", "info", "помощь", "инфо", "информация", "рудз", "штащ", "byaj", "gjvjom", "byajhvfwbz"],
callbackdata="keywords", callbackdata="keywords",
keyboard=get_start_kb,
text_msg="Привет! Это команда помощи. Тут ты можешь узнать, как пользоваться ботом.", text_msg="Привет! Это команда помощи. Тут ты можешь узнать, как пользоваться ботом.",
media="gif", path_to_media="https://t.me/c/2442589033/74653"
) )

View File

@@ -13,4 +13,5 @@ start_cmd = CommandHandler(
callbackdata="keywords", callbackdata="keywords",
text_msg="Старт!", text_msg="Старт!",
keyboard=get_start_kb, 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",
) )

View File

@@ -5,6 +5,7 @@ from aiogram import Router, types, F
from aiogram.enums import ChatAction from aiogram.enums import ChatAction
from aiogram.filters import Command from aiogram.filters import Command
from BotLibrary import valid_url
from ProjectsFiles import BotVar from ProjectsFiles import BotVar
from BotLibrary.validators import username from BotLibrary.validators import username
from BotLibrary.loggers import Logs from BotLibrary.loggers import Logs
@@ -55,6 +56,8 @@ class CommandHandler:
async def handler(self, message: types.Message): async def handler(self, message: types.Message):
"""Основной хэндлер команды.""" """Основной хэндлер команды."""
try: try:
url : bool = valid_url(self.path_to_media)
Logs.info(log_type=self.log_type, user=username(message), text=f"использовал(а) команду /{self.name}") Logs.info(log_type=self.log_type, user=username(message), text=f"использовал(а) команду /{self.name}")
if self.media == "message": if self.media == "message":
await message.reply( await message.reply(
@@ -70,46 +73,115 @@ class CommandHandler:
) )
else: else:
if self.media == "photo": if self.media == "photo":
await message.reply_photo( if url:
photo="https://vos-mo.ru/upload/iblock/329/g0s939ge8o1n8xp7rcqnw9kkz9mcfrg2/risunok.jpg", await message.reply_photo(photo=self.path_to_media,
caption=self.text_msg) 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: if self.chat_action:
await message.bot.send_chat_action( await message.bot.send_chat_action(
chat_id=message.chat.id, chat_id=message.chat.id,
action=ChatAction.UPLOAD_PHOTO, action=ChatAction.UPLOAD_PHOTO,
) )
if self.media == "gif": elif self.media == "gif":
await message.reply_animation( if url:
animation="https://vos-mo.ru/upload/iblock/329/g0s939ge8o1n8xp7rcqnw9kkz9mcfrg2/risunok.jpg") 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: if self.chat_action:
await message.bot.send_chat_action( await message.bot.send_chat_action(
chat_id=message.chat.id, chat_id=message.chat.id,
action=ChatAction.UPLOAD_VIDEO, 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: if self.chat_action:
await message.bot.send_chat_action( await message.bot.send_chat_action(
chat_id=message.chat.id, chat_id=message.chat.id,
action=ChatAction.UPLOAD_VIDEO, 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: if self.chat_action:
await message.bot.send_chat_action( await message.bot.send_chat_action(
chat_id=message.chat.id, chat_id=message.chat.id,
action=ChatAction.UPLOAD_VIDEO_NOTE, 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: if self.chat_action:
await message.bot.send_chat_action( await message.bot.send_chat_action(
chat_id=message.chat.id, chat_id=message.chat.id,
action=ChatAction.UPLOAD_VOICE, 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: if self.chat_action:
await message.bot.send_chat_action( await message.bot.send_chat_action(
chat_id=message.chat.id, chat_id=message.chat.id,

View File

@@ -4,3 +4,4 @@
# Экспортирование модулей во внешние слои проекта # Экспортирование модулей во внешние слои проекта
from .email_valid import * from .email_valid import *
from .username import * from .username import *
from .url_valid import *

View File

@@ -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))

View File

@@ -2,9 +2,9 @@
# Файл-хранилище всех секретных токенов и ключей # Файл-хранилище всех секретных токенов и ключей
# Токены от ботов телеграмма # Токены от ботов телеграмма
BOT_TOKEN=8076305634:AAGNoo4N-WVP9mbeD76G7SLClSsySw23nGw BOT_TOKEN=7193685715:AAHFEnFreZGLQcHj8_wdWYJ2FLPrB-A-hzY
BOT1_TOKEN=ТОКЕНОТА1 BOT1_TOKEN=8076305634:AAGNoo4N-WVP9mbeD76G7SLClSsySw23nGw
BOT2_TOKEN=ТОКЕНОТА2 BOT2_TOKEN=
# Ключи от API # Ключи от API
API_KEY=КЛЮЧ_ОТ_СТОРОННЕГО_API API_KEY=КЛЮЧ_ОТ_СТОРОННЕГО_API

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.4 KiB