-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetupPlayer.py
More file actions
43 lines (40 loc) · 1.98 KB
/
setupPlayer.py
File metadata and controls
43 lines (40 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import discord
import json
from os.path import exists
from lcUtils import *
def setUpPlayer(ctx):
playerID = ctx.author.id
playerName = str(ctx.author.name)
playerDiscriminator = str(ctx.author.discriminator)
serverID = ctx.guild.id
serverName = ctx.guild.name
if not exists(f"./servers/{serverID}.json"): # if the server has never been initialized, make it
with open("./initFiles/server.json", "r") as readFile:
serverInfo = json.load(readFile)
serverInfo["NAME"] = serverName
else:
with open(f"./servers/{serverID}.json", "r") as readFile: # if server info exists, retrieve it
serverInfo = json.load(readFile)
if playerID not in serverInfo["PLAYERS"]: # if player is not registered as a member of the server
serverInfo["PLAYERS"].append(playerID)
with open(f"./servers/{serverID}.json", "w") as writeFile: # save server info (also works for initializing
json.dump(serverInfo, writeFile) # because player will always not be in the server if it didnt exist)
if not exists(f"./players/{playerID}.json"): # if player has never registered, set up profile
with open(f"initFiles/player.json", "r") as readFile:
playerInfo = json.load(readFile)
playerInfo["NAME"] = playerName
playerInfo["DISCRIMINATOR"] = playerDiscriminator
with open(f"./players/{playerID}.json", "w") as writeFile: # save player info
json.dump(playerInfo, writeFile)
else:
playerInfo = getPlayer(playerID)
changesMade = False
if playerName != playerInfo["NAME"]:
changesMade = True
playerInfo["NAME"] = playerName
if playerDiscriminator != playerInfo["DISCRIMINATOR"]:
changesMade = True
playerInfo["DISCRIMINATOR"] = playerDiscriminator
if changesMade:
setPlayer(playerID, playerInfo)