Skip to content

Commit

Permalink
update: Add bot Client
Browse files Browse the repository at this point in the history
  • Loading branch information
SilentDemonSD committed Apr 26, 2024
1 parent 3bceb53 commit e6e3e72
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?***
Expand Down
14 changes: 11 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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('|'):
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions sample.env
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit e6e3e72

Please sign in to comment.