Download plugins/pd.py from Vvbbnnn/Bsbsben: direct link, hf CLI and curl.
- Browser
- Download file 2.8 kB
-
https://huggingface.co/spaces/Vvbbnnn/Bsbsben/resolve/main/plugins/pd.py
- Command line
-
hf download hf://spaces/Vvbbnnn/Bsbsben/plugins/pd.py
-
curl -L -o pd.py https://huggingface.co/spaces/Vvbbnnn/Bsbsben/resolve/main/plugins/pd.py
2.8 kB
| from . import kanha_bot, kanha_cmd | |
| import asyncio | |
| import re | |
| from telethon import events | |
| from telethon.tl.functions.channels import GetFullChannelRequest | |
| async def pd(event): | |
| chat = -1001737654150 # Chat where /myinventory and /give happen | |
| pinchat = -1001737654150 # Chat where pinned message is fetched | |
| retries = 3 | |
| give_retries = 3 | |
| delay = 5 | |
| send_amount = 0 | |
| # Get pinned message ID | |
| 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 | |
| # Step 1: Try getting /myinventory result | |
| 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) | |
| # Ensure it's replying to /myinventory | |
| 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 | |
| # Step 2: Try sending with /give | |
| 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.") | |