File size: 4,330 Bytes
78b07ad
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import asyncio

from pyrogram import Client
from pyrogram.types import Message

from . import HelpMenu, hellbot, on_message


def _chunk(from_msg: int, to_msg: int):
    curr_msg = from_msg

    while curr_msg < to_msg:
        yield list(range(curr_msg, min(curr_msg + 100, to_msg)))
        curr_msg += 100


@on_message("purge", allow_stan=True)
async def purgeMsg(client: Client, message: Message):
    if not message.reply_to_message:
        return await hellbot.delete(
            message, "__Reply to a message to delete all messages after that.__"
        )

    deleted = 0
    from_msg = message.reply_to_message

    hell = await hellbot.edit(message, "__Purging...__")
    for msg_ids in _chunk(from_msg.id, message.id + 1):
        try:
            status = await client.delete_messages(message.chat.id, msg_ids)
            deleted += status
        except:
            pass

    await hellbot.delete(hell, f"__🧹 Purged {deleted} messages.__")


@on_message("purgeme", allow_stan=True)
async def purgeMe(client: Client, message: Message):
    if len(message.command) < 2:
        return await hellbot.delete(
            message, "__Give the number of messages you want to delete.__"
        )
    try:
        count = int(message.command[1])
    except:
        return await hellbot.delete(message, "Argument must be an integer.")

    hell = await hellbot.edit(message, "__Purging...__")
    async for msgs in client.search_messages(
        message.chat.id, limit=count, from_user="me"
    ):
        try:
            await msgs.delete()
        except:
            pass

    await hellbot.delete(hell, f"__🧹 Purged {count} messages.__")


@on_message("purgeuser", allow_stan=True)
async def purgeUser(client: Client, message: Message):
    if not message.reply_to_message or not message.reply_to_message.from_user:
        return await hellbot.delete(
            message, "__Reply to a user to delete their messages.__"
        )

    count = 0
    if len(message.command) > 1:
        try:
            count = int(message.command[1])
        except:
            return await hellbot.delete(message, "Argument must be an integer.")

    hell = await hellbot.edit(message, "__Purging...__")
    async for msgs in client.search_messages(
        message.chat.id, limit=count, from_user=message.reply_to_message.from_user.id
    ):
        try:
            await msgs.delete()
        except:
            pass

    await hellbot.delete(
        hell,
        f"__🧹 Purged {count} messages of {message.reply_to_message.from_user.mention}.__,,"
    )


@on_message("del", allow_stan=True)
async def delMsg(_, message: Message):
    if not message.reply_to_message:
        return await hellbot.delete(
            message, "__Reply to a message to delete that message.__"
        )

    await message.reply_to_message.delete()
    await message.delete()


@on_message(["selfdestruct", "sd"], allow_stan=True)
async def selfdestruct(client: Client, message: Message):
    if len(message.command) < 3:
        return await hellbot.delete(
            message, "__Give the number of seconds and the message to self-destruct.__"
        )

    try:
        seconds = int(message.command[1])
    except:
        return await hellbot.delete(message, "Argument must be an integer.")

    msg = " ".join(message.command[2:])
    await message.delete()
    x = await client.send_message(message.chat.id, msg)
    await asyncio.sleep(seconds)
    await x.delete()


HelpMenu("purge").add(
    "purge",
    "<reply to message>",
    "Deletes all messages after the replied message.",
    "purge",
).add(
    "purgeme",
    "<count>",
    "Deletes last x number of your messages.",
    "purgeme 69",
).add(
    "purgeuser",
    "<reply to user> <count>",
    "Deletes last x number of messages of replied user.",
    "purgeuser @ForGo10God 69",
).add(
    "del",
    "<reply to message>",
    "Deletes the replied message.",
    "del",
).add(
    "selfdestruct",
    "<seconds> <message>",
    "Sends a message and deletes it after x seconds.",
    "selfdestruct 10 Hello World!",
    "An alias of 'sd' is also available.",
).info(
    "Bulk delete messages."
).done()