Bsbsben / plugins /pd.py
soxogvv's picture
Upload 8 files
14d7d32 verified
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 # 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.")