adding existing whitelist overwrites permissions

This commit is contained in:
Skillet 2023-04-17 22:13:00 -04:00
parent 4007a49d37
commit d41b16281a
2 changed files with 16 additions and 9 deletions

View File

@ -17,17 +17,19 @@ class Group(commands.Cog, name="group"):
async def baseperm(self, interaction: discord.Interaction, role: discord.Role, perms: str): async def baseperm(self, interaction: discord.Interaction, role: discord.Role, perms: str):
if role.id in self.client.whitelistGrps.keys(): if role.id in self.client.whitelistGrps.keys():
await interaction.response.send_message( 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 = [] membsup = []
for memb in role.members: for memb in role.members:
membsup.append(memb.id) membsup.append(memb.id)
@ -39,6 +41,7 @@ class Group(commands.Cog, name="group"):
udata = memupcur.fetchall() udata = memupcur.fetchall()
for data in udata: for data in udata:
self.client.whitelistGrps[role.id].addMember(config.WhitelistMember(data[2], "unknown", data[0])) 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() self.client.squadjs.commit()
@app_commands.command() @app_commands.command()

View File

@ -33,6 +33,10 @@ class WhitelistGroup:
os.remove(f"./wlgrps/{self.name}.cfg") os.remove(f"./wlgrps/{self.name}.cfg")
os.remove(f"./wlgrps/{self.name}.json") os.remove(f"./wlgrps/{self.name}.json")
def updateGroup(self):
self.updateFile()
self.updateWL()
def updateFile(self): def updateFile(self):
outFile = open(f"./wlgrps/{self.name}.json", "w") outFile = open(f"./wlgrps/{self.name}.json", "w")
outFile.write(jsonpickle.encode(self)) outFile.write(jsonpickle.encode(self))