Skip to content

fix: support emoji aliases like :smile: in PartialEmoji.from_str #2774

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

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

Lumabots
Copy link

@Lumabots Lumabots commented May 2, 2025

Summary

Information

Checklist

  • I have searched the open pull requests for duplicates.
  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • If type: ignore comments were used, a comment is also left explaining why.
  • I have updated the changelog to include these changes.

@Lumabots Lumabots requested a review from a team as a code owner May 2, 2025 21:30
@pullapprove4 pullapprove4 bot requested a review from Middledot May 2, 2025 21:30
@Lumabots Lumabots changed the title Emoji fix: support emoji aliases like 😄 in PartialEmoji.from_str May 2, 2025
@Lumabots
Copy link
Author

Lumabots commented May 2, 2025

fix of #1582

@Lumabots
Copy link
Author

Lumabots commented May 2, 2025

so my current fix is using the emoji lib : https://pypi.org/project/emoji/
how should i do, just add this to the requirement txt ?

Signed-off-by: Lumouille <[email protected]>
@Lumabots Lumabots changed the title fix: support emoji aliases like 😄 in PartialEmoji.from_str fix: support emoji aliases like :smile: in PartialEmoji.from_str May 2, 2025
@Paillat-dev
Copy link
Contributor

@Lumabots What concerns me is that the emoji lib does not necessarily always include all of discord's nomenclature for markdown emojis. Notably, see this and this reddit threads.

Also, if this fixes #1582, please edit your pr description to add Fixes #1582 so that the pr is linked to the issue.

@Lumabots
Copy link
Author

Lumabots commented May 3, 2025

@Lumabots What concerns me is that the emoji lib does not necessarily always include all of discord's nomenclature for markdown emojis. Notably, see this and this reddit threads.

Also, if this fixes #1582, please edit your pr description to add Fixes #1582 so that the pr is linked to the issue.

I have been using this for years and I never really had any issue of missing emoji, but I'll try to do a test with every emoji of discord to see if there is lacking one.
Also in case there is lacking one do you have an alternative ?

@Lumabots
Copy link
Author

Lumabots commented May 3, 2025

Im thinking else I can do a json file with every discord emoji so I can just replace it

@Paillat-dev
Copy link
Contributor

@Lumabots dmed you on discord a huge json from discord with all the emojis. Maybe it can be helpful to you in some way ? Specifically the nameToEmoji and emoji keys (I think you can ignore the other two). However i am not sure storing a json like that in the lib is the best strategy.

@NeloBlivion
Copy link
Member

I'm not sure this is really ideal; users are expected to pass actual unicode emojis, not :name:

@Lumabots
Copy link
Author

Lumabots commented May 3, 2025

Lala added a bug tag in the related issue so I assumed it was

Lumabots added 2 commits May 4, 2025 02:09
Signed-off-by: Lumouille <[email protected]>
Signed-off-by: Lumouille <[email protected]>
@Lumabots
Copy link
Author

Lumabots commented May 3, 2025

should be ready for review using Paillait Lib dismoji

@Dorukyum
Copy link
Member

Dorukyum commented May 4, 2025

I'm strongly against adding a new dependency for this.

@Paillat-dev
Copy link
Contributor

Paillat-dev commented May 4, 2025

To be honest I agree that adding a dependency is not a good idea. To be clear, while this issue made me create that lib, I did not create it with the intent of it specifically be used in py-cord. Maybe a note should simply be added indicating to use a custom converter with a link to this pr &/ the issue.

An alternative could be to modify PartialEmoji to support storing an emoji exclusively based on a :some_emoji: string, however there wouldn't be anything to make sure that emoji is valid.

@Lumabots
Copy link
Author

Lumabots commented May 4, 2025

Why not just use ur system so we do a requests at first to get the emoji list from discord, and then just replace it directly ? So no need to install a new one

@Lumabots
Copy link
Author

Lumabots commented May 4, 2025

so i implemented a way to just download paillait file and then replace the emoji, i just need to find a way to load this file wihout blocking the bot. if you want to proceed differently tell me

@Paillat-dev
Copy link
Contributor

@Lumabots cor security reasons it is not possible to have it download at startup. Instead, you would need to download the file and store it next to the python code and load from there, and the file should be updated periodically.

To open the file you can use pathlib like this:

import json
from pathlib import Path

EMOJIS_MAP_PATH = Path(__file__).parent / "emojis.json"

with EMOJIS_MAP_PATH.open("r", encoding="utf-8") as f:
    EMOJIS_MAP = json.loads(f.read())

@Lumabots
Copy link
Author

Lumabots commented May 5, 2025

should be ready for review

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.

As long as including the json in the build is approved, this lgtm. However I have no idea wether there are some rules that would exclude it at build time so that should be verified.

Lumabots and others added 2 commits May 19, 2025 09:46
Co-authored-by: Paillat <[email protected]>
Signed-off-by: Lumouille <[email protected]>
@Lumabots Lumabots requested a review from Paillat-dev May 19, 2025 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

discord.Emoji and discord.PartialEmoji didn't work in slash option.
5 participants