Skip to content

feat: Added support for emoji aliases like :smile: in PartialEmoji.from_str (redo) #2815

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

Lulalaby
Copy link
Member

Reverts #2814
Re-applies #2774

@Paillat-dev
Copy link
Contributor

Also this is not a fix but probably more a feat

@Lulalaby Lulalaby changed the title fix: support emoji aliases like :smile: in PartialEmoji.from_str (redo) feat: support emoji aliases like :smile: in PartialEmoji.from_str (redo) Jun 21, 2025
Co-authored-by: Paillat <[email protected]>
Signed-off-by: Lala Sabathil <[email protected]>
Lulalaby added 2 commits June 21, 2025 13:28
Signed-off-by: Lala Sabathil <[email protected]>
Signed-off-by: Lala Sabathil <[email protected]>
@Lulalaby Lulalaby changed the title feat: support emoji aliases like :smile: in PartialEmoji.from_str (redo) feat: Added support for emoji aliases like :smile: in PartialEmoji.from_str (redo) Jun 21, 2025
@Lulalaby Lulalaby requested a review from Paillat-dev June 21, 2025 11:29
@Paillat-dev
Copy link
Contributor

@Lulalaby pls add include discord/emojis.json to MANIFEST.in thyy

@Lumabots
Copy link
Contributor

Lumabots commented Jun 24, 2025

should i make a new pr or could we add to this pr the support unicode emoji in partial emoji converter ?
I also added a check for the unicode emoji since normally all unicode emoji supported by the partial should be inside the list that discord provide.

from discord.partial_emoji import EMOJIS_MAP
class PartialEmojiConverter(Converter[discord.PartialEmoji]):
    """Converts to a :class:`~discord.PartialEmoji`.

    This is done by extracting the animated flag, name, and ID for custom emojis,
    or by using the standard Unicode emojis supported by Discord.

    .. versionchanged:: 1.5
         Raise :exc:`.PartialEmojiConversionFailure` instead of generic :exc:`.BadArgument`
    """

    async def convert(self, ctx: Context, argument: str) -> discord.PartialEmoji:
        match = re.match(r"<(a?):(\w{1,32}):([0-9]{15,20})>$", argument)

        if match:
            emoji_animated = bool(match.group(1))
            emoji_name = match.group(2)
            emoji_id = int(match.group(3))

            return discord.PartialEmoji.with_state(
                ctx.bot._connection,
                animated=emoji_animated,
                name=emoji_name,
                id=emoji_id,
            )

        if argument in EMOJIS_MAP.values():
            return discord.PartialEmoji.with_state(
                ctx.bot._connection,
                animated=False,
                name=argument,
                id=None,
            )

        raise PartialEmojiConversionFailure(argument)

for the moment, only custom emoji are supported.
this should also fix #1582 for the partial emoji part

@Lulalaby
Copy link
Member Author

pr it to the branch

Signed-off-by: Lala Sabathil <[email protected]>
@Lumabots

This comment was marked as outdated.

Copy link
Contributor

@Paillat-dev Paillat-dev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested please someone else test it too

@Lumabots
Copy link
Contributor

pr it to the branch

so its rely on this pr (for the emoji custom map, so to be able to pr it i will first need this to be merged.
i cannot really suggest change here so i dont know what im supposed to do

@Lulalaby
Copy link
Member Author

MissionYozakuraGIF

You can just work based on this branch, and PR to this branch

@Lumabots
Copy link
Contributor

oups that's mb, i'm usually not able to pr directly on branch, but it might be different since you are a maintainer

* Update converter.py

* fix: enhance PartialEmojiConverter to support direct emoji names

* update doc
@Lulalaby
Copy link
Member Author

Pr changes 😂 I'm too dead

@Lumabots
Copy link
Contributor

im gonna sleep its 2am rn, but i'll check that tomorrow morning, if you have a more efficient way to check for the value feel free to share it

@Lumabots Lumabots mentioned this pull request Jun 25, 2025
9 tasks
Lumabots and others added 2 commits June 25, 2025 13:56
* Add Unicode emoji support to PartialEmojiConverter

PartialEmojiConverter now recognizes standard Unicode emojis using a new UNICODE_EMOJIS set loaded from emojis.json. The emoji mapping and set are moved to discord.utils for reuse, and references in partial_emoji.py are updated accordingly.

* style(pre-commit): auto fixes from pre-commit.com hooks

* Update converter.py

Signed-off-by: Lumouille <[email protected]>

* Update converter.py

* fix(utils): update UNICODE_EMOJIS to use values from EMOJIS_MAP

---------

Signed-off-by: Lumouille <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
* Add Unicode emoji support to PartialEmojiConverter

PartialEmojiConverter now recognizes standard Unicode emojis using a new UNICODE_EMOJIS set loaded from emojis.json. The emoji mapping and set are moved to discord.utils for reuse, and references in partial_emoji.py are updated accordingly.

* style(pre-commit): auto fixes from pre-commit.com hooks

* Update converter.py

Signed-off-by: Lumouille <[email protected]>

* Update converter.py

* fix(utils): update UNICODE_EMOJIS to use values from EMOJIS_MAP

* fix(partial_emoji): simplify emoji name extraction by using removeprefix and removesuffix

* style(pre-commit): auto fixes from pre-commit.com hooks

---------

Signed-off-by: Lumouille <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Signed-off-by: Lala Sabathil <[email protected]>
@Lulalaby Lulalaby requested a review from Paillat-dev June 26, 2025 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants