From d41b16281ac5efae571d36267d16191d42276bb2 Mon Sep 17 00:00:00 2001 From: Skillet Date: Mon, 17 Apr 2023 22:13:00 -0400 Subject: [PATCH] adding existing whitelist overwrites permissions --- autowl/Cogs/Group.py | 21 ++++++++++++--------- autowl/config.py | 4 ++++ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/autowl/Cogs/Group.py b/autowl/Cogs/Group.py index b193d6a..3d93592 100644 --- a/autowl/Cogs/Group.py +++ b/autowl/Cogs/Group.py @@ -17,17 +17,19 @@ class Group(commands.Cog, name="group"): async def baseperm(self, interaction: discord.Interaction, role: discord.Role, perms: str): if role.id in self.client.whitelistGrps.keys(): await interaction.response.send_message( - f"**{role.name}** is already added, cannot add it again!" + f"**{role.name}** is already added, overwriting permissions..." + ) + self.client.whitelistGrps[role.id].squadPerms = perms + self.client.whitelistGrps[role.id].updateGroup() + else: + log.info(f"Adding {role.name} ({role.id}) as a Whitelist role") + await interaction.response.send_message( + f"Adding **{role.name}** as a Whitelist role" + ) + self.client.whitelistGrps[role.id] = config.WhitelistGroup( + name=role.name, roleID=role.id, permissions=perms ) - return - log.info(f"Adding {role.name} ({role.id}) as a Whitelist role") - await interaction.response.send_message( - f"Adding **{role.name}** as a Whitelist role" - ) - self.client.whitelistGrps[role.id] = config.WhitelistGroup( - name=role.name, roleID=role.id, permissions=perms - ) membsup = [] for memb in role.members: membsup.append(memb.id) @@ -39,6 +41,7 @@ class Group(commands.Cog, name="group"): udata = memupcur.fetchall() for data in udata: self.client.whitelistGrps[role.id].addMember(config.WhitelistMember(data[2], "unknown", data[0])) + interaction.response.send_message("Whitelist group successfully added/updated") self.client.squadjs.commit() @app_commands.command() diff --git a/autowl/config.py b/autowl/config.py index 716da19..eff02af 100644 --- a/autowl/config.py +++ b/autowl/config.py @@ -33,6 +33,10 @@ class WhitelistGroup: os.remove(f"./wlgrps/{self.name}.cfg") os.remove(f"./wlgrps/{self.name}.json") + def updateGroup(self): + self.updateFile() + self.updateWL() + def updateFile(self): outFile = open(f"./wlgrps/{self.name}.json", "w") outFile.write(jsonpickle.encode(self))