File size: 2,804 Bytes
14d7d32
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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.")