コード例 #1
0
ファイル: roles.py プロジェクト: Falsejoey/NabBot
    async def autorole_remove(self, ctx: NabCtx, role: InsensitiveRole, *,
                              guild: str):
        """Removes an autorole rule.

        Role names, mentions and ids are accepted. Role names with multiple words need to be quoted.

        Note that members that currently have the role won't be affected."""
        group: discord.Role = role
        result = userDatabase.execute(
            "SELECT * FROM auto_roles WHERE role_id = ? and guild LIKE ?",
            (group.id, guild))
        exists = list(result)
        if not exists:
            await ctx.send(f"{ctx.tick(False)} That rule doesn't exist.")
            return

        # Can't modify role higher than the owner's top role
        top_role: discord.Role = ctx.author.top_role
        if group >= top_role:
            await ctx.send(
                f"{ctx.tick(False)} You can't delete a role rule for a role higher than yours."
            )
            return

        await ctx.send(
            f"{ctx.tick()} Auto role rule removed. "
            f"Note that the role won't be removed from current members.")
        userDatabase.execute(
            "DELETE FROM auto_roles WHERE role_id = ? AND guild LIKE ?",
            (group.id, guild))
コード例 #2
0
ファイル: roles.py プロジェクト: Falsejoey/NabBot
    async def autorole_add(self, ctx: NabCtx, role: InsensitiveRole, *,
                           guild: str):
        """Creates a new autorole rule.

        Rules consist of a role and a guild name.  
        When a user has a registered character in said guild, they receive the role.  
        If they stop having a character in the guild, the role is removed.

        If `*` is used as a guild. It means that the role will be given for having any assigned character.

        Role names, role mentions or role ids are allowed. Role names with multiple words must be quoted.
        Note that current members will be updated until their characters or guilds change."""
        role: discord.Role = role
        name = guild
        if guild != "*":
            try:
                guild = await get_guild(name)
                if guild is None:
                    await ctx.send(f"There's no guild named `{name}`")
                    return
                name = guild.name
            except NetworkError:
                await ctx.send("I'm having network issues, try again later.")
                return

        result = userDatabase.execute(
            "SELECT * FROM auto_roles WHERE role_id = ? and guild LIKE ?",
            (role.id, name))
        exists = list(result)
        if exists:
            await ctx.send(f"{ctx.tick(False)} Autorole rule already exists.")
            return

        # Can't make autorole rule for role higher than the owner's top role
        top_role: discord.Role = ctx.author.top_role
        if role >= top_role:
            await ctx.send(
                f"{ctx.tick(False)} You can't create an automatic role with a role higher or equals "
                f"than your highest.")
            return

        if name != "*":
            msg = await ctx.send(
                f"Members of guild `{name}` will automatically receive the `{role.name}` role. "
                f"Is this correct?")
        else:
            msg = await ctx.send(
                f"All users with registered characters will automatically receive the `{role.name}` "
                f"role. Is this correct?")
        confirm = await ctx.react_confirm(msg, delete_after=True, timeout=60)
        if not confirm:
            return

        userDatabase.execute(
            "INSERT INTO auto_roles(server_id, role_id, guild) VALUES(?,?, ?)",
            (ctx.guild.id, role.id, name))
        await ctx.send(f"{ctx.tick()} Autorole rule created.")
コード例 #3
0
ファイル: roles.py プロジェクト: Falsejoey/NabBot
    async def on_guild_role_delete(self, role: discord.Role):
        """Called when a role is deleted.

        Removes joinable groups from the database when the role is deleted.
        """

        userDatabase.execute("DELETE FROM joinable_roles WHERE role_id = ?",
                             (role.id, ))
        userDatabase.execute("DELETE FROM auto_roles WHERE role_id = ?",
                             (role.id, ))
