Skip to content

PyDrocsid.converter

Color

Bases: Converter[int]

Color converter which also supports hex codes.

Source code in PyDrocsid/converter.py
32
33
34
35
36
37
38
39
40
41
42
43
class Color(Converter[int]):
    """Color converter which also supports hex codes."""

    async def convert(self, ctx: Context[Bot], argument: str) -> int:
        try:
            return (await ColorConverter().convert(ctx, argument)).value
        except BadArgument:
            pass

        if not re.match(r"^[0-9a-fA-F]{6}$", argument):
            raise BadArgument(t.invalid_color)
        return int(argument, 16)

EmojiConverter

Bases: PartialEmojiConverter

Emoji converter which also supports unicode emojis.

Source code in PyDrocsid/converter.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class EmojiConverter(PartialEmojiConverter):
    """Emoji converter which also supports unicode emojis."""

    async def convert(self, ctx: Context[Bot], argument: str) -> PartialEmoji:
        try:
            return await super().convert(ctx, argument)
        except BadArgument:
            pass

        if argument not in emoji_to_name:
            raise BadArgument

        connection = ctx.bot._connection  # noqa
        return PartialEmoji.with_state(connection, animated=False, name=argument, id=None)

UserMemberConverter

Bases: Converter[User | Member]

Return a member or user object depending on whether the user is currently a guild member.

Source code in PyDrocsid/converter.py
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class UserMemberConverter(Converter[User | Member]):
    """Return a member or user object depending on whether the user is currently a guild member."""

    async def convert(self, ctx: Context[Bot], argument: str) -> User | Member:
        guild: Guild = ctx.bot.guilds[0]

        if not (match := re.match(r"^(<@!?)?([0-9]{15,20})(?(1)>)$", argument)):
            raise BadArgument(t.user_not_found)

        # find user/member by id
        user_id: int = int(match.group(2))
        if member := guild.get_member(user_id):
            return member
        try:
            return await ctx.bot.fetch_user(user_id)
        except (NotFound, HTTPException):
            raise BadArgument(t.user_not_found)