-
Notifications
You must be signed in to change notification settings - Fork 1
/
invite.py
135 lines (124 loc) · 4.95 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
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
from telethon.errors import (
ChannelInvalidError,
ChannelPrivateError,
ChannelPublicGroupNaError,
)
from telethon.tl import functions
from telethon.tl.functions.channels import GetFullChannelRequest
from telethon.tl.functions.messages import GetFullChatRequest
from . import *
async def get_chatinfo(event):
chat = event.pattern_match.group(1)
chat_info = None
if chat:
try:
chat = int(chat)
except ValueError:
pass
if not chat:
if event.reply_to_msg_id:
replied_msg = await event.get_reply_message()
if replied_msg.fwd_from and replied_msg.fwd_from.channel_id is not None:
chat = replied_msg.fwd_from.channel_id
else:
chat = event.chat_id
try:
chat_info = await event.client(GetFullChatRequest(chat))
except:
try:
chat_info = await event.client(GetFullChannelRequest(chat))
except ChannelInvalidError:
await event.reply("`Invalid channel/group`")
return None
except ChannelPrivateError:
await event.reply(
"`This is a private channel/group or I am banned from there`"
)
return None
except ChannelPublicGroupNaError:
await event.reply("`Channel or supergroup doesn't exist`")
return None
except (TypeError, ValueError):
await event.reply("`Invalid channel/group`")
return None
return chat_info
def user_full_name(user):
names = [user.first_name, user.last_name]
names = [i for i in list(names) if i]
full_name = " ".join(names)
return full_name
@bot.on(admin_cmd(pattern="inviteall ?(.*)"))
@bot.on(sudo_cmd(pattern="inviteall ?(.*)", allow_sudo=True))
async def get_users(event):
sender = await event.get_sender()
me = await event.client.get_me()
if not sender.id == me.id:
d3vil = await edit_or_reply(event, "`processing...`")
else:
d3vil = await edit_or_reply(event, "`processing...`")
d3vilkrish = await get_chatinfo(event)
chat = await event.get_chat()
if event.is_private:
return await d3vil.edit("`Sorry, Cant add users here`")
s = 0
f = 0
error = "None"
await d3vil.edit("**TerminalStatus**\n\n`Collecting Users.......`")
async for user in event.client.iter_participants(d3vilkrish.full_chat.id):
try:
if error.startswith("Too"):
return await d3vil.edit(
f"**Terminal Finished With Error**\n(`May Got Limit Error from telethon Please try agin Later`)\n**Error** : \n`{error}`\n\n• Invited `{s}` people \n• Failed to Invite `{f}` people"
)
await event.client(
functions.channels.InviteToChannelRequest(channel=chat, users=[user.id])
)
s = s + 1
await d3vil.edit(
f"**Terminal Running...**\n\n• Invited `{s}` people \n• Failed to Invite `{f}` people\n\n**× LastError:** `{error}`"
)
except Exception as e:
error = str(e)
f = f + 1
return await d3vil.edit(
f"**Terminal Finished** \n\n• Successfully Invited `{s}` people \n• failed to invite `{f}` people"
)
@bot.on(admin_cmd(pattern="add ?(.*)"))
@bot.on(sudo_cmd(pattern="add ?(.*)", allow_sudo=True))
async def _(event):
if event.fwd_from:
return
to_add_users = event.pattern_match.group(1)
if event.is_private:
await edit_or_reply(event, "`.add` 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 edit_or_reply(event, "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 edit_or_reply(event, "Added user to the chat....")
CmdHelp("invite").add_command(
"add", "<username/id>", "Adds the given user to the group"
).add_command(
"inviteall", "<group username>", "Scraps user from the targeted group to your group. Basically Kidnapps user from one chat to another"
).add()