コード例 #4
0
ファイル: roles.py プロジェクト: Falsejoey/NabBot
    async def group_list(self, ctx: NabCtx):
        """Shows a list of available groups."""
        result = userDatabase.execute(
            "SELECT role_id FROM joinable_roles WHERE server_id = ?",
            (ctx.guild.id, ))
        groups = list(result)
        if not groups:
            await ctx.send(
                f"{ctx.tick(False)} This server has no joinable groups.")
            return

        flat_groups = [g['role_id'] for g in groups]

        entries = []
        roles = ctx.guild.role_hierarchy
        for role in roles:
            if role.id in flat_groups:
                entries.append(
                    f"{role.mention} (`{len(role.members)} members`)")

        per_page = 20 if ctx.long else 5
        pages = Pages(ctx, entries=entries, per_page=per_page)
        pages.embed.title = "Joinable groups"
        try:
            await pages.paginate()
        except CannotPaginate as e:
            await ctx.send(e)
コード例 #5
0
ファイル: roles.py プロジェクト: Falsejoey/NabBot
    async def group(self, ctx: NabCtx, group: InsensitiveRole):
        """Joins or leaves a group (role).

        If you're not in the group, you will be added.
        If you're already in the group, you will be removed.

        To see a list of joinable groups, use `group list`"""
        group: discord.Role = group
        result = userDatabase.execute(
            "SELECT * FROM joinable_roles WHERE role_id = ?", (group.id, ))
        exists = list(result)
        if not exists:
            await ctx.send(
                f"{ctx.tick(False)} Group `{group.name}` doesn't exists.")
            return

        # Check if user already has the role
        member_role = discord.utils.get(ctx.author.roles, id=group.id)

        try:
            if member_role is None:
                await ctx.author.add_roles(group, reason="Joined group")
            else:
                await ctx.author.remove_roles(member_role, reason="Left group")
        except discord.Forbidden:
            await ctx.send(
                f"{ctx.tick(False)} I need `Manage Roles` to manage groups.")
        except discord.HTTPException:
            await ctx.send(
                f"{ctx.tick(False)} Something went wrong. Try again later.")
        else:
            if member_role is None:
                await ctx.send(f"{ctx.tick(True)} Joined `{group.name}`.")
            else:
                await ctx.send(f"{ctx.tick(True)} You left `{group.name}`.")
コード例 #6
0
ファイル: roles.py プロジェクト: Falsejoey/NabBot
    async def autorole_list(self, ctx: NabCtx):
        """Shows a list of autorole rules."""
        result = userDatabase.execute(
            "SELECT role_id, guild FROM auto_roles WHERE server_id = ?",
            (ctx.guild.id, ))
        rules = list(result)
        if not rules:
            await ctx.send(
                f"{ctx.tick(False)} This server has no autorole rules.")
            return

        flat_rules = [(r['role_id'], r['guild']) for r in rules]

        entries = []
        for role_id, guild in flat_rules:
            role: discord.Role = discord.utils.get(ctx.guild.roles, id=role_id)
            if role is None:
                continue
            entries.append(f"{role.mention} — `{guild}`")

        if not entries:
            await ctx.send(
                f"{ctx.tick(False)} This server has no autorole rules.")
            return

        per_page = 20 if ctx.long else 5
        pages = Pages(ctx, entries=entries, per_page=per_page)
        pages.embed.title = "Autorole rules"
        try:
            await pages.paginate()
        except CannotPaginate as e:
            await ctx.send(e)
コード例 #7
0
    async def group_add(self, ctx: NabCtx, *, name: str):
        """Creates a new group for members to join.

        The group can be a new role that will be created with this command.  
        If the name matches an existent role, that role will become joinable.

        You need `Manage Roles` permissions to use this command."""
        name = name.replace("\"", "")
        forbidden = ["add", "remove", "delete", "list"]
        converter = InsensitiveRole()
        try:
            role = await converter.convert(ctx, name)
        except commands.BadArgument:
            try:
                if name.lower() in forbidden:
                    raise discord.InvalidArgument()
                role = await ctx.guild.create_role(
                    name=name, reason="Created joinable role")
            except discord.Forbidden:
                await ctx.send(
                    f"{ctx.tick(False)} I need `Manage Roles` permission to create a group."
                )
                return
            except discord.InvalidArgument:
                await ctx.send(f"{ctx.tick(False)} Invalid group name.")
                return
        result = userDatabase.execute(
            "SELECT * FROM joinable_roles WHERE role_id = ?", (role.id, ))
        group = list(result)
        if group:
            await ctx.send(
                f"{ctx.tick(False)} Group `{role.name}` already exists.")
            return

        # Can't make joinable group a role higher than the owner's top role
        top_role: discord.Role = ctx.author.top_role
        if role >= top_role:
            await ctx.send(
                f"{ctx.tick(False)} You can't make a group with a role higher or equals than your highest."
            )
            return

        userDatabase.execute(
            "INSERT INTO joinable_roles(server_id, role_id) VALUES(?,?)",
            (ctx.guild.id, role.id))
        await ctx.send(
            f"{ctx.tick()} Group `{role.name}` created successfully.")
