genstava789 commited on
Commit ·
3eec2a4
1
Parent(s): 73e1c34
init
Browse files
bot.py
CHANGED
|
@@ -306,37 +306,11 @@ async def download_twitter_media(client: Client, message: Message):
|
|
| 306 |
|
| 307 |
@bot.on_message(filters.command("time"))
|
| 308 |
async def time(client: Client, message: Message):
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
input_value = message.command[1]
|
| 316 |
-
if input_value.startswith('t.me/') or input_value.startswith('https://t.me/'):
|
| 317 |
-
channel_username = '@' + input_value.split('/')[-1]
|
| 318 |
-
elif input_value.startswith('@'):
|
| 319 |
-
channel_username = input_value
|
| 320 |
-
else:
|
| 321 |
-
await message.reply_text("Please provide a valid channel username starting with '@' or a valid channel link starting with 't.me/' or 'https://t.me/'.")
|
| 322 |
-
return
|
| 323 |
-
|
| 324 |
-
try:
|
| 325 |
-
progress_message = await message.reply_text("Fetching channel information...")
|
| 326 |
-
|
| 327 |
-
chat = await client.get_chat(channel_username)
|
| 328 |
-
response = f"*Username:* `{chat.username}`\n*Member count:* `{chat.members_count}`\n*Channel ID:* `{chat.id}`"
|
| 329 |
-
|
| 330 |
-
if chat.photo:
|
| 331 |
-
await progress_message.edit_text("Fetching profile photo...")
|
| 332 |
-
photo_file_id = chat.photo.big_file_id
|
| 333 |
-
photo_path = await client.download_media(photo_file_id, file_name=f"{chat.username}_profile_photo.jpg")
|
| 334 |
-
await message.reply_photo(photo_path, caption=response)
|
| 335 |
-
else:
|
| 336 |
-
await progress_message.edit_text(response)
|
| 337 |
-
except Exception as e:
|
| 338 |
-
response = f"Failed to fetch information: {e}"
|
| 339 |
-
await progress_message.edit_text(response)
|
| 340 |
|
| 341 |
@bot.on_message(filters.command("threads"))
|
| 342 |
async def threads(client: Client, message: Message):
|
|
@@ -509,24 +483,21 @@ async def process_tiktok_link(client: Client, message: Message, url: str):
|
|
| 509 |
|
| 510 |
@bot.on_message(filters.command("info"))
|
| 511 |
async def info_handler(client: Client, message: Message):
|
| 512 |
-
|
| 513 |
-
|
| 514 |
-
if len(message.command) != 2:
|
| 515 |
-
await message.reply_text(f"Usage: /info <channel_username_or_link>")
|
| 516 |
return
|
| 517 |
|
| 518 |
-
input_value = message.
|
| 519 |
if input_value.startswith('t.me/') or input_value.startswith('https://t.me/'):
|
| 520 |
channel_username = '@' + input_value.split('/')[-1]
|
| 521 |
elif input_value.startswith('@'):
|
| 522 |
channel_username = input_value
|
| 523 |
else:
|
| 524 |
-
await message.
|
| 525 |
return
|
| 526 |
|
|
|
|
| 527 |
try:
|
| 528 |
-
progress_message = await message.reply_text("Fetching channel information...")
|
| 529 |
-
|
| 530 |
chat = await client.get_chat(channel_username)
|
| 531 |
response = f"*Username:* `{chat.username}`\n*Member count:* `{chat.members_count}`\n*Channel ID:* `{chat.id}`"
|
| 532 |
|
|
@@ -534,12 +505,15 @@ async def info_handler(client: Client, message: Message):
|
|
| 534 |
await progress_message.edit_text("Fetching profile photo...")
|
| 535 |
photo_file_id = chat.photo.big_file_id
|
| 536 |
photo_path = await client.download_media(photo_file_id, file_name=f"{chat.username}_profile_photo.jpg")
|
| 537 |
-
await
|
| 538 |
else:
|
| 539 |
await progress_message.edit_text(response)
|
| 540 |
except Exception as e:
|
| 541 |
-
|
| 542 |
-
await
|
|
|
|
|
|
|
|
|
|
| 543 |
|
| 544 |
|
| 545 |
def run_bot():
|
|
|
|
| 306 |
|
| 307 |
@bot.on_message(filters.command("time"))
|
| 308 |
async def time(client: Client, message: Message):
|
| 309 |
+
|
| 310 |
+
jakarta_tz = pytz.timezone('Asia/Jakarta')
|
| 311 |
+
jakarta_time = datetime.now(jakarta_tz)
|
| 312 |
+
time_str = jakarta_time.strftime('%Y-%m-%d %H:%M:%S')
|
| 313 |
+
await message.reply(f"The current date and time in Asia/Jakarta is: {time_str}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 314 |
|
| 315 |
@bot.on_message(filters.command("threads"))
|
| 316 |
async def threads(client: Client, message: Message):
|
|
|
|
| 483 |
|
| 484 |
@bot.on_message(filters.command("info"))
|
| 485 |
async def info_handler(client: Client, message: Message):
|
| 486 |
+
if len(message.text.split()) < 2:
|
| 487 |
+
await message.reply("Usage: /info <channel_username_or_link>")
|
|
|
|
|
|
|
| 488 |
return
|
| 489 |
|
| 490 |
+
input_value = message.text.split(maxsplit=1)[1]
|
| 491 |
if input_value.startswith('t.me/') or input_value.startswith('https://t.me/'):
|
| 492 |
channel_username = '@' + input_value.split('/')[-1]
|
| 493 |
elif input_value.startswith('@'):
|
| 494 |
channel_username = input_value
|
| 495 |
else:
|
| 496 |
+
await message.reply("Please provide a valid channel username starting with '@' or a valid channel link starting with 't.me/' or 'https://t.me/'.")
|
| 497 |
return
|
| 498 |
|
| 499 |
+
progress_message = await message.reply("Fetching channel information...")
|
| 500 |
try:
|
|
|
|
|
|
|
| 501 |
chat = await client.get_chat(channel_username)
|
| 502 |
response = f"*Username:* `{chat.username}`\n*Member count:* `{chat.members_count}`\n*Channel ID:* `{chat.id}`"
|
| 503 |
|
|
|
|
| 505 |
await progress_message.edit_text("Fetching profile photo...")
|
| 506 |
photo_file_id = chat.photo.big_file_id
|
| 507 |
photo_path = await client.download_media(photo_file_id, file_name=f"{chat.username}_profile_photo.jpg")
|
| 508 |
+
await client.send_photo(message.chat.id, photo_path, caption=response)
|
| 509 |
else:
|
| 510 |
await progress_message.edit_text(response)
|
| 511 |
except Exception as e:
|
| 512 |
+
logging.error(f"An error occurred: {e}")
|
| 513 |
+
await client.send_message(dev_id, f'[ ERROR MESSAGE ]\n\n• Username: @{message.from_user.username}\n• Channel: {channel_username}\n\n{str(e)}')
|
| 514 |
+
await message.reply('Failed to fetch information. Please try again later.')
|
| 515 |
+
finally:
|
| 516 |
+
await progress_message.delete()
|
| 517 |
|
| 518 |
|
| 519 |
def run_bot():
|