forked from TeamUltroid/UltroidAddons
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzombies.py
More file actions
111 lines (99 loc) · 3.46 KB
/
zombies.py
File metadata and controls
111 lines (99 loc) · 3.46 KB
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
# Ultroid Userbot
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
"""✘ Commands Available
• `{i}zombies`
Gives the Number of Deleted Accounts.
• `{i}zombies clean`
Remove the deleted accounts if the user is admin.
"""
import asyncio
from telethon.errors import ChatAdminRequiredError, UserAdminInvalidError
from telethon.tl.functions.channels import EditBannedRequest
from telethon.tl.types import ChatBannedRights
from . import *
BANNED_RIGHTS = ChatBannedRights(
until_date=None,
view_messages=True,
send_messages=True,
send_media=True,
send_stickers=True,
send_gifs=True,
send_games=True,
send_inline=True,
embed_links=True,
)
UNBAN_RIGHTS = ChatBannedRights(
until_date=None,
send_messages=None,
send_media=None,
send_stickers=None,
send_gifs=None,
send_games=None,
send_inline=None,
embed_links=None,
)
MUTE_RIGHTS = ChatBannedRights(until_date=None, send_messages=True)
UNMUTE_RIGHTS = ChatBannedRights(until_date=None, send_messages=False)
# ================================================
@ultroid_cmd(pattern="zombies ?(.*)")
async def rm_deletedacc(show):
ultroid_bot = show.client
con = show.pattern_match.group(1).lower()
del_u = 0
del_status = "`No deleted accounts found, Group is clean`"
if con != "clean":
eh = await eor(show, "`Searching for ghost/deleted/zombie accounts...`")
async for user in ultroid_bot.iter_participants(show.chat_id):
if user.deleted:
del_u += 1
if del_u > 0:
del_status = f"`Found` {del_u} `ghost/deleted/zombie account(s) in this group,\
\nClean them by using` `{HNDLR}zombies clean`"
await eh.edit(del_status)
return
chat = await show.get_chat()
admin = chat.admin_rights
creator = chat.creator
if not admin and not creator:
await eor(show, "`I am not an admin here!`")
return
ehh = await eor(show, "`Deleting deleted accounts...`")
del_u = 0
del_a = 0
async for user in ultroid_bot.iter_participants(show.chat_id):
if user.deleted:
try:
await ultroid_bot(
EditBannedRequest(show.chat_id, user.id, BANNED_RIGHTS)
)
except ChatAdminRequiredError:
await eh.edit("`I don't have ban rights in this group`")
return
except UserAdminInvalidError:
del_u -= 1
del_a = 0
async for user in ultroid_bot.iter_participants(show.chat_id):
if user.deleted:
try:
await ultroid_bot(
EditBannedRequest(show.chat_id, user.id, BANNED_RIGHTS)
)
except ChatAdminRequiredError:
await eh.edit("`I don't have ban rights in this group`")
return
except UserAdminInvalidError:
del_u -= 1
del_a += 1
await ultroid_bot(EditBannedRequest(show.chat_id, user.id, UNBAN_RIGHTS))
del_u += 1
if del_u > 0:
del_status = f"Cleaned **{del_u}** deleted account(s)"
if del_a > 0:
del_status = f"Cleaned **{del_u}** deleted account(s) \
\n**{del_a}** deleted admin accounts are not removed"
await ehh.edit(del_status)
await asyncio.sleep(2)
await show.delete()