output Squad whitelist file

This commit is contained in:
Skillet 2023-03-04 14:34:59 -05:00
parent 6f05fcb5ee
commit ef315a70e1
4 changed files with 19 additions and 7 deletions

1
.gitignore vendored
View File

@ -133,3 +133,4 @@ dmypy.json
.envrc .envrc
/test.json /test.json
/testwl

View File

@ -34,13 +34,22 @@ class Whitelist(commands.Cog):
if role.id == self.client.whitelist[group].discord_role_id: if role.id == self.client.whitelist[group].discord_role_id:
steam64_updated = True steam64_updated = True
self.client.whitelist[group].members[ self.client.whitelist[group].members[
interaction.user.id str(interaction.user.id)
] = config.WhitelistMember(interaction.user.name, steam64) ] = config.WhitelistMember(interaction.user.name, steam64)
if steam64_updated: if steam64_updated:
outFile = open("test.json", "w") outFile = open("test.json", "w")
outFile.write(jsonpickle.encode(self.client.whitelist, unpicklable=False)) outFile.write(jsonpickle.encode(self.client.whitelist))
outFile.close() outFile.close()
wlFile = open("testwl", "w")
for wlgrp in self.client.whitelist:
wlFile.write(f"Group={wlgrp}:reserve\n")
for wlgrp in self.client.whitelist:
wlFile.write("\n")
wlFile.write(f"//{wlgrp}\n")
for wlmem in self.client.whitelist[wlgrp].members:
wlFile.write(f"Admin={self.client.whitelist[wlgrp].members[wlmem].steam64}:{wlgrp} //{self.client.whitelist[wlgrp].members[wlmem].discord_username} ({wlmem})\n")
wlFile.close()
log.info( log.info(
f"Updated {interaction.user.name}'s ({interaction.user.id}) whitelist steam64 to {steam64}" f"Updated {interaction.user.name}'s ({interaction.user.id}) whitelist steam64 to {steam64}"
) )

View File

@ -10,10 +10,13 @@ log = logging.getLogger(__name__)
class Bot(commands.Bot): class Bot(commands.Bot):
whitelist = config.Whitelist({}).whitelist whitelist = config.Whitelist({}).whitelist
infile = open("test.json", "r") try:
if infile: infile = open("test.json", "r")
whitelist = jsonpickle.decode(infile.read()) if infile:
infile.close() whitelist = jsonpickle.decode(infile.read())
infile.close()
except:
pass
def __init__(self, config: config.DiscordClientConfig): def __init__(self, config: config.DiscordClientConfig):
self.config = config self.config = config

View File

@ -1,6 +1,5 @@
from dataclasses import dataclass from dataclasses import dataclass
@dataclass @dataclass
class DiscordClientConfig: class DiscordClientConfig:
login_token: str login_token: str