|
|
|
|
|
|
|
|
|
|
|
|
|
""" |
|
β Commands Available - |
|
|
|
β’ `{i}get var <variable name>` |
|
Get value of the given variable name. |
|
|
|
β’ `{i}get type <variable name>` |
|
Get variable type. |
|
|
|
β’ `{i}get db <key>` |
|
Get db value of the given key. |
|
|
|
β’ `{i}get keys` |
|
Get all redis keys. |
|
""" |
|
|
|
import os |
|
|
|
from . import eor, get_string, udB, ultroid_cmd, HNDLR |
|
|
|
|
|
@ultroid_cmd(pattern="get($| (.*))", fullsudo=True) |
|
async def get_var(event): |
|
try: |
|
opt = event.text.split(maxsplit=2)[1] |
|
except IndexError: |
|
return await event.eor(f"what to get?\nRead `{HNDLR}help variables`") |
|
x = await event.eor(get_string("com_1")) |
|
if opt != "keys": |
|
try: |
|
varname = event.text.split(maxsplit=2)[2] |
|
except IndexError: |
|
return await eor(x, "Such a var doesn't exist!", time=5) |
|
if opt == "var": |
|
c = 0 |
|
|
|
val = udB.get_key(varname) |
|
if val is not None: |
|
c += 1 |
|
await x.edit( |
|
f"**Variable** - `{varname}`\n**Value**: `{val}`\n**Type**: Redis Key." |
|
) |
|
|
|
val = os.getenv(varname) |
|
if val is not None: |
|
c += 1 |
|
await x.edit( |
|
f"**Variable** - `{varname}`\n**Value**: `{val}`\n**Type**: Env Var." |
|
) |
|
|
|
if c == 0: |
|
await eor(x, "Such a var doesn't exist!", time=5) |
|
|
|
elif opt == "type": |
|
c = 0 |
|
|
|
val = udB.get_key(varname) |
|
if val is not None: |
|
c += 1 |
|
await x.edit(f"**Variable** - `{varname}`\n**Type**: Redis Key.") |
|
|
|
val = os.getenv(varname) |
|
if val is not None: |
|
c += 1 |
|
await x.edit(f"**Variable** - `{varname}`\n**Type**: Env Var.") |
|
|
|
if c == 0: |
|
await eor(x, "Such a var doesn't exist!", time=5) |
|
|
|
elif opt == "db": |
|
val = udB.get(varname) |
|
if val is not None: |
|
await x.edit(f"**Key** - `{varname}`\n**Value**: `{val}`") |
|
else: |
|
await eor(x, "No such key!", time=5) |
|
|
|
elif opt == "keys": |
|
keys = sorted(udB.keys()) |
|
msg = "".join( |
|
f"β’ `{i}`" + "\n" |
|
for i in keys |
|
if not i.isdigit() |
|
and not i.startswith("-") |
|
and not i.startswith("_") |
|
and not i.startswith("GBAN_REASON_") |
|
) |
|
|
|
await x.edit(f"**List of DB Keys :**\n{msg}") |
|
|