-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
auth.py
160 lines (139 loc) · 5.27 KB
/
auth.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
# 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}addauth` `add Complete Chat for Voice chat. `
`{i}addauth admins` - `allow only Chat Admin to Use Vc`
• `{i}remauth`
Remove chat from Vc Auth.
• `{i}listauth`
Get All Vc Authorised Chat..
• `{i}vcaccess <id/username/reply to msg>`
Give access of Voice Chat Bot.
• `{i}rmvcaccess <id/username/reply to msg>`
Remove access of Voice Chat Bot.
• `{i}listvcaccess`
Get The List of People having vc access.
"""
from pyUltroid.dB.vc_sudos import add_vcsudo, del_vcsudo, get_vcsudos, is_vcsudo
from . import vc_asst, owner_and_sudos, get_string, udB
@vc_asst("addauth", from_users=owner_and_sudos(), vc_auth=False)
async def auth_group(event):
try:
key = event.text.split(" ", maxsplit=1)[1]
admins = "admins" in key
except IndexError:
admins = False
chat = event.chat_id
key = udB.get_key("VC_AUTH_GROUPS") or {}
cha, adm = (key[chat], key[chat]["admins"]) if key.get(chat) else (None, None)
if cha and adm == admins:
return await event.reply(get_string("vcbot_19"))
key.update({chat: {"admins": admins}})
udB.set_key("VC_AUTH_GROUPS", key)
kem = "Admins" if admins else "All"
await event.eor(
f"• Added to AUTH Groups Successfully For <code>{kem}</code>.",
parse_mode="html",
)
@vc_asst("remauth", from_users=owner_and_sudos(), vc_auth=False)
async def auth_group(event):
chat = event.chat_id
key = udB.get_key("VC_AUTH_GROUPS") or {}
gc = key.get(chat)
if not gc:
return await event.eor(get_string("vcbot_16"))
del key[chat]
if key:
udB.set_key("VC_AUTH_GROUPS", key)
else:
udB.del_key("VC_AUTH_GROUPS")
await event.eor(get_string("vcbot_10"))
@vc_asst("listauth", from_users=owner_and_sudos(), vc_auth=False)
async def listVc(e):
chats = udB.get_key("VC_AUTH_GROUPS")
if not chats:
return await e.eor(get_string("vcbot_18"))
text = "• <strong>Vc Auth Chats •</strong>\n\n"
for on in chats.keys():
st = "Admins" if chats[on]["admins"] else "All"
try:
title = (await e.client.get_entity(on)).title
except ValueError:
title = "No Info"
text += f"∆ <strong>{title}</strong> [ <code>{on}</code> ] : <code>{st}</code>"
await e.eor(text, parse_mode="html")
@vc_asst("listvcaccess$", from_users=owner_and_sudos(), vc_auth=False)
async def _(e):
xx = await e.eor(get_string("vcbot_11"))
mm = get_vcsudos()
pp = f"<strong>{len(mm)} Voice Chat Bot Approved Users</strong>\n"
if len(mm) > 0:
for m in mm:
try:
name = (await e.client.get_entity(int(m))).first_name
pp += f"• <a href=tg://user?id={int(m)}>{name}</a>\n"
except ValueError:
pp += f"• <code>{int(m)} » No Info</code>\n"
await xx.edit(pp, parse_mode="html")
@vc_asst("rmvcaccess( (.*)|$)", from_users=owner_and_sudos(), vc_auth=False)
async def _(e):
xx = await e.eor("`Disapproving to access Voice Chat features...`")
input = e.pattern_match.group(1).strip()
if e.reply_to_msg_id:
userid = (await e.get_reply_message()).sender_id
name = (await e.client.get_entity(userid)).first_name
elif input:
try:
userid = await e.client.parse_id(input)
name = (await e.client.get_entity(userid)).first_name
except ValueError as ex:
return await xx.edit(f"`{str(ex)}`", time=5)
else:
return await xx.edit(get_string("vcbot_17"), time=3)
if not is_vcsudo(userid):
return await xx.eor(
xx,
f"[{name}](tg://user?id={userid})` is not approved to use my Voice Chat Bot.`",
time=5,
)
try:
del_vcsudo(userid)
await xx.eor(
f"[{name}](tg://user?id={userid})` is removed from Voice Chat Bot Users.`",
time=5,
)
except Exception as ex:
return await xx.edit(f"`{ex}`", time=5)
@vc_asst("vcaccess( (.*)|$)", from_users=owner_and_sudos(), vc_auth=False)
async def _(e):
xx = await e.eor("`Approving to access Voice Chat features...`")
input = e.pattern_match.group(1).strip()
if e.reply_to_msg_id:
userid = (await e.get_reply_message()).sender_id
name = (await e.client.get_entity(userid)).first_name
elif input:
try:
userid = await e.client.parse_id(input)
name = (await e.client.get_entity(userid)).first_name
except ValueError as ex:
return await xx.eor(f"`{str(ex)}`", time=5)
else:
return await xx.eor(get_string("vcbot_17"), time=3)
if is_vcsudo(userid):
return await xx.eor(
f"[{name}](tg://user?id={userid})` is already approved to use my Voice Chat Bot.`",
time=5,
)
try:
add_vcsudo(userid)
await xx.eor(
f"[{name}](tg://user?id={userid})` is added to Voice Chat Bot Users.`",
time=5,
)
except Exception as ex:
return await xx.eor(f"`{ex}`", time=5)