2023-03-04 18:32:59 -06:00
|
|
|
import os
|
|
|
|
|
|
|
|
import jsonpickle
|
2023-02-05 04:32:26 -06:00
|
|
|
from dataclasses import dataclass
|
|
|
|
|
2023-03-04 18:32:59 -06:00
|
|
|
|
2023-02-05 04:32:26 -06:00
|
|
|
@dataclass
|
|
|
|
class DiscordClientConfig:
|
|
|
|
login_token: str
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class WhitelistMember:
|
2023-03-04 18:32:59 -06:00
|
|
|
discord_id: int
|
2023-02-05 04:32:26 -06:00
|
|
|
discord_username: str
|
|
|
|
steam64: int
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class WhitelistGroup:
|
2023-03-04 18:32:59 -06:00
|
|
|
name: str
|
2023-02-05 04:32:26 -06:00
|
|
|
discord_role_id: int
|
2023-03-04 18:32:59 -06:00
|
|
|
squadPerms: str
|
|
|
|
members: dict[str, WhitelistMember]
|
|
|
|
|
2024-10-01 18:27:04 -05:00
|
|
|
def __init__(self, name, roleID, permissions="reserve"):
|
2023-03-04 18:32:59 -06:00
|
|
|
self.name = name
|
|
|
|
self.discord_role_id = roleID
|
|
|
|
self.squadPerms = permissions
|
|
|
|
self.members = {}
|
|
|
|
|
|
|
|
def delGroup(self):
|
2023-03-04 22:32:26 -06:00
|
|
|
os.remove(f"./wlgrps/{self.name}.cfg")
|
2023-03-04 18:32:59 -06:00
|
|
|
os.remove(f"./wlgrps/{self.name}.json")
|
|
|
|
|
2023-04-17 21:13:00 -05:00
|
|
|
def updateGroup(self):
|
|
|
|
self.updateFile()
|
|
|
|
self.updateWL()
|
|
|
|
|
2023-03-04 18:32:59 -06:00
|
|
|
def updateFile(self):
|
|
|
|
outFile = open(f"./wlgrps/{self.name}.json", "w")
|
|
|
|
outFile.write(jsonpickle.encode(self))
|
|
|
|
outFile.close()
|
|
|
|
|
|
|
|
def updateWL(self):
|
2023-03-04 22:32:26 -06:00
|
|
|
wlFile = open(f"./wlgrps/{self.name}.cfg", "w")
|
2023-03-04 18:32:59 -06:00
|
|
|
wlFile.write(f"Group={self.name}:{self.squadPerms}\n")
|
|
|
|
wlFile.write("\n")
|
|
|
|
wlFile.write(f"//{self.name}\n")
|
|
|
|
for wlmem in self.members:
|
|
|
|
memb = self.members[wlmem]
|
2024-10-01 18:27:04 -05:00
|
|
|
wlFile.write(
|
|
|
|
f"Admin={memb.steam64}:{self.name} //{memb.discord_username} ({memb.discord_id})\n"
|
|
|
|
)
|
2023-03-04 18:32:59 -06:00
|
|
|
wlFile.close()
|
|
|
|
|
|
|
|
def addMember(self, member):
|
|
|
|
self.members[f"{member.discord_id}"] = member
|
|
|
|
self.updateFile()
|
|
|
|
self.updateWL()
|
|
|
|
pass
|
|
|
|
|
|
|
|
def delMember(self, discordID):
|
2024-10-01 18:27:04 -05:00
|
|
|
self.members.pop(f"{discordID}")
|
2023-03-04 18:32:59 -06:00
|
|
|
self.updateFile()
|
|
|
|
self.updateWL()
|