示例#1
0
    async def _reminders_repeat(self, ctx: custom.Context, reminder: objects.Reminder, *, repeat_type: enums.ReminderRepeatType) -> None:
        """
        Edits a reminders repeat type.

        **reminder**: The id of the reminder to edit.
        **repeat_type**: The repeat type to set for the reminder.
        """

        if reminder.done:
            raise exceptions.EmbedError(
                colour=colours.RED,
                emoji=emojis.CROSS,
                description="That reminder is already done."
            )

        await reminder.change_repeat_type(repeat_type)

        await ctx.reply(
            embed=utils.embed(
                colour=colours.GREEN,
                emoji=emojis.TICK,
                description=f"Edited repeat type of reminder with id **{reminder.id}**."
            )
        )
示例#2
0
    async def notifications_disable(
            self,
            ctx: custom.Context,
            *,
            notification_type: enums.NotificationType = utils.MISSING) -> None:
        """
        Disables a notification type.

        **notification_type**: The notification type to disable, if not passed, a list of a valid types will be displayed.
        """

        if not notification_type:
            await converters.EnumConverter(
                enums.NotificationType, "Notification type").convert(
                    ctx,
                    "a")  # this is a bad way to cause the error but whatever.

        user_config = await self.bot.user_manager.get_config(ctx.author.id)
        attr_name = notification_type.value.lower()

        if getattr(user_config.notifications, attr_name) is False:
            raise exceptions.EmbedError(
                colour=colours.RED,
                emoji=emojis.CROSS,
                description=
                f"You already have **{attr_name.replace('_', ' ')}** notifications disabled."
            )

        await user_config.notifications.set_notification(
            notification_type, False)

        await ctx.reply(embed=utils.embed(
            colour=colours.GREEN,
            emoji=emojis.TICK,
            description=
            f"Disabled **{attr_name.replace('_', ' ')}** notifications."))
示例#3
0
    async def blacklist_add(self, ctx: custom.Context, user: discord.User, *,
                            reason: str | None) -> None:
        """
        Adds a user to the blacklist.

        **user**: The user to blacklist, can be their ID, Username, Nickname or @Mention.
        **reason**: Reason why the user is being blacklisted.
        """

        reason = reason or f"{user} - No reason"

        user_config = await self.bot.user_manager.get_config(user.id)
        if user_config.blacklisted is True:
            raise exceptions.EmbedError(
                colour=colours.RED,
                emoji=emojis.CROSS,
                description=f"**{user}** is already blacklisted.")

        await user_config.set_blacklisted(True, reason=reason)

        embed = utils.embed(colour=colours.GREEN,
                            emoji=emojis.TICK,
                            description=f"Added **{user}** to the blacklist.")
        await ctx.reply(embed=embed)
示例#4
0
文件: enum.py 项目: Axelancerr/Life
class EnumConverter(Generic[EnumType], commands.Converter[EnumType]):
    def __init__(self, enum: Type[EnumType], name: str) -> None:

        self.enum: EnumType = enum
        self.name: str = name

    async def convert(self, ctx: custom.Context, argument: str) -> EnumType:

        if enum := getattr(self.enum,
                           argument.replace(" ", "_").upper(), None):
            return enum

        options = [
            f"- `{option}`" for option in [
                repeat_type.name.replace("_", " ").lower()
                for repeat_type in self.enum
            ]
        ]

        raise exceptions.EmbedError(
            colour=colours.RED,
            description=
            f"{self.name} must be one of:\n{values.NL.join(options)}",
        )
