Exemplo n.º 1
0
    async def role_leave(self, ctx: commands.Context, *, name: str = None):
        """Leave a self-assignable role"""

        timeout = settings.timeout(ctx.guild, self._session)
        member = ctx.message.author
        if name is None:
            await ctx.send(
                f"{member.mention}, to leave a self assignable role do `/leave <role_name>`",
                delete_after=timeout)
        elif not get(ctx.guild.roles, name=name):
            await ctx.send(
                f"{member.mention}, the role `{name}` does not exist, was that a typo?",
                delete_after=timeout)
        else:
            role = get(ctx.guild.roles, name=name)
            if self._registered(role):
                try:
                    await member.remove_roles(role)
                    await ctx.send(
                        f"{member.mention} has left **{role.name}**",
                        delete_after=timeout)
                except:
                    await ctx.send(
                        f"{member.mention}, **{name}** is set as self-assignable but cannot be assigned due to insufficient bot permissions, please contact an administrator",
                        delete_after=timeout)
            else:
                await ctx.send(
                    f"{member.mention}, **{role.name}** is not a self-assignable role. This incident will be reported.",
                    delete_after=timeout)
        await ctx.message.delete()
Exemplo n.º 2
0
    async def role_remove(self, ctx: commands.Context, *, name: str = None):
        """Remove a role from the list of self-assignables. Does not delete the role."""
        if settings.delete_user_command(ctx.guild, self._session):
            await ctx.message.delete()

        timeout = settings.timeout(ctx.guild, self._session)
        member: discord.Member = ctx.author
        if not member.guild_permissions.administrator:
            await ctx.send(
                f'{member.mention} Only an administrator may perform this action.',
                delete_after=timeout)
            return
        if name is None:
            await ctx.send(
                f"{member.mention}, to remove a self assignable role do `/remove <role_name>`",
                delete_after=timeout)
            return
        guild = ctx.guild
        role: discord.Role = get(guild.roles, name=name)

        if not role:
            await ctx.send(f'{member.mention} Role **{name}** does not exist.',
                           delete_after=timeout)
            return

        if role and not self._registered(role):
            await ctx.send(
                f'{member.mention} Role **{name}** is already non-self-assignable.',
                delete_after=timeout)
            return

        self._unregister(role)
        await ctx.send(
            f'{member.mention} Role **{name}** is no longer self-assignable.',
            delete_after=timeout)
Exemplo n.º 3
0
    async def start_new_season(self, ctx: commands.Context):
        """Remove roles from all"""
        if settings.delete_user_command(ctx.guild, self._session):
            await ctx.message.delete()

        timeout = settings.timeout(ctx.guild, self._session)
        member = ctx.message.author
        if not self._is_admin(member):
            await ctx.send(
                f"{member.mention} is not in the Admins role, This incident will be reported.",
                delete_after=timeout)
            return

        await ctx.send(f"**Starting new semester**")
        rows = self._session.execute(
            "SELECT role FROM giraffetime.roles WHERE guild=%s",
            (ctx.guild.id, ))
        for row in rows:
            role_id = row.role
            removeCount = 0
            role = get(ctx.guild.roles, id=role_id)
            await ctx.send(f"Reseting **{role.name}**", delete_after=timeout)
            for member in role.members:
                try:
                    await member.remove_roles(role)
                    removeCount += 1
                except:
                    await ctx.send(
                        f"An error occurred whilst removing {member.name} from role **{role.name}**.",
                        delete_after=timeout)
            await ctx.send(
                f"Removed **{removeCount}** members from **{role.name}**",
                delete_after=timeout)
        await ctx.send(f"**Reset all members' self-assignable roles**",
                       delete_after=timeout)
Exemplo n.º 4
0
    async def role_add(self, ctx: commands.Context, *, name: str = None):
        """If the role exists, add it to the list of self-assignable roles. Otherwise create a self-assignable role."""
        if settings.delete_user_command(ctx.guild, self._session):
            await ctx.message.delete()

        timeout = settings.timeout(ctx.guild, self._session)
        member: discord.Member = ctx.author

        if not self._is_admin(member):
            await ctx.send(
                f'{member.mention} Only an administrator may perform this action.',
                delete_after=timeout)
            return

        if name is None:
            await ctx.send(
                f"{member.mention}, to add a self assignable role do `/add <role_name>`",
                delete_after=timeout)
            return

        guild = ctx.guild
        role: discord.Role = get(guild.roles, name=name)
        if role and self._registered(role):
            await ctx.send(
                f'{member.mention} Role **{name}** is already self-assignable.',
                delete_after=timeout)
            return

        if not role:
            if not settings.create_new_role(ctx.guild, self._session):
                await ctx.send(
                    f'{member.mention} Role **{name}** does not exist.',
                    delete_after=timeout)
                return
            role = await guild.create_role(name=name)
            await ctx.send(
                f'{member.mention} Role **{name}** does not exist. Creating new role **{name}**.',
                delete_after=timeout)
            # Confirmation prompt for creating a new role? Not asynchronous, so will not respond to other requests.
            # await ctx.send(f'{member.mention} Role **{name}** does not exist. Create a new role? (yes|no)')
            # def check(m: discord.Message):
            #     return m.author == member
            # try:
            #     confirmation = await self.bot.wait_for('message', check=check, timeout=5.0)
            #     content: str = confirmation.content.lower()
            #     if content == 'y' or content == 'yes':
            #         role = await guild.create_role(name=name)
            #         await ctx.send(f'{member.mention} Created role **{name}**.', delete_after=timeout)
            #     else:
            #         await ctx.send(f'{member.mention} Operation cancelled.', delete_after=timeout)
            #         return
            # except asyncio.TimeoutError:
            #     await ctx.send(f'{member.mention} Operation cancelled -- took too long to respond.', delete_after=timeout)
            #     return

        self._register(role)
        await ctx.send(
            f'{member.mention} Role **{name}** is now self-assignable.',
            delete_after=timeout)
Exemplo n.º 5
0
    async def list_roles(self, ctx):
        """List all self-assignables roles"""
        settings.timeout(ctx.guild, self._session)
        if settings.delete_user_command(ctx.guild, self._session):
            await ctx.message.delete()

        timeout = settings.timeout(ctx.guild, self._session)

        roles = "```\n"
        rows = self._session.execute(
            "SELECT role FROM giraffetime.roles WHERE guild=%s",
            (ctx.guild.id, ))

        for row in rows:
            role_id = row.role
            removeCount = 0
            role = get(ctx.guild.roles, id=role_id)
            if role is not None:
                roles += role.name + "\n"
        roles += "```"
        embed = discord.Embed(color=0xff1c8d)
        embed.add_field(name="Self Assignable Roles", value=roles, inline=True)
        await ctx.send(embed=embed, delete_after=timeout)