0.7.2 теперь сборщик команд имеет все типы
This commit is contained in:
@@ -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"
|
||||
)
|
||||
|
||||
@@ -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",
|
||||
)
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -4,3 +4,4 @@
|
||||
# Экспортирование модулей во внешние слои проекта
|
||||
from .email_valid import *
|
||||
from .username import *
|
||||
from .url_valid import *
|
||||
|
||||
24
BotLibrary/validators/url_valid.py
Normal file
24
BotLibrary/validators/url_valid.py
Normal 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))
|
||||
@@ -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
|
||||
|
||||
BIN
ProjectsFiles/media/Avatar/bot_avatar.png
Normal file
BIN
ProjectsFiles/media/Avatar/bot_avatar.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.4 KiB |
BIN
ProjectsFiles/media/Avatar/console_avatar.png
Normal file
BIN
ProjectsFiles/media/Avatar/console_avatar.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.4 KiB |
Reference in New Issue
Block a user