| from . import kanha_bot, kanha_cmd |
| import asyncio |
| import re |
| from telethon import events |
| from telethon.tl.functions.channels import GetFullChannelRequest |
|
|
| @kanha_bot.on(events.NewMessage(outgoing=True, pattern=r"[.!]pd")) |
| async def pd(event): |
| chat = -1001737654150 |
| pinchat = -1001737654150 |
| retries = 3 |
| give_retries = 3 |
| delay = 5 |
| send_amount = 0 |
|
|
| |
| try: |
| full_chat = await event.client(GetFullChannelRequest(pinchat)) |
| pinmsg_id = full_chat.full_chat.pinned_msg_id |
| if not pinmsg_id: |
| await event.edit("β No pinned message found.") |
| return |
| except Exception as e: |
| await event.edit("β Failed to fetch pinned message.") |
| return |
|
|
| |
| for attempt in range(retries): |
| try: |
| async with event.client.conversation(chat, timeout=20) as conv: |
| await conv.send_message("/myinventory@HeXamonbot") |
| response = await conv.get_response(timeout=15) |
|
|
| |
| if "Poke Dollars π΅" in response.text: |
| match = re.search(r"Poke Dollars π΅: (\d+)", response.text) |
| if match: |
| amount = int(match.group(1)) |
| send_amount = max(0, amount - 300) |
| if send_amount > 0: |
| break |
| else: |
| await event.edit("Not enough Poke Dollars. Keeping minimum 300.") |
| return |
| except asyncio.TimeoutError: |
| if attempt < retries - 1: |
| await asyncio.sleep(delay) |
| else: |
| await event.edit("β Inventory fetch failed after retries.") |
| return |
|
|
| if send_amount == 0: |
| await event.edit("β No Poke Dollars to send.") |
| return |
|
|
| |
| for attempt in range(give_retries): |
| try: |
| async with event.client.conversation(chat, timeout=20) as conv: |
| await conv.send_message(f"/give {send_amount}", reply_to=pinmsg_id) |
| response = await conv.get_response(timeout=10) |
|
|
| if "Poke Dollars sent" in response.text: |
| await event.edit(f"β
Sent {send_amount} Poke Dollars!") |
| return |
| except asyncio.TimeoutError: |
| if attempt < give_retries - 1: |
| await asyncio.sleep(delay) |
| else: |
| await event.edit("β /give failed after retries.") |
| return |
|
|
| await event.edit("β Failed to send Poke Dollars.") |
|
|