From ef315a70e1f15d3a9a61c37d5787ad9acfa39f7f Mon Sep 17 00:00:00 2001 From: Skillet Date: Sat, 4 Mar 2023 14:34:59 -0500 Subject: [PATCH] output Squad whitelist file --- .gitignore | 1 + autowl/Cogs/Whitelist.py | 13 +++++++++++-- autowl/bot.py | 11 +++++++---- autowl/config.py | 1 - 4 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 7e6958f..5e8208f 100644 --- a/.gitignore +++ b/.gitignore @@ -133,3 +133,4 @@ dmypy.json .envrc /test.json +/testwl diff --git a/autowl/Cogs/Whitelist.py b/autowl/Cogs/Whitelist.py index d1e2afa..4a54f8d 100644 --- a/autowl/Cogs/Whitelist.py +++ b/autowl/Cogs/Whitelist.py @@ -34,13 +34,22 @@ class Whitelist(commands.Cog): if role.id == self.client.whitelist[group].discord_role_id: steam64_updated = True self.client.whitelist[group].members[ - interaction.user.id + str(interaction.user.id) ] = config.WhitelistMember(interaction.user.name, steam64) if steam64_updated: outFile = open("test.json", "w") - outFile.write(jsonpickle.encode(self.client.whitelist, unpicklable=False)) + outFile.write(jsonpickle.encode(self.client.whitelist)) 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( f"Updated {interaction.user.name}'s ({interaction.user.id}) whitelist steam64 to {steam64}" ) diff --git a/autowl/bot.py b/autowl/bot.py index a363eee..8034174 100644 --- a/autowl/bot.py +++ b/autowl/bot.py @@ -10,10 +10,13 @@ log = logging.getLogger(__name__) class Bot(commands.Bot): whitelist = config.Whitelist({}).whitelist - infile = open("test.json", "r") - if infile: - whitelist = jsonpickle.decode(infile.read()) - infile.close() + try: + infile = open("test.json", "r") + if infile: + whitelist = jsonpickle.decode(infile.read()) + infile.close() + except: + pass def __init__(self, config: config.DiscordClientConfig): self.config = config diff --git a/autowl/config.py b/autowl/config.py index e4767b8..552d55d 100644 --- a/autowl/config.py +++ b/autowl/config.py @@ -1,6 +1,5 @@ from dataclasses import dataclass - @dataclass class DiscordClientConfig: login_token: str