예제 #1
0
    async def moverole(self, ctx: aoi.AoiContext, position: int, roles: Greedy[discord.Role]):
        if not roles:
            raise commands.BadArgument("I need to know what role(s) to move!")
        roles: List[discord.Role] = list(roles)

        for role in roles:
            if role >= ctx.author.top_role and ctx.guild.owner_id != ctx.author.id:
                raise aoi.RoleHierarchyError(f"{role.mention} must be below your highest role in order for "
                                             f"you to move it.")
            if role >= ctx.me.top_role:
                raise aoi.RoleHierarchyError(f"{role.mention} must be above my highest role for me to move it.")
        if not await ctx.confirm(f"Move {' '.join(r.name for r in roles)} to position {position}?",
                                 "Moving roles...",
                                 "Role move cancelled"):
            return

        n = 0

        async def do_op():
            nonlocal n
            for r in roles:
                await r.edit(position=position)

        await ctx.trigger_typing()
        if len(roles) > 3:
            await ctx.send_info(f"Moving {len(roles)} roles. Will take at least {len(roles)}s")
        await self.bot.create_task(ctx, do_op(), lambda: f"{n}/{(len(roles))}")
        await ctx.send_ok(f"Moved {' '.join('`' + r.name + '`' for r in roles)}", ping=len(roles) > 10)
예제 #2
0
 async def setnick(self, ctx: aoi.AoiContext, member: discord.Member, *, nickname: str):
     if member.top_role >= ctx.author.top_role:
         raise aoi.RoleHierarchyError("You can't change the nickname of a person with a role higher than yours!")
     if member.id == ctx.me.id:
         await ctx.me.edit(nick=nickname)
     else:
         if member.top_role >= ctx.me.top_role:
             raise aoi.RoleHierarchyError("I can't change the nickname of a person with a role higher than mine!")
         await member.edit(nick=nickname)
     await ctx.send_ok(f"{member.mention}'s nickname set to {nickname}")
예제 #3
0
 def _check_role(self,
                 ctx: aoi.AoiContext,
                 member: discord.Member,
                 action: str = "edit"):
     if member.top_role >= ctx.author.top_role and ctx.guild.owner_id != ctx.author.id:
         raise aoi.RoleHierarchyError(
             f"You can't {action} someone with a role higher than yours")
     if member.top_role >= ctx.me.top_role:
         raise aoi.RoleHierarchyError(
             f"I can't {action} someone with a role higher than mine")
     if member.id == ctx.guild.owner_id:
         raise aoi.RoleHierarchyError(f"We can't {action} the server owner")
예제 #4
0
def _soft_check_role(ctx: aoi.AoiContext,
                     member: discord.Member,
                     action: str = "edit"):
    if member.top_role >= ctx.me.top_role:
        raise aoi.RoleHierarchyError(
            f"I can't {action} someone with a role higher than or equal to mine"
        )
예제 #5
0
 async def addrero(self, ctx: aoi.AoiContext, message: discord.Message, *,
                   args: str):  # noqa c901
     split = ctx.group_list(args.split(), 2)
     role_converter = commands.RoleConverter()
     for i in split:
         print(i)
         try:
             emoji: discord.PartialEmoji = await partial_emoji_convert(
                 ctx, i[0])
             role: discord.Role = await role_converter.convert(ctx, i[1])
         except commands.PartialEmojiConversionFailure:
             return await ctx.send_error(f"Emoji {i[0]} invalid")
         except commands.RoleNotFound:
             return await ctx.send_error(f"Role {i[1]} invalid")
         if role >= ctx.author.top_role and ctx.guild.owner_id != ctx.author.id:
             raise aoi.RoleHierarchyError(
                 f"Role {role} must be lower than your highest")
         if role >= ctx.me.top_role:
             raise aoi.RoleHierarchyError(
                 f"Role {role} must be lower than mine")
         try:
             await message.add_reaction(emoji)
         except discord.Forbidden:
             return await ctx.send_error("I can't react to that message!")
         except discord.HTTPException:
             return await ctx.send_error(f"Emoji {i[0]} invalid")
         if message.id not in self._roles:
             self._roles[message.id] = {}
         if emoji.name in self._roles[message.id] or str(
                 emoji.id) in self._roles[message.id]:
             return await ctx.send_error("That emoji is already being used")
         self._roles[message.id][str(emoji.id) if emoji.id else emoji.
                                 name] = _ReactionRoleData(role)
         await self._db.conn.execute(
             "insert into rero values (?,?,?,?,?,0,0)",
             (ctx.guild.id, message.channel.id, message.id,
              str(emoji.id) if emoji.id else emoji.name, role.id))
         await self._db.conn.commit()
         await ctx.send_ok("Added!")
예제 #6
0
    async def roleall(self, ctx: aoi.AoiContext, role: discord.Role):
        flags = ctx.flags
        ignore_bots = "ignorebots" in flags
        with_role = flags.get("withrole", None)
        if role >= ctx.author.top_role and ctx.guild.owner_id != ctx.author.id:
            raise aoi.RoleHierarchyError(f"{role.mention} must be below your highest role in order for "
                                         f"you to delete it.")
        if role >= ctx.me.top_role:
            raise aoi.RoleHierarchyError(f"{role.mention} must be above my highest role for me to delete it.")
        members: List[discord.Member] = list(filter(lambda x: role.id not in [r.id for r in x.roles],  # noqa
                                                    ctx.guild.members))
        if ignore_bots:
            members = [member for member in members if not member.bot]
        if with_role:
            members = [member for member in members if with_role.id in [r.id for r in member.roles]]
        await ctx.send_ok(f"Adding {role.mention} to {len(members)} that don't have it" +
                          (", while ignoring bots" if ignore_bots else "") +
                          ". This will take at " +
                          f"least {len(members) // 2}s")
        n = 0

        async def do_op():
            nonlocal n
            for m in members:
                if m.bot and ignore_bots:
                    continue
                if with_role and with_role.id not in [r.id for r in m.roles]:
                    continue
                await m.add_roles(role, reason=f"roleall by {ctx.author} | {ctx.author.id}")
                n += 1
                await aoi.asyncio.sleep(1)

        await ctx.trigger_typing()
        await self.bot.create_task(ctx, do_op(), lambda: f"{n}/{len(members)}")

        await ctx.done_ping()
예제 #7
0
 def _soft_check_role(self, ctx: aoi.AoiContext, role: discord.Role, action: str = "edit"):
     if role >= ctx.me.top_role:
         raise aoi.RoleHierarchyError(f"I can't {action} a role higher than or equal to mine")
예제 #8
0
 def _check_role(self, ctx: aoi.AoiContext, role: discord.Role, action: str = "edit"):
     if role >= ctx.author.top_role and ctx.guild.owner_id != ctx.author.id:
         raise aoi.RoleHierarchyError(f"Role to {action} must be lower than your highest")
     if role >= ctx.me.top_role:
         raise aoi.RoleHierarchyError(f"I can't {action} a role higher than or equal to mine")