示例#1
0
    async def role_get(self, ctx, *roles: discord.Role):
        """Adds self-serve roles to the caller.

        Examples:
          ~role get DotA
          ~role get Gamer "League of Legends"

        Roles must be allowed via ~role allow before they can be used with this
        command. See ~help role allow for more information.
        Requires Manage Roles (Bot)
        """
        role_config = await ctx.bot.storage.role_configs.get(ctx.guild.id)
        role_config = role_config or proto.RoleConfig()
        role_ids = set(role_config.self_serve_role_ids)
        # Ensure the roles can be safely added.
        top_role = ctx.guild.me.top_role
        for role in roles:
            if role >= top_role:
                await ctx.send(f"`{role.name}` is higher than bot's highest.",
                               delete_after=DELETE_WAIT_DURATION)
                return
            if role.id not in role_ids:
                await ctx.send(f'`{role.name}` is not set up for self-serve.',
                               delete_after=DELETE_WAIT_DURATION)
                return
        reason = 'Self serve role(s) requested by user.'
        await ctx.author.add_roles(*roles, reason=reason)
        await ctx.send(':thumbsup:', delete_after=DELETE_WAIT_DURATION)
示例#2
0
    async def role_forbid(self, ctx, *roles: discord.Role):
        """Disallows one or more role to be self served.

        Examples:
          ~role forbid DotA
          ~role forbid Gamer "League of Legends"

        Running this command disallows normal users to use ~role get and
        ~role drop.
        Requires Manage Roles (User and Bot)
        """
        async def _check_highest_role(member):
            highest_role = max(member.roles)
            for role in roles:
                if role > highest_role:
                    msg = (f'Cannot disallow self serve of "{role.name}". Role'
                           f' is higher than {member.mention}\'s highest '
                           f'role.')
                    await ctx.send(msg, delete_after=DELETE_WAIT_DURATION)
                    return True
            return False

        if ((await _check_highest_role(ctx.guild.me))
                or (await _check_highest_role(ctx.author))):
            return

        storage = ctx.bot.storage.role_configs
        role_config = await storage.get(ctx.guild.id)
        role_config = role_config or proto.RoleConfig()
        role_ids = set(role_config.self_serve_role_ids)
        for role in roles:
            if role.id in role_ids:
                role_config.self_serve_role_ids.remove(role.id)
        await storage.set(ctx.guild.id, role_config)
        await ctx.send(':thumbsup:', delete_after=DELETE_WAIT_DURATION)
示例#3
0
    async def role_forbid(self, ctx, *roles: discord.Role):
        """Disallows one or more role to be self served.

        Examples:
          ~role forbid DotA
          ~role forbid Gamer "League of Legends"

        Running this command disallows normal users to use ~role get and
        ~role drop.
        Requires Manage Roles (User and Bot)
        """
        if not (await check_role_manager(ctx, *roles)):
            return

        storage = ctx.bot.storage.role_configs
        role_config = await storage.get(ctx.guild.id)
        role_config = role_config or proto.RoleConfig()
        role_ids = set(role_config.self_serve_role_ids)
        for role in roles:
            if role.id in role_ids:
                role_config.self_serve_role_ids.remove(role.id)
        await storage.set(ctx.guild.id, role_config)
        await ctx.send(':thumbsup:', delete_after=DELETE_WAIT_DURATION)
示例#4
0
    async def role_drop(self, ctx, *roles: discord.Role):
        """Removes self-serve roles to the caller.

        Examples:
          ~role drop DotA
          ~role drop Gamer "League of Legends"

        Roles must be allowed via ~role allow before they can be used with this
        command. See ~help role allow for more information.
        Requires Manage Roles (Bot)
        """
        role_config = await ctx.bot.storage.role_configs.get(ctx.guild.id)
        role_config = role_config or proto.RoleConfig()
        role_ids = set(role_config.self_serve_role_ids)
        # Ensure the roles can be safely removed.
        roles = [r for r in roles if r < max(ctx.guild.me.roles)]
        for role in roles:
            if role.id not in role_ids:
                await ctx.send(f'`{role.name}` is not set up for self-serve.',
                               delete_after=DELETE_WAIT_DURATION)
                return
        reason = 'Self serve role(s) requested to be removed by user.'
        await ctx.author.remove_roles(*roles, reason=reason)
        await ctx.send(':thumbsup:', delete_after=DELETE_WAIT_DURATION)