Skip to content

Commit

Permalink
Added Global user variables
Browse files Browse the repository at this point in the history
  • Loading branch information
LilbabxJJ-1 committed Apr 9, 2024
1 parent 526bb20 commit e29d626
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
21 changes: 21 additions & 0 deletions CharmCord/functions/Variables/getGlobalUserVar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import json
from CharmCord.globeHandler import get_globals


async def getGlobalUserVar(args, context):
all_vars = get_globals()[2]

ag = args.split(";")
user = ag[0].replace("<@", "").replace(">", "")
var = ag[1]
try:
with open("variables.json", "r") as variables:
total = json.load(variables)
return total[f"{user}_{var}"]
except KeyError:
with open("variables.json", "r") as variables:
total = json.load(variables)
with open("variables.json", "w") as variables:
total.update({f"{user}_{var}": all_vars[var]})
json.dump(total, variables)
return all_vars[var]
17 changes: 17 additions & 0 deletions CharmCord/functions/Variables/setGlobalUserVar.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import json


async def setGlobalUserVar(args, context):
ag = args.split(";")
user = ag[0].replace("<@", "").replace(">", "")
var = ag[1]
value = ag[2]
with open("variables.json", "r") as variables:
total = json.load(variables)
with open("variables.json", "w") as variables:
try:
total.update({f"{user}_{var}": int(value)})
except:
total.update({f"{user}_{var}": value})
json.dump(total, variables)
return

0 comments on commit e29d626

Please sign in to comment.