forked from TeamUltroid/Ultroid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchats.py
394 lines (368 loc) · 12.6 KB
/
chats.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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
# Ultroid - UserBot
# Copyright (C) 2021-2022 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}delchat <optional- username/id>`
Delete the group this cmd is used in.
• `{i}getlink`
• `{i}getlink r` - `create link with admin approval`
• `{i}getlink r title_here` - `admin approval with link title`
• `{i}getlink 10` - `usage limit in new link`
Get link of group this cmd is used in.
• `{i}create (g|b|c) <group_name> ; <optional-username>`
Create group woth a specific name.
g - megagroup/supergroup
b - small group
c - channel
• `{i}setgpic <reply to Photo><chat username>`
Set Profile photo of Group.
• `{i}delgpic <chat username -optional>`
Delete Profile photo of Group.
• `{i}unbanall`
Unban all Members of a group.
• `{i}rmusers`
Remove users specifically.
"""
from telethon.errors import ChatAdminRequiredError as no_admin
from telethon.tl.functions.channels import (
CreateChannelRequest,
DeleteChannelRequest,
EditPhotoRequest,
GetFullChannelRequest,
UpdateUsernameRequest,
)
from telethon.tl.functions.messages import (
CreateChatRequest,
ExportChatInviteRequest,
GetFullChatRequest,
)
from telethon.tl.types import (
ChannelParticipantsKicked,
User,
UserStatusEmpty,
UserStatusLastMonth,
UserStatusLastWeek,
UserStatusOffline,
UserStatusOnline,
UserStatusRecently,
)
from . import HNDLR, LOGS, asst, con, get_string, mediainfo, os, types, udB, ultroid_cmd
@ultroid_cmd(
pattern="delchat",
groups_only=True,
)
async def _(e):
xx = await e.eor(get_string("com_1"))
try:
match = e.text.split(" ", maxsplit=1)[1]
chat = await e.client.parse_id(match)
except IndexError:
chat = e.chat_id
try:
await e.client(DeleteChannelRequest(chat))
except TypeError:
return await xx.eor(get_string("chats_1"), time=10)
except no_admin:
return await xx.eor(get_string("chats_2"), time=10)
await e.client.send_message(
int(udB.get_key("LOG_CHANNEL")), get_string("chats_6").format(e.chat_id)
)
@ultroid_cmd(
pattern="getlink( (.*)|$)",
groups_only=True,
manager=True,
)
async def _(e):
reply = await e.get_reply_message()
match = e.pattern_match.group(1).strip()
if reply and not isinstance(reply.sender, User):
chat = await reply.get_sender()
else:
chat = await e.get_chat()
if hasattr(chat, "username") and chat.username:
return await e.eor(f"Username: @{chat.username}")
request, usage, title = None, None, None
if match:
split = match.split(maxsplit=1)
request = bool(split[0] in ["r", "request"])
title = "Created by Ultroid"
if len(split) > 1:
match = split[1]
spli = match.split(maxsplit=1)
if spli[0].isdigit():
usage = int(spli[0])
if len(spli) > 1:
title = spli[1]
elif not request:
if match.isdigit():
usage = int(match)
else:
title = match
if request and usage:
usage = 0
if request or title:
try:
r = await e.client(
ExportChatInviteRequest(
e.chat_id,
request_needed=request,
usage_limit=usage,
title=title,
),
)
except no_admin:
return await e.eor(get_string("chats_2"), time=10)
link = r.link
else:
if isinstance(chat, types.Chat):
FC = await e.client(GetFullChatRequest(chat.id))
elif isinstance(chat, types.Channel):
FC = await e.client(GetFullChannelRequest(chat.id))
else:
return
Inv = FC.full_chat.exported_invite
if Inv and not Inv.revoked:
link = Inv.link
if link:
return await e.eor(f"Link:- {link}")
await e.eor("`Failed to getlink!\nSeems like link is inaccessible to you...`")
@ultroid_cmd(
pattern="create (b|g|c)(?: |$)(.*)",
)
async def _(e):
type_of_group = e.pattern_match.group(1).strip()
group_name = e.pattern_match.group(2)
username = None
if " ; " in group_name:
group_ = group_name.split(" ; ", maxsplit=1)
group_name = group_[0]
username = group_[1]
xx = await e.eor(get_string("com_1"))
if type_of_group == "b":
try:
r = await e.client(
CreateChatRequest(
users=[asst.me.username],
title=group_name,
),
)
created_chat_id = r.chats[0].id
result = await e.client(
ExportChatInviteRequest(
peer=created_chat_id,
),
)
await xx.edit(
get_string("chats_4").format(group_name, result.link),
link_preview=False,
)
except Exception as ex:
await xx.edit(str(ex))
elif type_of_group in ["g", "c"]:
try:
r = await e.client(
CreateChannelRequest(
title=group_name,
about=get_string("chats_5"),
megagroup=type_of_group != "c",
)
)
created_chat_id = r.chats[0].id
if username:
await e.client(UpdateUsernameRequest(created_chat_id, username))
result = "https://t.me/" + username
else:
result = (
await e.client(
ExportChatInviteRequest(
peer=created_chat_id,
),
)
).link
await xx.edit(
get_string("chats_6").format(f"[{group_name}]({result})"),
link_preview=False,
)
except Exception as ex:
await xx.edit(str(ex))
# ---------------------------------------------------------------- #
@ultroid_cmd(
pattern="setgpic( (.*)|$)", admins_only=True, manager=True, require="change_info"
)
async def _(ult):
if not ult.is_reply:
return await ult.eor("`Reply to a Media..`", time=5)
match = ult.pattern_match.group(1).strip()
if not ult.client._bot and match:
try:
chat = await ult.client.parse_id(match)
except Exception as ok:
return await ult.eor(str(ok))
else:
chat = ult.chat_id
reply = await ult.get_reply_message()
if reply.photo or reply.sticker or reply.video:
replfile = await reply.download_media()
elif reply.document and reply.document.thumbs:
replfile = await reply.download_media(thumb=-1)
else:
return await ult.eor("Reply to a Photo or Video..")
mediain = mediainfo(reply.media)
if "animated" in mediain:
replfile = await con.convert(replfile, convert_to="mp4")
else:
replfile = await con.convert(
replfile, outname="chatphoto", allowed_formats=["jpg", "png", "mp4"]
)
file = await ult.client.upload_file(replfile)
try:
if "pic" not in mediain:
file = types.InputChatUploadedPhoto(video=file)
await ult.client(EditPhotoRequest(chat, file))
await ult.eor("`Group Photo has Successfully Changed !`", time=5)
except Exception as ex:
await ult.eor("Error occured.\n`{}`".format(str(ex)), time=5)
os.remove(replfile)
@ultroid_cmd(
pattern="delgpic( (.*)|$)", admins_only=True, manager=True, require="change_info"
)
async def _(ult):
match = ult.pattern_match.group(1).strip()
chat = ult.chat_id
if not ult.client._bot and match:
chat = match
try:
await ult.client(EditPhotoRequest(chat, types.InputChatPhotoEmpty()))
text = "`Removed Chat Photo..`"
except Exception as E:
text = str(E)
return await ult.eor(text, time=5)
@ultroid_cmd(pattern="unbanall$", manager=True, admins_only=True, require="ban_users")
async def _(event):
xx = await event.eor("Searching Participant Lists.")
p = 0
title = (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 no_admin:
pass
except BaseException as er:
LOGS.exception(er)
await xx.eor(f"{title}: {p} unbanned", time=5)
@ultroid_cmd(
pattern="rmusers( (.*)|$)",
groups_only=True,
admins_only=True,
fullsudo=True,
)
async def _(event):
xx = await event.eor(get_string("com_1"))
input_str = event.pattern_match.group(1).strip()
p, a, b, c, d, m, n, y, w, o, q, r = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
async for i in event.client.iter_participants(event.chat_id):
p += 1 # Total Count
if isinstance(i.status, UserStatusEmpty):
if "empty" in input_str:
try:
await event.client.kick_participant(event.chat_id, i)
c += 1
except BaseException:
pass
else:
y += 1
if isinstance(i.status, UserStatusLastMonth):
if "month" in input_str:
try:
await event.client.kick_participant(event.chat_id, i)
c += 1
except BaseException:
pass
else:
m += 1
if isinstance(i.status, UserStatusLastWeek):
if "week" in input_str:
try:
await event.client.kick_participant(event.chat_id, i)
c += 1
except BaseException:
pass
else:
w += 1
if isinstance(i.status, UserStatusOffline):
if "offline" in input_str:
try:
await event.client.kick_participant(event.chat_id, i)
c += 1
except BaseException:
pass
else:
o += 1
if isinstance(i.status, UserStatusOnline):
if "online" in input_str:
try:
await event.client.kick_participant(event.chat_id, i)
c += 1
except BaseException:
pass
else:
q += 1
if isinstance(i.status, UserStatusRecently):
if "recently" in input_str:
try:
await event.client.kick_participant(event.chat_id, i)
c += 1
except BaseException:
pass
else:
r += 1
if i.bot:
if "bot" in input_str:
try:
await event.client.kick_participant(event.chat_id, i)
c += 1
except BaseException:
pass
else:
b += 1
elif i.deleted:
if "deleted" in input_str:
try:
await event.client.kick_participant(event.chat_id, i)
c += 1
except BaseException:
pass
else:
d += 1
elif i.status is None:
if "none" in input_str:
try:
await event.client.kick_participant(event.chat_id, i)
c += 1
except BaseException:
pass
else:
n += 1
if input_str:
required_string = f"**>> Kicked** `{c} / {p}` **users**\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}`"
await xx.eor(required_string)