mirror of
https://github.com/BEDOLAGA-DEV/remnawave-bedolaga-telegram-bot.git
synced 2026-02-17 01:20:34 +00:00
26 lines
952 B
Python
26 lines
952 B
Python
from pathlib import Path
|
|
from aiogram.types import Message, FSInputFile, InputMediaPhoto
|
|
|
|
LOGO_PATH = Path("vpn_logo.png")
|
|
|
|
_original_answer = Message.answer
|
|
_original_edit_text = Message.edit_text
|
|
|
|
async def _answer_with_photo(self: Message, text: str = None, **kwargs):
|
|
if LOGO_PATH.exists():
|
|
return await self.answer_photo(FSInputFile(LOGO_PATH), caption=text, **kwargs)
|
|
return await _original_answer(self, text, **kwargs)
|
|
|
|
async def _edit_with_photo(self: Message, text: str, **kwargs):
|
|
if self.photo:
|
|
media_kwargs = {"media": self.photo[-1].file_id, "caption": text}
|
|
if "parse_mode" in kwargs:
|
|
media_kwargs["parse_mode"] = kwargs.pop("parse_mode")
|
|
return await self.edit_media(InputMediaPhoto(**media_kwargs), **kwargs)
|
|
return await _original_edit_text(self, text, **kwargs)
|
|
|
|
def patch_message_methods():
|
|
Message.answer = _answer_with_photo
|
|
Message.edit_text = _edit_with_photo
|
|
|