DiscordWhitelist/autowl/config.py

67 lines
1.6 KiB
Python
Raw Normal View History

2023-03-04 18:32:59 -06:00
import os
import jsonpickle
from dataclasses import dataclass
2023-03-04 18:32:59 -06:00
@dataclass
class DiscordClientConfig:
login_token: str
@dataclass
class WhitelistMember:
2023-03-04 18:32:59 -06:00
discord_id: int
discord_username: str
steam64: int
@dataclass
class WhitelistGroup:
2023-03-04 18:32:59 -06:00
name: str
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):
os.remove(f"./wlgrps/{self.name}.cfg")
2023-03-04 18:32:59 -06:00
os.remove(f"./wlgrps/{self.name}.json")
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):
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()