forked from TeamUltroid/Ultroid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsudo.py
132 lines (121 loc) · 4.14 KB
/
sudo.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
# 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}addsudo`
Add Sudo Users by replying to user or using <space> separated userid(s)
• `{i}delsudo`
Remove Sudo Users by replying to user or using <space> separated userid(s)
• `{i}listsudo`
List all sudo users.
"""
from pyUltroid.misc import sudoers
from . import *
@ultroid_cmd(
pattern="addsudo ?(.*)",
)
async def _(ult):
if not ult.out and not is_fullsudo(ult.sender_id):
return await eod(ult, "`This Command is Sudo Restricted!..`")
inputs = ult.pattern_match.group(1)
if str(ult.sender_id) in sudoers():
return await eod(ult, "`Sudo users can't add new sudos!`", time=10)
ok = await eor(ult, "`Updating SUDO Users List ...`")
mmm = ""
if ult.reply_to_msg_id:
replied_to = await ult.get_reply_message()
sender = replied_to.sender
id = sender.id
name = sender.first_name
elif inputs:
id = await get_user_id(inputs)
try:
name = (await ult.client.get_entity(int(id))).first_name
except BaseException:
name = ""
else:
return await eod(ult, "`Reply to a msg or add it's id/username.`")
if id == ultroid_bot.me.id:
mmm += "You cant add yourself as Sudo User..."
elif is_sudo(id):
if name != "":
mmm += f"[{name}](tg://user?id={id}) `is already a SUDO User ...`"
else:
mmm += f"`{id} is already a SUDO User...`"
elif add_sudo(id):
udB.set("SUDO", "True")
if name != "":
mmm += f"**Added [{name}](tg://user?id={id}) as SUDO User**"
else:
mmm += f"**Added **`{id}`** as SUDO User**"
else:
mmm += "`SEEMS LIKE THIS FUNCTION CHOOSE TO BREAK ITSELF`"
await eod(ok, mmm)
@ultroid_cmd(
pattern="delsudo ?(.*)",
)
async def _(ult):
if not ult.out and not is_fullsudo(ult.sender_id):
return await eod(ult, "`This Command is Sudo Restricted!..`")
inputs = ult.pattern_match.group(1)
if str(ult.sender_id) in sudoers():
return await eod(
ult,
"You are sudo user, You cant remove other sudo user.",
)
ok = await eor(ult, "`Updating SUDO Users List ...`")
mmm = ""
if ult.reply_to_msg_id:
replied_to = await ult.get_reply_message()
id = replied_to.sender_id
name = replied_to.sender.first_name
elif inputs:
id = await get_user_id(inputs)
try:
name = (await ult.client.get_entity(int(id))).first_name
except BaseException:
name = ""
else:
return await eod(ult, "`Reply to a msg or add it's id/username.`")
if not is_sudo(id):
if name != "":
mmm += f"[{name}](tg://user?id={id}) `wasn't a SUDO User ...`"
else:
mmm += f"`{id} wasn't a SUDO User...`"
elif del_sudo(id):
if name != "":
mmm += f"**Removed [{name}](tg://user?id={id}) from SUDO User(s)**"
else:
mmm += f"**Removed **`{id}`** from SUDO User(s)**"
else:
mmm += "`SEEMS LIKE THIS FUNCTION CHOOSE TO BREAK ITSELF`"
await eod(ok, mmm)
@ultroid_cmd(
pattern="listsudo$",
)
async def _(ult):
ok = await eor(ult, "`...`")
sudos = Redis("SUDOS")
if sudos == "" or sudos is None:
return await eod(ult, "`No SUDO User was assigned ...`", time=5)
sumos = sudos.split(" ")
msg = ""
for i in sumos:
try:
name = (await ult.client.get_entity(int(i))).first_name
except BaseException:
name = ""
if name != "":
msg += f"• [{name}](tg://user?id={i}) ( `{i}` )\n"
else:
msg += f"• `{i}` -> Invalid User\n"
m = udB.get("SUDO") if udB.get("SUDO") else "False"
if m == "False":
m = "[False](https://telegra.ph/Ultroid-04-06)"
return await ok.edit(
f"**SUDO MODE : {m}\n\nList of SUDO Users :**\n{msg}", link_preview=False
)