async def remove(self, ctx, role: discord.Role = None) -> None: role_repo = RoleRepository() await role_repo.set_role_assignable(role.id, False) title = f'Role #{role.name} Removed as assignable :white_check_mark:' embed = discord.Embed(title=title, color=Colors.ClemsonOrange) await ctx.send(embed=embed)
async def set_role(self, ctx, role: discord.Role = None) -> None: role_repo = RoleRepository() if not await role_repo.check_is_role_assignable(role.id): await self.send_role_list(ctx, f'@{str(role)} is not an assignable role') return if role.id in [role.id for role in ctx.author.roles]: await self.remove_role(ctx, role) else: await self.add_role(ctx, role)
async def set_role(self, ctx, role: discord.Role = None) -> None: role_repo = RoleRepository() if not await role_repo.check_is_role_assignable(role.id): embed = discord.Embed(title=f'@{role.name} is not assignable', color=Colors.Error) await ctx.send(embed=embed) return if role.id in [role.id for role in ctx.author.roles]: await self.remove_role(ctx, role) else: await self.add_role(ctx, role)
async def send_channel_list(self, ctx, title: str): role_repo = RoleRepository() results = await role_repo.get_assignable_roles(ctx.guild.id) if results: names = '\n'.join([role['name'] for role in results]) else: names = 'No currently assignable channels' embed = discord.Embed(title=title, color=Colors.ClemsonOrange) embed.add_field(name='Available:', value=names) await ctx.send(embed=embed)
async def insert_guild(self, guild: discord.Guild): log.info(f'Loading Roles from {guild.name}') role_repo = RoleRepository() db_roles = [i[0] for i in await role_repo.get_role_ids(guild.id)] api_roles = [r.id for r in guild.roles] for deleted_role_id in set(db_roles) - set(api_roles): log.info(f'Missing role {deleted_role_id} found, removing from local db') await role_repo.delete_role(deleted_role_id) for role in guild.roles: log.info(f'Loading role "{role.name}" in {guild.name}') await role_repo.add_or_update_role(role, guild.id)
async def send_role_list(self, ctx, title: str): role_repo = RoleRepository() CHUNK_SIZE= 15 results = await role_repo.get_assignable_roles(ctx.guild.id) embed = discord.Embed(title= title, color= Colors.ClemsonOrange) if results: for chunk in self.chunk_list([role['name'] for role in results], CHUNK_SIZE): embed.add_field(name= 'Available:', value= '\n'.join(chunk), inline= True) else: embed.add_field(name= 'Available:', value= 'No currently assignable roles.') await ctx.send(embed= embed)
async def assignable_role_remove(self, role): role_repo = RoleRepository() await role_repo.set_role_assignable(role.id, False)
async def assignable_role_add(self, role): role_repo = RoleRepository() await role_repo.set_role_assignable(role.id, True)