From e6e3e7256bba3ad3ad76a00caa2437c41e93cdd9 Mon Sep 17 00:00:00 2001 From: SilentDemonSD Date: Fri, 26 Apr 2024 18:42:13 +0530 Subject: [PATCH] update: Add bot Client --- README.md | 1 + main.py | 14 +++++++++++--- sample.env | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 101c3c1..0911611 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ _A Simple Telegram Status Updater to Pretify All your Bots for your Channel in s > Default: Telegram Bot Status : - `TIME_ZONE`: Time Zone for Sync with your Local Time > Default: Asia/Kolkata +- `BOT_TOKEN`: (Optional) Only Required if `MSG_BUTTONS` is added for Post Buttons. - `MSG_BUTTONS`: Make Awesome Telegram Buttons to show at the bottom of the Text. > Unlimited Buttons with Any Design ! - ***How to Use ?*** diff --git a/main.py b/main.py index b896078..9401c9d 100644 --- a/main.py +++ b/main.py @@ -46,6 +46,7 @@ API_ID = int(getenv("API_ID", 0)) API_HASH = getenv("API_HASH") PYRO_SESSION = getenv('PYRO_SESSION') +BOT_TOKEN = getenv('BOT_TOKEN') if PYRO_SESSION is None: log.error('PYRO_SESSION is not set') exit(1) @@ -72,6 +73,12 @@ except BaseException as e: log.warning(e) exit(1) +if BOT_TOKEN: + try: + bot = Client("TgBotStatus", api_id=API_ID, api_hash=API_HASH, bot_token=BOT_TOKEN, no_updates=True) + except BaseException as e: + log.warning(e) + exit(1) def progress_bar(current, total): pct = current/total * 100 @@ -114,8 +121,6 @@ async def bot_info(user_id): def make_btns(): btns = [] - if not MSG_BUTTONS: - return None for row in MSG_BUTTONS.split('||'): row_btns = [] for sbtn in row.split('|'): @@ -126,8 +131,11 @@ def make_btns(): async def editMsg(chat_id, message_id, text): try: - return await client.edit_message_text(int(chat_id), int(message_id), text, + post_msg = await client.edit_message_text(int(chat_id), int(message_id), text, disable_web_page_preview=True) + if BOT_TOKEN and MSG_BUTTONS: + async with bot: + await bot.edit_message_reply_markup(post_msg.chat.id, post_msg.id, make_btns()) except FloodWait as f: await sleep(f.value * 1.2) await editMsg(chat_id, message_id, text) diff --git a/sample.env b/sample.env index a1dcdfc..ba5759d 100644 --- a/sample.env +++ b/sample.env @@ -6,5 +6,6 @@ PYRO_SESSION="" # Same Session Supported ## Optional HEADER_MSG="" # Use Markdown / HTML for Formatting FOOTER_MSG="" # Use Markdown / HTML for Formatting +BOT_TOKEN="" # Use Bot to Add Message Buttons MSG_BUTTONS="" # b_text#b_url|b_textb_url||b_text#b_url|b_text#b_url TIME_ZONE="Asia/Kolkata" \ No newline at end of file