forked from TeamUltroid/Ultroid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvariables.py
97 lines (83 loc) · 2.71 KB
/
variables.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
# 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}get var <variable name>`
Get value of the given variable name.
• `{i}get type <variable name>`
Get variable type.
• `{i}get redis <key>`
Get redis value of the given key.
• `{i}get keys`
Get all redis keys.
"""
import os
from . import *
@ultroid_cmd(pattern="get")
async def get_var(event):
if not event.out and not is_fullsudo(event.sender_id):
return await eod(event, "`This Command Is Sudo Restricted.`")
if len(event.text) > 4:
if " " in event.text[4]:
opt = event.text.split(" ", maxsplit=2)[1]
else:
return
else:
return
x = await eor(event, get_string("com_1"))
if not opt == "keys":
try:
varname = event.text.split(" ", maxsplit=2)[2]
except IndexError:
return await eod(x, "Such a var doesn't exist!", time=5)
if opt == "var":
c = 0
# try redis
val = udB.get(varname)
if val is not None:
c += 1
return await x.edit(
f"**Variable** - `{varname}`\n**Value**: `{val}`\n**Type**: Redis Key."
)
# try env vars
val = os.getenv(varname)
if val is not None:
c += 1
return await x.edit(
f"**Variable** - `{varname}`\n**Value**: `{val}`\n**Type**: Env Var."
)
if c == 0:
return await eod(x, "Such a var doesn't exist!", time=5)
elif opt == "type":
c = 0
# try redis
val = udB.get(varname)
if val is not None:
c += 1
return await x.edit(f"**Variable** - `{varname}`\n**Type**: Redis Key.")
# try env vars
val = os.getenv(varname)
if val is not None:
c += 1
return await x.edit(f"**Variable** - `{varname}`\n**Type**: Env Var.")
if c == 0:
return await eod(x, "Such a var doesn't exist!", time=5)
elif opt == "redis":
val = udB.get(varname)
if val is not None:
return await x.edit(f"**Key** - `{varname}`\n**Value**: `{val}`")
else:
return await eod(x, "No such key!")
elif opt == "keys":
keys = sorted(udB.keys())
msg = ""
for i in keys:
if i.isdigit() or i.startswith("-") or i.startswith("GBAN_REASON_"):
pass
else:
msg += f"• `{i}`" + "\n"
await x.edit(f"**List of Redis Keys :**\n{msg}")