Пример #1
0
 async def reset(self, ctx):
     session = Session()
     obj = to_sql(session, ctx.guild, Guild)
     for member in obj.members:
         self.set_data(session, member, DEFAULT_ROLE_USER_DATA)
     for role in obj.roles:
         self.set_data(session, role, DEFAULT_ROLE_USER_DATA)
     embed = generate_embed_template(ctx, 'Permissions Bindings Reset Successfully')
     embed.description = 'You may now set up your permissions again.'
     await ctx.send(embed=embed)
Пример #2
0
 async def allow(self, ctx, role: DiscordRole):
     session = Session()
     obj = to_sql(session, role, Role)
     data = self.get_data(obj, DEFAULT_ROLE_DATA)
     if data:
         session.close()
         raise CommandError('Role `{}` is already allowed'.format(
             str(role)))
     self.set_data(session, obj, True)
     session.close()
     embed = generate_embed_template(ctx, 'Role Allowed Successfully')
     embed.description = str(role)
     await ctx.send(embed=embed)
Пример #3
0
 async def add(self, ctx, role: DiscordRole):
     session = Session()
     obj = to_sql(session, role, Role)
     data = self.get_data(obj, DEFAULT_ROLE_DATA)
     session.close()
     if data:
         if role in ctx.author.roles:
             raise CommandError('You already have the role `{}`'.format(
                 str(role)))
         await ctx.author.add_roles(role, reason='Added via command')
         embed = generate_embed_template(ctx, 'Role Add Successfully')
         embed.description = str(role)
         await ctx.send(embed=embed)
         return
     raise CommandError('You are not allowed to add role {}'.format(
         str(role)))
Пример #4
0
 async def add(self, ctx, target: typing.Union[DiscordRole, DiscordMember], permission: str):
     session = Session()
     if isinstance(target, DiscordMember):
         obj = to_sql(session, target, Member)
         target_type = 'Member'
     else:
         obj = to_sql(session, target, Role)
         target_type = 'Role'
     data = self.get_data(obj, DEFAULT_ROLE_USER_DATA)
     if permission in data:
         session.close()
         raise CommandError('{} `{}` already has permission `{}`'.format(target_type, str(target), permission))
     else:
         data.append(permission)
         self.set_data(session, obj, data)
         embed = generate_embed_template(ctx, 'Permissions Binding Added Successfully')
         set_permissions_embed(embed, target_type, target, permission)
         session.close()
         await ctx.send(embed=embed)
Пример #5
0
 async def remove(self, ctx, target: typing.Union[DiscordMember, DiscordRole], permission: str):
     session = Session()
     if isinstance(target, DiscordMember):
         obj = to_sql(session, target, Member)
         target_type = 'Member'
     else:
         obj = to_sql(session, target, Role)
         target_type = 'Role'
     data = self.get_data(obj, DEFAULT_ROLE_USER_DATA)
     if permission in data:
         data.remove(permission)
         self.set_data(session, obj, data)
         embed = generate_embed_template(ctx, 'Permissions Binding Removed Successfully')
         set_permissions_embed(embed, target_type, target, permission)
         session.close()
         await ctx.send(embed=embed)
     else:
         session.close()
         raise CommandError('Could not find {} `{}` with permission `{}`'.format(target_type.lower(), str(target),
                                                                                 permission))
Пример #6
0
 async def on_command_error(self, ctx, exception):
     embed = generate_embed_template(ctx, 'Error Running Command', True)
     embed.description = str(exception)
     await ctx.send(embed=embed)