forked from TeamUltroid/Ultroid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroups.py
229 lines (219 loc) · 7.64 KB
/
groups.py
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# Ultroid - UserBot
# Copyright (C) 2021 TeamUltroid
#
# 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}setgpic <reply to Photo>`
Set Profile photo of Group.
• `{i}unbanall`
Unban all Members of a group.
• `{i}rmusers`
Remove users specifically.
"""
from telethon.tl.functions.channels import EditBannedRequest, EditPhotoRequest
from telethon.tl.types import (
ChannelParticipantsKicked,
ChatBannedRights,
UserStatusEmpty,
UserStatusLastMonth,
UserStatusLastWeek,
UserStatusOffline,
UserStatusOnline,
UserStatusRecently,
)
from . import *
@ultroid_cmd(pattern="setgpic$", groups_only=True, admins_only=True)
async def _(ult):
if not ult.is_reply:
return await eod(ult, "`Reply to a Media..`")
reply_message = await ult.get_reply_message()
try:
replfile = await reply_message.download_media()
except AttributeError:
return await eor(ult, "Reply to a Photo..")
file = await ult.client.upload_file(replfile)
mediain = mediainfo(reply_message.media)
try:
if "pic" in mediain:
await ult.client(EditPhotoRequest(ult.chat_id, file))
else:
return await eod(ult, "`Invalid MEDIA Type !`")
await eod(ult, "`Group Photo has Successfully Changed !`")
except Exception as ex:
await eod(ult, "Error occured.\n`{}`".format(str(ex)))
os.remove(replfile)
@ultroid_cmd(
pattern="unbanall$",
groups_only=True,
)
async def _(event):
xx = await eor(event, "Searching Participant Lists.")
p = 0
(await event.get_chat()).title
async for i in event.client.iter_participants(
event.chat_id,
filter=ChannelParticipantsKicked,
aggressive=True,
):
try:
await event.client.edit_permissions(event.chat_id, i, view_messages=True)
p += 1
except BaseException:
pass
await eod(xx, "{title}: {p} unbanned")
@ultroid_cmd(
pattern="rmusers ?(.*)",
groups_only=True,
)
async def _(event):
xx = await eor(event, "Searching Participant Lists.")
input_str = event.pattern_match.group(1)
if input_str:
chat = await event.get_chat()
if not (chat.admin_rights or chat.creator):
return await eod(xx, "`You aren't an admin here!`", time=5)
p = 0
b = 0
c = 0
d = 0
m = 0
n = 0
y = 0
w = 0
o = 0
q = 0
r = 0
async for i in event.client.iter_participants(event.chat_id):
p += 1
rights = ChatBannedRights(
until_date=None,
view_messages=True,
)
if isinstance(i.status, UserStatusEmpty):
y += 1
if "empty" in input_str:
try:
await event.client(
EditBannedRequest(event.chat_id, i, rights),
)
c += 1
y -= 1
except BaseException:
pass
if isinstance(i.status, UserStatusLastMonth):
m += 1
if "month" in input_str:
try:
await event.client(
EditBannedRequest(event.chat_id, i, rights),
)
c += 1
m -= 1
except BaseException:
pass
if isinstance(i.status, UserStatusLastWeek):
w += 1
if "week" in input_str:
try:
await event.client(
EditBannedRequest(event.chat_id, i, rights),
)
c += 1
w -= 1
except BaseException:
pass
if isinstance(i.status, UserStatusOffline):
o += 1
if "offline" in input_str:
try:
await event.client(
EditBannedRequest(event.chat_id, i, rights),
)
c += 1
o -= 1
except BaseException:
pass
if isinstance(i.status, UserStatusOnline):
q += 1
if "online" in input_str:
try:
await event.client(
EditBannedRequest(event.chat_id, i, rights),
)
c += 1
q -= 1
except BaseException:
pass
if isinstance(i.status, UserStatusRecently):
r += 1
if "recently" in input_str:
try:
await event.client(
EditBannedRequest(event.chat_id, i, rights),
)
c += 1
r -= 1
except BaseException:
pass
if i.bot:
b += 1
if "bot" in input_str:
try:
await event.client(
EditBannedRequest(event.chat_id, i, rights),
)
c += 1
b -= 1
except BaseException:
pass
elif i.deleted:
d += 1
if "deleted" in input_str:
try:
await event.client(
EditBannedRequest(event.chat_id, i, rights),
)
c += 1
d -= 1
except BaseException:
pass
elif i.status is None:
n += 1
if "none" in input_str:
try:
await event.client(
EditBannedRequest(event.chat_id, i, rights),
)
c += 1
n -= 1
except BaseException:
pass
required_string = ""
if input_str:
required_string += f"**>> Kicked** `{c} / {p}` **users**\n\n"
required_string += f" **••Deleted Accounts••** `{d}`\n"
required_string += f" **••UserStatusEmpty••** `{y}`\n"
required_string += f" **••UserStatusLastMonth••** `{m}`\n"
required_string += f" **••UserStatusLastWeek••** `{w}`\n"
required_string += f" **••UserStatusOffline••** `{o}`\n"
required_string += f" **••UserStatusOnline••** `{q}`\n"
required_string += f" **••UserStatusRecently••** `{r}`\n"
required_string += f" **••Bots••** `{b}`\n"
required_string += f" **••None••** `{n}`\n"
else:
required_string += f"**>> Total** `{p}` **users**\n\n"
required_string += f" `{HNDLR}rmusers deleted` **••** `{d}`\n"
required_string += f" `{HNDLR}rmusers empty` **••** `{y}`\n"
required_string += f" `{HNDLR}rmusers month` **••** `{m}`\n"
required_string += f" `{HNDLR}rmusers week` **••** `{w}`\n"
required_string += f" `{HNDLR}rmusers offline` **••** `{o}`\n"
required_string += f" `{HNDLR}rmusers online` **••** `{q}`\n"
required_string += f" `{HNDLR}rmusers recently` **••** `{r}`\n"
required_string += f" `{HNDLR}rmusers bot` **••** `{b}`\n"
required_string += f" `{HNDLR}rmusers none` **••** `{n}`\n\n"
required_string += f"**••Empty** `Name with deleted Account`\n"
required_string += f"**••None** `Last Seen A Long Time Ago`\n"
await eod(xx, required_string)