azils3/bash
0
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 9from . import get_help10 11__doc__ = get_help("help_database")12 13 14import re15 16from . import Redis, eor, get_string, udB, ultroid_cmd17 18 19@ultroid_cmd(pattern="setdb( (.*)|$)", fullsudo=True)20async def _(ult):21 match = ult.pattern_match.group(1).strip()22 if not match:23 return await ult.eor("Provide key and value to set!")24 try:25 delim = " " if re.search("[|]", match) is None else " | "26 data = match.split(delim, maxsplit=1)27 if data[0] in ["--extend", "-e"]:28 data = data[1].split(maxsplit=1)29 data[1] = f"{str(udB.get_key(data[0]))} {data[1]}"30 udB.set_key(data[0], data[1])31 await ult.eor(32 f"**DB Key Value Pair Updated\nKey :** `{data[0]}`\n**Value :** `{data[1]}`"33 )34 35 except BaseException:36 await ult.eor(get_string("com_7"))37 38 39@ultroid_cmd(pattern="deldb( (.*)|$)", fullsudo=True)40async def _(ult):41 key = ult.pattern_match.group(1).strip()42 if not key:43 return await ult.eor("Give me a key name to delete!", time=5)44 _ = key.split(maxsplit=1)45 try:46 if _[0] == "-m":47 for key in _[1].split():48 k = udB.del_key(key)49 key = _[1]50 else:51 k = udB.del_key(key)52 if k == 0:53 return await ult.eor("`No Such Key.`")54 await ult.eor(f"`Successfully deleted key {key}`")55 except BaseException:56 await ult.eor(get_string("com_7"))57 58 59@ultroid_cmd(pattern="rendb( (.*)|$)", fullsudo=True)60async def _(ult):61 match = ult.pattern_match.group(1).strip()62 if not match:63 return await ult.eor("`Provide Keys name to rename..`")64 delim = " " if re.search("[|]", match) is None else " | "65 data = match.split(delim)66 if Redis(data[0]):67 try:68 udB.rename(data[0], data[1])69 await eor(70 ult,71 f"**DB Key Rename Successful\nOld Key :** `{data[0]}`\n**New Key :** `{data[1]}`",72 )73 74 except BaseException:75 await ult.eor(get_string("com_7"))76 else:77 await ult.eor("Key not found")78 