💰 Added money-based commands
This commit is contained in:
40
funcs/games/money.py
Normal file
40
funcs/games/money.py
Normal file
@ -0,0 +1,40 @@
|
||||
import json
|
||||
|
||||
from funcs import logThis
|
||||
|
||||
def checkBalance(user):
|
||||
with open("resources/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
if user in data["users"]:
|
||||
return data["users"][user]
|
||||
else: return 0
|
||||
|
||||
def addMoney(user,amount):
|
||||
with open("resources/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
if user in data["users"]:
|
||||
points = data["users"][user]
|
||||
data["users"][user] = points + amount
|
||||
else:
|
||||
data["users"][user] = amount
|
||||
|
||||
with open("resources/games.json", "w") as f:
|
||||
json.dump(data,f,indent=4)
|
||||
|
||||
def giveMoney(user,targetUser,amount):
|
||||
with open("resources/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
if user in data["users"]:
|
||||
if data["users"][user] >= amount:
|
||||
addMoney(user,-1 * amount)
|
||||
addMoney(targetUser,amount)
|
||||
return "Transferred the points"
|
||||
else:
|
||||
logThis("They didn't have enough points")
|
||||
return "You don't have that many points"
|
||||
else:
|
||||
logThis("They didn't have enough points")
|
||||
return "You don't have that many points"
|
Reference in New Issue
Block a user