diff --git a/tgbot/utils/const_functions.py b/tgbot/utils/const_functions.py index e473e78..8675823 100644 --- a/tgbot/utils/const_functions.py +++ b/tgbot/utils/const_functions.py @@ -7,7 +7,8 @@ from typing import Union import pytz from aiogram import Bot -from aiogram.types import InlineKeyboardButton, KeyboardButton, WebAppInfo, Message +from aiogram.types import InlineKeyboardButton, KeyboardButton, WebAppInfo, Message, InlineKeyboardMarkup, \ + ReplyKeyboardMarkup from tgbot.data.config import get_admins, BOT_TIMEZONE @@ -38,6 +39,29 @@ async def del_message(message: Message): ... +# Умная отправка сообщений (автоотправка сообщения с фото или без) +async def smart_message( + bot: Bot, + user_id: int, + text: str, + keyboard: Union[InlineKeyboardMarkup, ReplyKeyboardMarkup] = None, + photo: Union[str, None] = None, +): + if photo is not None and photo.title() != "None": + await bot.send_photo( + chat_id=user_id, + photo=photo, + caption=text, + reply_markup=keyboard, + ) + else: + await bot.send_message( + chat_id=user_id, + text=text, + reply_markup=keyboard, + ) + + # Отправка сообщения всем админам async def send_admins(bot: Bot, text: str, markup=None, not_me=0): for admin in get_admins():