Skip to content

Commit

Permalink
Stringify all the roles
Browse files Browse the repository at this point in the history
  • Loading branch information
optimumtact committed Sep 7, 2024
1 parent 47c9f03 commit f2ec6c7
Showing 1 changed file with 29 additions and 20 deletions.
49 changes: 29 additions & 20 deletions rolemanage/rolemanage.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,26 +124,33 @@ async def roleadd(self, ctx, sourcerole: discord.Role, targetrole: discord.Role)
"""
Sets that a given role can manage a given role by applying and removing it
"""
sourceroleid = str(sourcerole.id)
targetroleid = str(targetrole.id)
roles = await self.config.guild(ctx.guild).role_map()
if sourcerole.id in roles:
if targetrole.id not in roles[sourcerole.id]:
roles[sourcerole.id].append(targetrole.id)
if sourceroleid in roles:
if targetroleid not in roles[sourceroleid]:
roles[sourceroleid].append(targetroleid)
await self.config.guild(ctx.guild).role_map.set(roles)
await ctx.send(f"Role {sourcerole} can now manage {targetrole}")
else:
roles[sourcerole.id] = list()
roles[sourcerole.id].append(targetrole.id)
await self.config.guild(ctx.guild).role_map.set(roles)
await ctx.send(f"Role {sourcerole} can now manage {targetrole}")
roles[sourceroleid] = list()
roles[sourceroleid].append(targetroleid)
await self.config.guild(ctx.guild).role_map.set(roles)
await ctx.send(f"Role {sourcerole} can now manage {targetrole}")

@config.command()
async def roledel(self, ctx, sourcerole: discord.Role, targetrole: discord.Role):
"""
Removes that a given role can manage a given role by applying and removing it
"""
roles = await self.config.guild(ctx.guild).role_map()
if sourcerole.id in roles:
roles[sourcerole.id].remove(targetrole.id)
await self.config.guild(ctx.guild).role_map.set(roles)
await ctx.send(f"Role {sourcerole} can no longer manage {targetrole}")
sourceroleid = str(sourcerole.id)
targetroleid = str(targetrole.id)
if sourceroleid in roles:
if targetroleid in roles[sourceroleid]:
roles[sourceroleid].remove(targetroleid)
await self.config.guild(ctx.guild).role_map.set(roles)
await ctx.send(f"Role {sourcerole} can no longer manage {targetrole}")

@config.command()
async def enable(self, ctx):
Expand All @@ -169,13 +176,14 @@ async def remove(self, ctx, user: discord.Member, role: discord.Role):

role_map_dict = await self.config.guild(ctx.guild).role_map()
allowed_roles = set()
roleid = str(role.id)
for author_role in ctx.author.roles:
roleid = str(author_role.id)
if roleid in role_map_dict:
allowed_roles.update(role_map_dict[roleid])
log.debug(f"found role mappings {role_map_dict[roleid]}")
authorroleid = str(author_role.id)
if authorroleid in role_map_dict:
allowed_roles.update(role_map_dict[authorroleid])
log.debug(f"found role mappings {role_map_dict[authorroleid]}")

if role.id not in allowed_roles:
if roleid not in allowed_roles:
log.debug(f"The {role} was not in the {allowed_roles}")
await ctx.send("You are not authorised to remove this role")
return
Expand Down Expand Up @@ -207,12 +215,13 @@ async def apply(self, ctx, user: discord.Member, role: discord.Role):

role_map_dict = await self.config.guild(ctx.guild).role_map()
allowed_roles = set()
roleid = str(role.id)
for author_role in ctx.author.roles:
roleid = str(author_role.id)
if roleid in role_map_dict:
allowed_roles.update(role_map_dict[roleid])
authorroleid = str(author_role.id)
if authorroleid in role_map_dict:
allowed_roles.update(role_map_dict[authorroleid])

if role.id not in allowed_roles:
if roleid not in allowed_roles:
log.debug(f"The {role} was not in the {allowed_roles}")
await ctx.send("You are not authorised to add this role")
return
Expand Down

0 comments on commit f2ec6c7

Please sign in to comment.