diff --git a/.gitignore b/.gitignore index adebd1e..8af3f7e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ __pycache__ conf_backup/ logs/ .mypy_cache +psutil diff --git a/app/extra_config.py b/app/extra_config.py index 0b09aa4..7ec3f95 100644 --- a/app/extra_config.py +++ b/app/extra_config.py @@ -1,5 +1,9 @@ from os import environ +ALIVE_MEDIA: str = environ.get( + "ALIVE_MEDIA", "https://telegra.ph/file/a1d35a86c7f54a96188a9.png" +) + BOT_NAME = "PLAIN-UB" DISABLED_SUPERUSERS: list[int] = [] diff --git a/app/plugins/misc/alive.py b/app/plugins/misc/alive.py new file mode 100644 index 0000000..cd91bdb --- /dev/null +++ b/app/plugins/misc/alive.py @@ -0,0 +1,91 @@ +from sys import version_info + +from pyrogram import __version__ as pyro_version +from pyrogram import filters +from pyrogram.raw.types.messages import BotResults +from pyrogram.types import ( + InlineKeyboardButton, + InlineKeyboardMarkup, + InlineQuery, + InlineQueryResultAnimation, + InlineQueryResultPhoto, +) +from ub_core.utils import MediaType, get_type +from ub_core.version import __version__ as core_version + +from app import BOT, Config, Message, bot, extra_config + +PY_VERSION = f"{version_info.major}.{version_info.minor}.{version_info.micro}" + + +@bot.add_cmd(cmd="alive") +async def alive(bot: BOT, message: Message): + # Inline Alive if Dual Mode + if bot.is_user and bot.has_bot: + inline_result: BotResults = await bot.get_inline_bot_results( + bot=bot.bot.me.username, query="inline_alive" + ) + await bot.send_inline_bot_result( + chat_id=message.chat.id, + result_id=inline_result.results[0].id, + query_id=inline_result.query_id, + ) + return + + kwargs = dict( + chat_id=message.chat.id, + caption=await get_alive_text(), + reply_markup=get_alive_buttons(bot=bot), + reply_to_message_id=message.reply_id or message.id, + ) + + if get_type(url=extra_config.ALIVE_MEDIA) == MediaType.PHOTO: + await bot.send_photo(photo=extra_config.ALIVE_MEDIA, **kwargs) + else: + await bot.send_animation( + animation=extra_config.ALIVE_MEDIA, unsave=True, **kwargs + ) + + +if bot.is_bot or bot.has_bot: + + @bot.bot.on_inline_query(filters=filters.regex("^inline_alive$"), group=2) + async def return_inline_alive_results(bot: BOT, inline_query: InlineQuery): + kwargs = dict( + title=f"Send Alive Media.", + caption=await get_alive_text(), + reply_markup=get_alive_buttons(bot.bot), + ) + + if get_type(url=extra_config.ALIVE_MEDIA) == MediaType.PHOTO: + result_type = InlineQueryResultPhoto( + photo_url=extra_config.ALIVE_MEDIA, **kwargs + ) + else: + result_type = InlineQueryResultAnimation( + animation_url=extra_config.ALIVE_MEDIA, **kwargs + ) + + await inline_query.answer(results=[result_type], cache_time=300) + + +async def get_alive_text() -> str: + user_info = await bot.get_users(user_ids=Config.OWNER_ID) + return ( + f"Plain-UB, A simple Telegram User-Bot by Meliodas.\n" + f"\n › User : {user_info.first_name}" + f"\n › Python : v{PY_VERSION}" + f"\n › Pyrogram : v{pyro_version}" + f"\n › Core : v{core_version}" + ) + + +def get_alive_buttons(bot: BOT): + if not bot.is_bot: + return + return InlineKeyboardMarkup( + [ + [InlineKeyboardButton(text=f"UB-Core", url=Config.UPDATE_REPO)], + [InlineKeyboardButton(text=f"Support Group", url="t.me/plainub")], + ] + )