AutoZoomDiscord/modules/functions_bot.py

44 lines
1.1 KiB
Python

from modules.functions import jsonLoad, jsonSave
def locale(key, *args):
strings = jsonLoad("strings.json")
string = strings
for dict_key in args:
string = string[dict_key]
return string[key]
def configGet(key):
return jsonLoad("config.json")[key]
def configAppend(key, value):
config = jsonLoad("config.json")
config[key].append(value)
jsonSave("config.json", config)
def configRemove(key, value):
config = jsonLoad("config.json")
config[key].remove(value)
jsonSave("config.json", config)
def userSet(userid, key, value):
user = jsonLoad(f"data/users/{userid}.json")
user[key] = value
jsonSave(f"data/users/{userid}.json", user)
def userGet(userid, key):
try:
return jsonLoad(f"data/users/{userid}.json")[key]
except KeyError:
return None
except FileNotFoundError:
return None
def userClear(userid, key):
try:
user = jsonLoad(f"data/users/{userid}.json")
del user[key]
jsonSave(f"data/users/{userid}.json", user)
except KeyError:
pass