示例#5
0
        *,
        source: slate.obsidian.Source,
        ctx: custom.Context | None,
    ) -> slate.obsidian.Result[custom.Context]:

        if (url := yarl.URL(query)) and url.host and url.scheme:
            source = slate.obsidian.Source.NONE

        try:
            search = await self._node.search(query, source=source, ctx=ctx)

        except slate.obsidian.NoResultsFound as error:

            raise exceptions.EmbedError(
                colour=colours.RED,
                emoji=emojis.CROSS,
                description=
                f"No {error.search_source.value.lower().replace('_', ' ')} {error.search_type.value}s were found for your search.",
            )

        except (slate.obsidian.SearchFailed, slate.HTTPError):
            raise exceptions.EmbedError(
                colour=colours.RED,
                emoji=emojis.CROSS,
                description="There was an error while searching for results.",
                view=views.SupportButton())

        return search

    async def queue_search(
        self,
        query: str,
示例#6
0
        guild_config = await self.bot.guild_manager.get_config(ctx.guild.id)

        if not (tags := guild_config.get_tags_matching(name=name)):
            raise exceptions.EmbedError(
                colour=colours.RED,
                emoji=emojis.CROSS,
                description=f"There are no tags with the name **{name}**.")

        tag = tags[0]

        if tag.name != name:
            msg = f"Maybe you meant one of these?\n{values.NL.join(f'- **{tag.name}**' for tag in tags[0:])}" if len(
                tags) > 1 else ""
            raise exceptions.EmbedError(
                colour=colours.RED,
                emoji=emojis.CROSS,
                description=f"There are no tags with the name **{name}**. {msg}"
            )

        if tag.alias:
            tag = guild_config.get_tag(tag_id=tag.alias)

        await ctx.reply(discord.utils.escape_markdown(tag.content))

    @_tag.command(name="create", aliases=["make"])
    async def tag_create(self, ctx: custom.Context,
                         name: converters.TagNameConverter, *,
                         content: converters.TagContentConverter) -> None:
        """
        Creates a tag.
示例#7
0
文件: voice.py 项目: Axelancerr/Life
    async def skip(self, ctx: custom.Context, amount: int = 1) -> None:
        """
        Skips the current track.

        **amount**: The amount of tracks to skip, only works if you are the bot owner, guild owner, or have the manage guild, manage message, manage channels, kick members, or ban members permissions.
        """

        try:

            await commands.check_any(  # type: ignore
                checks.is_owner(),
                checks.is_guild_owner(),
                checks.has_any_permissions(manage_guild=True,
                                           manage_messages=True,
                                           manage_channels=True,
                                           kick_members=True,
                                           ban_members=True),
            ).predicate(ctx=ctx)

            if 0 <= amount > len(ctx.voice_client.queue) + 1:
                raise exceptions.EmbedError(
                    colour=colours.RED,
                    description=
                    f"There are not enough tracks in the queue to skip that many, try again with an amount between "
                    f"**1** and **{len(ctx.voice_client.queue) + 1}**.",
                )

            for _ in enumerate(ctx.voice_client.queue[:amount - 1]):
                ctx.voice_client.queue.get(put_history=False)

            await ctx.voice_client.stop()
            await ctx.reply(embed=utils.embed(
                colour=colours.GREEN,
                description=
                f"Skipped **{amount}** track{'s' if amount != 1 else ''}."))
            return

        except commands.CheckAnyFailure:

            if ctx.author.id == ctx.voice_client.current.requester.id:
                await ctx.voice_client.stop()
                await ctx.reply(
                    embed=utils.embed(colour=colours.GREEN,
                                      description="Skipped the current track.")
                )
                return

            if ctx.author not in ctx.voice_client.listeners:
                raise exceptions.EmbedError(
                    colour=colours.RED,
                    description=
                    "You can not vote to skip as you are currently deafened.",
                )

            skips_needed = math.floor(75 * len(ctx.voice_client.listeners) /
                                      100)

            if ctx.author.id not in ctx.voice_client.skip_request_ids:

                ctx.voice_client.skip_request_ids.add(ctx.author.id)

                if len(ctx.voice_client.skip_request_ids) < skips_needed:
                    embed = utils.embed(
                        colour=colours.GREEN,
                        description=
                        f"Added your vote to skip, currently on **{len(ctx.voice_client.skip_request_ids)}** out of **{skips_needed}** votes "
                        f"needed to skip.")
                    await ctx.reply(embed=embed)
                    return

                await ctx.voice_client.stop()
                await ctx.reply(
                    embed=utils.embed(colour=colours.GREEN,
                                      description="Skipped the current track.")
                )
                return

            ctx.voice_client.skip_request_ids.remove(ctx.author.id)
            await ctx.reply(embed=utils.embed(
                colour=colours.GREEN, description="Removed your vote to skip.")
                            )
示例#8
0
    async def embed_size(
        self,
        ctx: custom.Context,
        operation: Literal["set", "reset"] = utils.MISSING,
        size: Literal["large", "medium", "small"] = utils.MISSING,
    ) -> None:
        """
        Manage this servers embed size settings.

        **operation**: The operation to perform, can be **set** or **reset**.
        **size**: The size to set embeds too. Can be **large**, **medium** or **small**.
        """

        guild_config = await self.bot.guild_manager.get_config(ctx.guild.id)

        if not operation:
            await ctx.reply(embed=utils.embed(
                description=
                f"The embed size is **{guild_config.embed_size.name.title()}**."
            ))
            return

        try:
            await checks.is_mod().predicate(ctx=ctx)  # type: ignore
        except commands.CheckAnyFailure:
            raise exceptions.EmbedError(
                colour=colours.RED,
                emoji=emojis.CROSS,
                description=
                f"You do not have permission to edit the bots embed size in this server.",
            )

        if operation == "set":

            if not size:
                raise exceptions.EmbedError(
                    colour=colours.RED,
                    emoji=emojis.CROSS,
                    description=f"You didn't provide an embed size.")

            embed_size = getattr(enums.EmbedSize, size.upper())

            if guild_config.embed_size is embed_size:
                raise exceptions.EmbedError(
                    colour=colours.RED,
                    emoji=emojis.CROSS,
                    description=
                    f"The embed size is already **{embed_size.name.title()}**.",
                )

            await guild_config.set_embed_size(embed_size)

            await ctx.reply(embed=utils.embed(
                colour=colours.GREEN,
                emoji=emojis.TICK,
                description=
                f"Set the embed size to **{embed_size.name.title()}**."))

        elif operation == "reset":

            if guild_config.embed_size is enums.EmbedSize.MEDIUM:
                raise exceptions.EmbedError(
                    colour=colours.RED,
                    emoji=emojis.CROSS,
                    description=
                    f"The embed size is already the default of **Medium**.",
                )

            await guild_config.set_embed_size(enums.EmbedSize.MEDIUM)

            await ctx.reply(embed=utils.embed(
                colour=colours.GREEN,
                emoji=emojis.TICK,
                description=f"Reset the embed size to **Medium**."))
示例#9
0
    async def prefixes(
        self,
        ctx: custom.Context,
        operation: Literal["add", "remove", "reset", "clear"] = utils.MISSING,
        prefix: str = utils.MISSING,
    ) -> None:
        """
        Manage this servers prefix settings.

        **operation**: The operation to perform, can be **add**, **remove** or **reset**/**clear**.
        **prefix**: The prefix to add or remove. Must be less than 15 characters, and contain no backtick characters.
        """

        if not operation:
            prefixes = await self.bot.get_prefix(ctx.message)
            await ctx.paginate_embed(
                entries=[
                    f"`1.` {prefixes[0]}",
                    *(f"`{index + 2}.` `{prefix}`"
                      for index, prefix in enumerate(prefixes[2:])),
                ],
                per_page=10,
                title="List of usable prefixes.",
            )
            return

        try:
            await checks.is_mod().predicate(ctx=ctx)  # type: ignore
        except commands.CheckAnyFailure:
            raise exceptions.EmbedError(
                colour=colours.RED,
                emoji=emojis.CROSS,
                description=
                f"You do not have permission to edit the bots prefixes in this server.",
            )

        guild_config = await self.bot.guild_manager.get_config(ctx.guild.id)

        if operation == "add":

            if not prefix:
                raise exceptions.EmbedError(
                    colour=colours.RED,
                    emoji=emojis.CROSS,
                    description="You didn't provide a prefix to add.")
            if prefix in guild_config.prefixes:
                raise exceptions.EmbedError(
                    colour=colours.RED,
                    emoji=emojis.CROSS,
                    description=
                    f"This server already has the prefix **{prefix}**.")
            if len(guild_config.prefixes) > 20:
                raise exceptions.EmbedError(
                    colour=colours.RED,
                    emoji=emojis.CROSS,
                    description=
                    "This server can not have more than 20 custom prefixes.",
                )

            await guild_config.change_prefixes(prefix=prefix,
                                               operation=enums.Operation.ADD)

            await ctx.reply(embed=utils.embed(
                colour=colours.GREEN,
                emoji=emojis.TICK,
                description=f"Added **{prefix}** to this servers prefixes."))

        elif operation == "remove":

            if not prefix:
                raise exceptions.EmbedError(
                    colour=colours.RED,
                    emoji=emojis.CROSS,
                    description="You did not provide a prefix to remove.")
            if prefix not in guild_config.prefixes:
                raise exceptions.EmbedError(
                    colour=colours.RED,
                    emoji=emojis.CROSS,
                    description=
                    f"This server does not have the prefix **{prefix}**.")

            await guild_config.change_prefixes(
                prefix=prefix, operation=enums.Operation.REMOVE)

            await ctx.reply(embed=utils.embed(
                colour=colours.GREEN,
                emoji=emojis.TICK,
                description=f"Remove **{prefix}** from this servers prefixes.")
                            )

        elif operation in {"reset", "clear"}:

            if not guild_config.prefixes:
                raise exceptions.EmbedError(
                    colour=colours.RED,
                    emoji=emojis.CROSS,
                    description="This server does not have any custom prefixes."
                )

            await guild_config.change_prefixes(operation=enums.Operation.RESET)

            await ctx.reply(embed=utils.embed(
                colour=colours.GREEN,
                emoji=emojis.TICK,
                description=f"Cleared this servers prefixes."))
示例#10
0
                        description=
                        f"I did not recognise that timezone or user. Maybe you meant one of these?\n{msg}",
                    )
                else:
                    if (user_config := await self.bot.user_manager.get_config(
                            member.id
                    )).timezone_private is True and member.id != ctx.author.id:
                        raise exceptions.EmbedError(
                            colour=colours.RED,
                            emoji=emojis.CROSS,
                            description="That users timezone is private.")
                    found_timezone = user_config.timezone

        if not found_timezone:
            raise exceptions.EmbedError(
                colour=colours.RED,
                emoji=emojis.CROSS,
                description="That user has not set their timezone.")

        embed = discord.Embed(
            colour=colours.MAIN,
            title=
            f"Time in **{found_timezone.name}**{f' for **{member}**' if member else ''}:",
            description=
            f"```\n{utils.format_datetime(pendulum.now(tz=found_timezone))}\n```",
        )
        await ctx.reply(embed=embed)

    @commands.guild_only()
    @_timezone.command(name="card")
    async def _timezone_card(self, ctx: custom.Context) -> None:
        """
示例#11
0
文件: tag.py 项目: Axelancerr/Life
    async def convert(self, ctx: custom.Context, argument: str) -> str:

        if not (argument := (await commands.clean_content(escape_markdown=True).convert(ctx=ctx, argument=argument)).strip()):
            raise commands.BadArgument

        command: Any = ctx.bot.get_command("tag")

        if argument.split(" ")[0] in (names := command.all_commands.keys()):
            raise exceptions.EmbedError(
                colour=colours.RED,
                description=f"Tag names can not start with a tag subcommand name. ({', '.join(f'**{name}**' for name in names)})",
            )
        if len(argument) < 3 or len(argument) > 50:
            raise exceptions.EmbedError(
                colour=colours.RED,
                description="Tag names must be between 3 and 50 characters long."
            )

        return argument


class TagContentConverter(commands.Converter[str]):

    async def convert(self, ctx: custom.Context, argument: str) -> str:

        if not (argument := (await commands.clean_content(escape_markdown=True).convert(ctx=ctx, argument=argument)).strip()):
            raise commands.BadArgument

        if len(argument) > 1800:
            raise exceptions.EmbedError(
                colour=colours.RED,
示例#12
0
    async def choice(
        self,
        *,
        entries: list[Any],
        per_page: int,
        timeout: int = 300,
        delete_message: bool = True,
        codeblock: bool = False,
        splitter: str = "\n",
        header: str | None = None,
        footer: str | None = None,
        embed_footer_url: str | None = None,
        embed_footer: str | None = None,
        image: str | None = None,
        thumbnail: str | None = None,
        author: str | None = None,
        author_url: str | None = None,
        author_icon_url: str | None = None,
        title: str | None = None,
        url: str | None = None,
        colour: discord.Colour = colours.MAIN,
    ) -> int:

        if len(entries) == 1:
            return 0

        paginator = paginators.EmbedPaginator(
            ctx=self,
            entries=entries,
            per_page=per_page,
            timeout=timeout,
            delete_message=delete_message,
            codeblock=codeblock,
            splitter=splitter,
            header=header,
            footer=footer,
            embed_footer_url=embed_footer_url,
            embed_footer=embed_footer,
            image=image,
            thumbnail=thumbnail,
            author=author,
            author_url=author_url,
            author_icon_url=author_icon_url,
            title=title,
            url=url,
            colour=colour,
        )
        await paginator.paginate()

        for _ in range(5):

            try:
                response = await self.bot.wait_for(
                    "message",
                    check=lambda msg: msg.author.id == self.author.id and msg.
                    channel.id == self.channel.id,
                    timeout=30.0,
                )
            except asyncio.TimeoutError:
                raise exceptions.EmbedError(
                    colour=colours.RED,
                    emoji=emojis.CROSS,
                    description="You took too long to respond, try again.")

            if response.content == "cancel":
                break

            try:
                number = int(response.content) - 1
            except (ValueError, KeyError):
                embed = utils.embed(
                    colour=colours.RED,
                    emoji=emojis.CROSS,
                    description=
                    "That was not a valid choice, try again or send `cancel` to exit.",
                )
                await self.reply(embed=embed)
                continue

            await paginator.stop()
            return number

        raise exceptions.EmbedError(colour=colours.GREEN,
                                    emoji=emojis.TICK,
                                    description="Exiting choice selection.")
示例#13
0
""",
                                flags=re.VERBOSE)


class TimeConverter(commands.Converter[objects.Time]):
    async def convert(self, ctx: custom.Context,
                      argument: str) -> objects.Time:

        if (match := COLON_FORMAT_REGEX.match(argument)) or (
                match := HUMAN_FORMAT_REGEX.match(argument)):

            total = 0

            if hours := match.group("hours"):
                total += int(hours) * 60 * 60
            if minutes := match.group("minutes"):
                total += int(minutes) * 60
            if seconds := match.group("seconds"):
                total += int(seconds)

        else:

            try:
                total = int(argument)
            except ValueError:
                raise exceptions.EmbedError(
                    colour=colours.RED,
                    description="That time format was not recognized.")

        return objects.Time(seconds=total)