File size: 3,936 Bytes
ca4eb6d
 
 
007891e
1e7cb23
007891e
af1662b
ca4eb6d
 
 
 
934545e
8f3b78a
11170eb
ca4eb6d
 
 
 
 
 
 
5ed2636
ca4eb6d
 
 
 
 
 
 
 
 
 
 
 
 
af1662b
 
 
ca4eb6d
 
 
11170eb
 
 
ca4eb6d
 
 
 
af1662b
ca4eb6d
 
 
 
 
 
 
 
 
934545e
8f3b78a
11170eb
ca4eb6d
 
 
 
 
 
 
5ed2636
ca4eb6d
 
 
 
 
 
 
 
 
 
 
 
 
af1662b
 
 
ca4eb6d
 
 
11170eb
 
 
ca4eb6d
 
 
 
 
 
 
 
 
 
 
934545e
8f3b78a
ca4eb6d
 
 
 
 
 
 
 
 
11170eb
ca4eb6d
 
 
 
 
 
9da6fea
709df35
8e6421c
709df35
c664d1d
 
af1662b
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
from asyncio import sleep
from Powers import SUPPORT_GROUP
from Powers.bot_class import Gojo
from pyrogram.types import Message
from Powers.utils.chat_type import chattype
from pyrogram.errors import RPCError, MessageDeleteForbidden
from Powers.utils.custom_filters import command, admin_filter


@Gojo.on_message(command("purge") & admin_filter)
async def purge(c: Gojo, m: Message):
    chat_type = await chattype(m)
    if chat_type != "supergroup":
        await m.reply_text(text="Cannot purge messages in a basic group")
        return

    if m.reply_to_message:
        message_ids = list(range(m.reply_to_message.message_id, m.message_id))

        def divide_chunks(l: list, n: int = 100):
            for i in range(0, len(l), n):
                yield l[i : i + n]

        # Dielete messages in chunks of 100 messages
        m_list = list(divide_chunks(message_ids))

        try:
            for plist in m_list:
                await c.delete_messages(
                    chat_id=m.chat.id,
                    message_ids=plist,
                    revoke=True,
                )
            await m.delete()
        except MessageDeleteForbidden:
            await m.reply_text(
                text="Cannot delete all messages. The messages may be too old, I might not have delete rights, or this might not be a supergroup."
            )
            return
        except RPCError as ef:
            await m.reply_text(
                text=f"""Some error occured, report to @{SUPPORT_GROUP}

      <b>Error:</b> <code>{ef}</code>"""
            )

        count_del_msg = len(message_ids)

        z = await m.reply_text(text=f"Deleted <i>{count_del_msg}</i> messages")
        await sleep(3)
        await z.delete()
        return
    await m.reply_text("Reply to a message to start purge !")
    return


@Gojo.on_message(command("spurge") & admin_filter)
async def spurge(c: Gojo, m: Message):
    chat_type = await chattype(m)
    if chat_type != "supergroup":
        await m.reply_text(text="Cannot purge messages in a basic group")
        return

    if m.reply_to_message:
        message_ids = list(range(m.reply_to_message.message_id, m.message_id))

        def divide_chunks(l: list, n: int = 100):
            for i in range(0, len(l), n):
                yield l[i : i + n]

        # Dielete messages in chunks of 100 messages
        m_list = list(divide_chunks(message_ids))

        try:
            for plist in m_list:
                await c.delete_messages(
                    chat_id=m.chat.id,
                    message_ids=plist,
                    revoke=True,
                )
            await m.delete()
        except MessageDeleteForbidden:
            await m.reply_text(
                text="Cannot delete all messages. The messages may be too old, I might not have delete rights, or this might not be a supergroup."
            )
            return
        except RPCError as ef:
            await m.reply_text(
                text=f"""Some error occured, report to @{SUPPORT_GROUP}

      <b>Error:</b> <code>{ef}</code>"""
            )
        return
    await m.reply_text("Reply to a message to start spurge !")
    return


@Gojo.on_message(
    command("del") & admin_filter,
    group=9,
)
async def del_msg(c: Gojo, m: Message):
    chat_type = await chattype(m)
    if chat_type != "supergroup":
        return

    if m.reply_to_message:
        await m.delete()
        await c.delete_messages(
            chat_id=m.chat.id,
            message_ids=m.reply_to_message.message_id,
        )
    else:
        await m.reply_text(text="What do you wanna delete?")
    return


__PLUGIN__ = "purges"

__alt_name__ = ["purge", "del", "spurge"]

__HELP__ = """
***Purge***

* /purge: Deletes messages upto replied message.
* /spurge: Deletes messages upto replied message without a success message.
* /del: Deletes a single message, used as a reply to message."""