🗃️ UserID's instead of display names
This commit is contained in:
@@ -180,6 +180,17 @@ def makeFiles():
|
||||
json.dump(data,f,indent = 4)
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
# Creates users.json if it doesn't exist
|
||||
try:
|
||||
f = open("resources/users.json","r")
|
||||
except:
|
||||
logThis("users.json didn't exist. Making it now.")
|
||||
data = {}
|
||||
with open("resources/users.json","w") as f:
|
||||
json.dump(data,f,indent = 4)
|
||||
finally:
|
||||
f.close()
|
||||
|
||||
# Creates destinyPoints.txt if it doesn't exist
|
||||
try:
|
||||
@@ -291,11 +302,9 @@ def fiarReactionTest(channel,message,user):
|
||||
if message.id == oldImage:
|
||||
logThis("They reacted to the fourinarow game")
|
||||
turn = data["4 in a row games"][str(channel)]["turn"]
|
||||
if user.lower() == data["4 in a row games"][str(channel)]["players"][turn].lower():
|
||||
if user != data["4 in a row games"][str(channel)]["players"][turn]:
|
||||
data["4 in a row games"][str(channel)]["players"][turn] = user
|
||||
with open("resources/games/games.json","w") as f:
|
||||
json.dump(data,f,indent=4)
|
||||
print(user)
|
||||
print(data["4 in a row games"][str(channel)]["players"][turn])
|
||||
if user == data["4 in a row games"][str(channel)]["players"][turn]:
|
||||
return True, turn+1
|
||||
else:
|
||||
logThis("It wasn't their turn")
|
||||
@@ -321,3 +330,61 @@ def deleteGame(gameType,channel):
|
||||
del data[gameType][channel]
|
||||
with open("resources/games/games.json", "w") as f:
|
||||
json.dump(data,f,indent=4)
|
||||
|
||||
def addToDict(userID,userName):
|
||||
with open("resources/users.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
if userID in data:
|
||||
if data[userID]["user name"] != userName:
|
||||
logThis("changing name for "+userName)
|
||||
data[userID]["user name"] = userName
|
||||
with open("resources/users.json", "w") as f:
|
||||
json.dump(data,f,indent=4)
|
||||
else:
|
||||
logThis("creating "+userName+" in the system")
|
||||
|
||||
with open("resources/games/games.json","r") as f:
|
||||
games = json.load(f)
|
||||
|
||||
if userName.lower() in games["users"]:
|
||||
money = games["users"][userName.lower()]
|
||||
del games["users"][userName.lower()]
|
||||
with open("resources/games/games.json", "w") as f:
|
||||
json.dump(games,f,indent=4)
|
||||
else:
|
||||
money = 0
|
||||
|
||||
data[userID] = {"user name" : userName, "money" : money}
|
||||
with open("resources/users.json", "w") as f:
|
||||
json.dump(data,f,indent=4)
|
||||
|
||||
def getName(userID):
|
||||
try:
|
||||
with open("resources/users.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
if userID in data:
|
||||
logThis("yeet")
|
||||
return data[userID]["user name"]
|
||||
else:
|
||||
logThis("Couldn't find user")
|
||||
return userID
|
||||
except:
|
||||
logThis("Error getting name")
|
||||
|
||||
def getID(userName):
|
||||
try:
|
||||
with open("resources/users.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
userID = None
|
||||
|
||||
for key, value in data.items():
|
||||
if userName.lower() == value["user name"].lower():
|
||||
userID = key
|
||||
break
|
||||
|
||||
return userID
|
||||
except:
|
||||
logThis("Error getting ID")
|
||||
Reference in New Issue
Block a user