コード例 #8
0
ファイル: mod.py プロジェクト: Sinsae/NabBot
    async def unignore(self, ctx, *, channel: discord.TextChannel = None):
        """Makes teh bot unignore a channel

        Ignored channels don't process commands. However, the bot may still announce deaths and level ups if needed.

        If the parameter is used with no parameters, it ignores the current channel."""
        if channel is None:
            channel = ctx.channel

        if channel.id not in self.ignored.get(ctx.guild.id, []):
            await ctx.send(f"{channel.mention} is not ignored.")
            return

        with userDatabase:
            userDatabase.execute(
                "DELETE FROM ignored_channels WHERE channel_id = ?",
                (channel.id, ))
            await ctx.send(f"{channel.mention} is not ignored anymore.")
            self.reload_ignored()
コード例 #9
0
ファイル: mod.py プロジェクト: Sinsae/NabBot
    async def ignore(self, ctx, *, channel: discord.TextChannel = None):
        """Makes the bot ignore a channel

        Ignored channels don't process commands. However, the bot may still announce deaths and level ups if needed.

        If the parameter is used with no parameters, it ignores the current channel.

        Note that server administrators can bypass this."""
        if channel is None:
            channel = ctx.channel

        if channel.id in self.ignored.get(ctx.guild.id, []):
            await ctx.send(f"{channel.mention} is already ignored.")
            return

        with userDatabase:
            userDatabase.execute(
                "INSERT INTO ignored_channels(server_id, channel_id) VALUES(?, ?)",
                (ctx.guild.id, channel.id))
            await ctx.send(f"{channel.mention} is now ignored.")
            self.reload_ignored()
コード例 #10
0
ファイル: roles.py プロジェクト: Falsejoey/NabBot
    async def group_remove(self, ctx: NabCtx, *, group: InsensitiveRole):
        """Removes a group.

        Removes a group, making members unable to join.
        When removing a group, you can optionally delete the role too."""
        group: discord.Role = group
        result = userDatabase.execute(
            "SELECT * FROM joinable_roles WHERE role_id = ?", (group.id, ))
        exists = list(result)
        if not exists:
            await ctx.send(f"{ctx.tick(False)} `{group.name}` is not a group.")
            return

        # Can't modify role higher than the owner's top role
        top_role: discord.Role = ctx.author.top_role
        if group >= top_role:
            await ctx.send(
                f"{ctx.tick(False)} You can't delete a group of a role higher than yours."
            )
            return

        msg = await ctx.send(f"Group `{group.name}` will be removed."
                             f"Do you want to remove the role too?")
        confirm = await ctx.react_confirm(msg, timeout=60, delete_after=True)
        if confirm is True:
            try:
                await group.delete(reason=f"Group removed by {ctx.author}")
                await ctx.send(
                    f"{ctx.tick()} Group `{group.name}`  was removed and the role was deleted."
                )
            except discord.Forbidden:
                await ctx.send(
                    f"{ctx.tick(False)} I need `Manage Roles` permission to delete the role.\n"
                    f"{ctx.tick()} Group `{group.name}` removed.")
        else:
            await ctx.send(f"{ctx.tick()} Group `{group.name}` was removed.")
        userDatabase.execute("DELETE FROM joinable_roles WHERE role_id = ?",
                             (group.id, ))