forked from SpEcHiDe/UniBorg
-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathinvite.py
39 lines (36 loc) · 1.47 KB
/
invite.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
"""Invite the user(s) to the current chat
Syntax: .invite <User(s)>"""
from telethon import functions
from uniborg.util import admin_cmd
@borg.on(admin_cmd("invite ?(.*)"))
async def _(event):
if event.fwd_from:
return
to_add_users = event.pattern_match.group(1)
if event.is_private:
await event.edit("`.invite` users to a chat, not to a Private Message")
else:
logger.info(to_add_users)
if not event.is_channel and event.is_group:
# https://lonamiwebs.github.io/Telethon/methods/messages/add_chat_user.html
for user_id in to_add_users.split(" "):
try:
await borg(functions.messages.AddChatUserRequest(
chat_id=event.chat_id,
user_id=user_id,
fwd_limit=1000000
))
except Exception as e:
await event.reply(str(e))
await event.edit("Invited Successfully")
else:
# https://lonamiwebs.github.io/Telethon/methods/channels/invite_to_channel.html
for user_id in to_add_users.split(" "):
try:
await borg(functions.channels.InviteToChannelRequest(
channel=event.chat_id,
users=[user_id]
))
except Exception as e:
await event.reply(str(e))
await event.edit("Invited Successfully")