Team Ai
Apppublic

azils3/bash

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
variables.py95 linesDownload Raw Back to plugins
1# Ultroid - UserBot2# Copyright (C) 2021-2025 TeamUltroid3#4# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >5# PLease read the GNU Affero General Public License in6# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.7"""8✘ Commands Available -9 10• `{i}get var <variable name>`11   Get value of the given variable name.12 13• `{i}get type <variable name>`14   Get variable type.15 16• `{i}get db <key>`17   Get db value of the given key.18 19• `{i}get keys`20   Get all redis keys.21"""22 23import os24 25from . import eor, get_string, udB, ultroid_cmd, HNDLR26 27 28@ultroid_cmd(pattern="get($| (.*))", fullsudo=True)29async def get_var(event):30    try:31        opt = event.text.split(maxsplit=2)[1]32    except IndexError:33        return await event.eor(f"what to get?\nRead `{HNDLR}help variables`")34    x = await event.eor(get_string("com_1"))35    if opt != "keys":36        try:37            varname = event.text.split(maxsplit=2)[2]38        except IndexError:39            return await eor(x, "Such a var doesn't exist!", time=5)40    if opt == "var":41        c = 042        # try redis43        val = udB.get_key(varname)44        if val is not None:45            c += 146            await x.edit(47                f"**Variable** - `{varname}`\n**Value**: `{val}`\n**Type**: Redis Key."48            )49        # try env vars50        val = os.getenv(varname)51        if val is not None:52            c += 153            await x.edit(54                f"**Variable** - `{varname}`\n**Value**: `{val}`\n**Type**: Env Var."55            )56 57        if c == 0:58            await eor(x, "Such a var doesn't exist!", time=5)59 60    elif opt == "type":61        c = 062        # try redis63        val = udB.get_key(varname)64        if val is not None:65            c += 166            await x.edit(f"**Variable** - `{varname}`\n**Type**: Redis Key.")67        # try env vars68        val = os.getenv(varname)69        if val is not None:70            c += 171            await x.edit(f"**Variable** - `{varname}`\n**Type**: Env Var.")72 73        if c == 0:74            await eor(x, "Such a var doesn't exist!", time=5)75 76    elif opt == "db":77        val = udB.get(varname)78        if val is not None:79            await x.edit(f"**Key** - `{varname}`\n**Value**: `{val}`")80        else:81            await eor(x, "No such key!", time=5)82 83    elif opt == "keys":84        keys = sorted(udB.keys())85        msg = "".join(86            f"• `{i}`" + "\n"87            for i in keys88            if not i.isdigit()89            and not i.startswith("-")90            and not i.startswith("_")91            and not i.startswith("GBAN_REASON_")92        )93 94        await x.edit(f"**List of DB Keys :**\n{msg}")95