2021-09-06 02:15:41 +03:00
|
|
|
from aiogram.types import Message, CallbackQuery, InlineKeyboardMarkup
|
2021-06-29 15:29:41 +03:00
|
|
|
from aiogram.utils.exceptions import TelegramAPIError
|
|
|
|
|
2021-09-06 02:15:41 +03:00
|
|
|
from typing import Optional
|
|
|
|
|
2021-06-29 15:29:41 +03:00
|
|
|
|
|
|
|
async def try_delete_message(message: Message):
|
|
|
|
try:
|
|
|
|
await message.delete()
|
|
|
|
except TelegramAPIError:
|
|
|
|
pass
|
2021-09-06 02:15:41 +03:00
|
|
|
|
|
|
|
|
|
|
|
async def edit_or_create(call: CallbackQuery, message: str,
|
|
|
|
reply_markup: Optional[InlineKeyboardMarkup] = None,
|
|
|
|
parse_mode: Optional[str] = None):
|
|
|
|
try:
|
|
|
|
await call.message.edit_text(message, parse_mode=parse_mode)
|
|
|
|
await call.message.edit_reply_markup(reply_markup)
|
|
|
|
except TelegramAPIError: # кнопка устарела
|
|
|
|
await call.bot.send_message(call.message.chat.id, text=message, reply_markup=reply_markup,
|
|
|
|
parse_mode=parse_mode)
|
2021-09-17 11:35:51 +03:00
|
|
|
|
|
|
|
|
|
|
|
def button_text_limit(data: str) -> str:
|
|
|
|
max_len = 30
|
|
|
|
if len(data) > max_len:
|
|
|
|
data = data[:max_len-4] + "..."
|
|
|
|
return data
|