async def ranks_remove(self, ctx: Context, branch: str = None, *, role: str): if not branch or type(branch) == int: return await embed_maker.command_error(ctx) leveling_guild = self.bot.leveling_system.get_guild(ctx.guild.id) leveling_role = leveling_guild.get_leveling_role(role) branch = leveling_guild.get_leveling_route(branch) if branch is None: branch = leveling_guild.leveling_routes.parliamentary if leveling_role is None: return await embed_maker.error(ctx, f"Couldn't find a {branch.name} role by the name {role}") branch.roles.remove(leveling_role) await embed_maker.message( ctx, description=f'`{leveling_role.name}` has been remove from the list of `{branch.name}` roles', colour='green', send=True ) ctx.invoked_subcommand = '' return await self.ranks(ctx, branch.name)
async def reinvoke(self, ctx: commands.Context, *, call_hooks=False): early_invoke = not self.invoke_without_command if early_invoke: ctx.command = self await self._parse_arguments(ctx) if call_hooks: await self.call_before_hooks(ctx) view = ctx.view previous = view.index view.skip_ws() trigger = view.get_word() if trigger: ctx.subcommand_passed = trigger ctx.invoked_subcommand = self.all_commands.get(trigger) if early_invoke: try: await self.callback(*ctx.args, **ctx.kwargs) except Exception: ctx.command_failed = True raise finally: if call_hooks: await self.call_after_hooks(ctx) if trigger and ctx.invoked_subcommand: ctx.invoked_with = trigger await ctx.invoked_subcommand.reinvoke(ctx, call_hooks=call_hooks) elif not early_invoke: view.index = previous view.previous = previous await super().reinvoke(ctx, call_hooks=call_hooks)
async def ranks_add(self, ctx: Context, branch: str = None, *, role_name: str = None): if branch is None: return await embed_maker.command_error(ctx) leveling_guild = self.bot.leveling_system.get_guild(ctx.guild.id) branch = leveling_guild.get_leveling_route(branch) if branch is None: branch = leveling_guild.leveling_routes.parliamentary if not role_name: return await embed_maker.command_error(ctx, '[role name]') new_role = { 'name': role_name, 'perks': [] } leveling_role = leveling.LevelingRole(ctx.guild, branch, new_role) branch.roles.append(leveling_role) await embed_maker.message( ctx, description=f'`{role_name}` has been added to the list of `{branch.name}` roles', colour='green', send=True ) ctx.invoked_subcommand = '' return await self.ranks(ctx, branch.name)
async def invoke(self, ctx: commands.Context): early_invoke = not self.invoke_without_command if early_invoke: await self.prepare(ctx) view = ctx.view previous = view.index view.skip_ws() trigger = view.get_word() if trigger: ctx.subcommand_passed = trigger ctx.invoked_subcommand = self.all_commands.get(trigger) if early_invoke: injected = commands.core.hooked_wrapped_callback( self, ctx, self.callback) await injected(*ctx.args, **ctx.kwargs) if trigger and ctx.invoked_subcommand: ctx.invoked_with = trigger await ctx.invoked_subcommand.invoke(ctx) elif not early_invoke: view.index = previous view.previous = previous await super().invoke(ctx)