8000 fix: support emoji aliases like `:smile:` in PartialEmoji.from_str by Lumabots · Pull Request #2774 · Pycord-Development/pycord · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
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

Merged
merged 27 commits into from
Jun 20, 2025

Conversation

Lumabots
Copy link
Contributor
@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 and others added 2 commits May 3, 2025 00:27
Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>
@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
Contributor Author
Lumabots commented May 2, 2025

fix of #1582

@Lumabots
Copy link
Contributor 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 <144063653+Lumabots@users.noreply.github.com>
@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
Contributor 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
Contributor 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
Contributor 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 <144063653+Lumabots@users.noreply.github.com>
Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>
@Lumabots
Copy link
Contributor 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
Contributor 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 and others added 5 commits May 4, 2025 17:51
Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>
Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>
Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>
@Lumabots
Copy link
Contributor 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())

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.

Lgtm as long as its tested and works

@Lumabots
Copy link
Contributor Author

it as been tested and it works

Lulalaby
Lulalaby previously approved these changes Jun 19, 2025
Copy link
Member
@Lulalaby Lulalaby left a comment

Choose a reason for hiding this comment

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

@Paillat-dev can u review again

@Paillat-dev
Copy link
Contributor

@Lumabots The emoji json was updated, do you mind re-creating it with the updated data ? Also if you're using a script to convert the json feel free to send it here for future reference, thx !

@Lumabots
Copy link
Contributor Author

@Lumabots The emoji json was updated, do you mind re-creating it with the updated data ? Also if you're using a script to convert the json feel free to send it here for future reference, thx !

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:
    data = json.load(f)

EMOJIS_MAP = {}
for emoji_entry in data["emojis"]:
    for name in emoji_entry["names"]:
        EMOJIS_MAP[name] = emoji_entry["surrogates"]

with open("emojis.json", "w", encoding="utf-8") as f:
    json.dump(EMOJIS_MAP, f, ensure_ascii=False)

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.

@Lumabots please also recreate the emoji file, discord changed some emojis, other than that I think we're gtg

@Lumabots
Copy link
Contributor Author
Lumabots commented Jun 20, 2025

@Lumabots please also recreate the emoji file, discord changed some emojis, other than that I think we're gtg

again ? i already change it yesterday
done

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>
@Lulalaby Lulalaby dismissed stale reviews from Dorukyum and plun1331 June 20, 2025 12:36

Outdated

@Lulalaby Lulalaby enabled auto-merge (squash) June 20, 2025 12:37
@Lulalaby Lulalaby removed the request for review from Middledot June 20, 2025 12:37
@Lulalaby Lulalaby merged commit 735673b into Pycord-Development:master Jun 20, 2025
28 checks passed
@Lumabots Lumabots deleted the emoji branch June 20, 2025 15:24
VincentRPS pushed a commit to Pycord-Test/pycord that referenced this pull request Jun 28, 2025
* fix: Role Edit TypeHint (Pycord-Development#2795)

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* fix: command syncing edge cases (Pycord-Development#2797)

* change default nsfw to false

* cl

* localizations

* :=

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

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* fix: VoiceClient crashes while receiving audio (Pycord-Development#2800)


Signed-off-by: Hema2 <49586027+Hema2-official@users.noreply.github.com>
Co-authored-by: Lala Sabathil <lala@pycord.dev>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* chore(deps): bump typing-extensions from 4.13.1 to 4.13.2 in the patch-version-bumps group (Pycord-Development#2783)

chore(deps): bump typing-extensions in the patch-version-bumps group

Bumps the patch-version-bumps group with 1 update: [typing-extensions](https://github.com/python/typing_extensions).


Updates `typing-extensions` from 4.13.1 to 4.13.2
- [Release notes](https://github.com/python/typing_extensions/releases)
- [Changelog](https://github.com/python/typing_extensions/blob/main/CHANGELOG.md)
- [Commits](python/typing_extensions@4.13.1...4.13.2)

---
updated-dependencies:
- dependency-name: typing-extensions
  dependency-version: 4.13.2
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: patch-version-bumps
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* feat: add created_at property to Interaction (Pycord-Development#2801)

* feat: add created_at property to Interaction for message creation time

* Update CHANGELOG.md

* Update discord/interactions.py

Co-authored-by: UK <41271523+NeloBlivion@users.noreply.github.com>
Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* Update CHANGELOG.md

Co-authored-by: DA344 <108473820+DA-344@users.noreply.github.com>
Signed-off-by: Lala Sabathil <aiko@aitsys.dev>

---------

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>
Signed-off-by: Lala Sabathil <aiko@aitsys.dev>
Co-authored-by: UK <41271523+NeloBlivion@users.noreply.github.com>
Co-authored-by: Lala Sabathil <aiko@aitsys.dev>
Co-authored-by: DA344 <108473820+DA-344@users.noreply.github.com>

* chore(deps): update setuptools requirement from <=78.1.0,>=62.6 to >=62.6,<=80.8.0 (Pycord-Development#2786)

chore(deps): update setuptools requirement

Updates the requirements on [setuptools](https://github.com/pypa/setuptools) to permit the latest version.
- [Release notes](https://github.com/pypa/setuptools/releases)
- [Changelog](https://github.com/pypa/setuptools/blob/main/NEWS.rst)
- [Commits](pypa/setuptools@v72.2.0...v80.8.0)

---
updated-dependencies:
- dependency-name: setuptools
  dependency-version: 80.8.0
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore!: 🔥 Remove deprecated support for Option in bridge commands (Pycord-Development#2731)

* 🔥 Remove deprecated support for Option in bridge commands

* 📝 CHANGELOG.md

* ♻️ Better logic

---------

Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>

* fix: 🐛 `TypeError` when specifying `thread_name` in Webhook.send (Pycord-Development#2761)

* 🐛 Handle `thread_name` in `handle_message_parameters` to allow sending to thread with multipart

* 📝 CHANGELOG.md

* Update CHANGELOG.md

Co-authored-by: plun1331 <plun1331@gmail.com>
Signed-off-by: Paillat <jeremiecotti@ik.me>

---------

Signed-off-by: Paillat <me@paillat.dev>
Signed-off-by: Paillat <jeremiecotti@ik.me>
Co-authored-by: plun1331 <plun1331@gmail.com>
Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>

* fix: add BanEntry to __all__ exports in guild.py (Pycord-Development#2798)

* fix: add BanEntry to __all__ exports in guild.py

* Hold on

Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>

---------

Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>

* fix: correct generic return type in component utils (Pycord-Development#2796)

* Update CHANGELOG.md

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* sync with pycord

* fix: update Item type hints to Item[View] in view.py

* fix: update Item type hints to use TypeVar[V] in view.py

---------

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>
Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>

* chore(deps): update setuptools-scm requirement from <=8.2.1,>=6.2 to >=6.2,<=8.3.1 (Pycord-Development#2785)

chore(deps): update setuptools-scm requirement

Updates the requirements on [setuptools-scm](https://github.com/pypa/setuptools-scm) to permit the latest version.
- [Release notes](https://github.com/pypa/setuptools-scm/releases)
- [Changelog](https://github.com/pypa/setuptools-scm/blob/main/CHANGELOG.md)
- [Commits](pypa/setuptools-scm@v8.1.0...v8.3.1)

---
updated-dependencies:
- dependency-name: setuptools-scm
  dependency-version: 8.3.1
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(deps-dev): update pylint requirement from ~=3.3.6 to ~=3.3.7 (Pycord-Development#2784)

Updates the requirements on [pylint](https://github.com/pylint-dev/pylint) to permit the latest version.
- [Release notes](https://github.com/pylint-dev/pylint/releases)
- [Commits](pylint-dev/pylint@v3.3.6...v3.3.7)

---
updated-dependencies:
- dependency-name: pylint
  dependency-version: 3.3.7
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore(pre-commit): pre-commit autoupdate (Pycord-Development#2792)

updates:
- [github.com/asottile/pyupgrade: v3.19.1 → v3.20.0](asottile/pyupgrade@v3.19.1...v3.20.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* docs: 📝 Fix malformed CHANGELOG.md hyperlinks (Pycord-Development#2804)

:memo: Fix CHANGELOG.md formatting

* fix: :bug: Fix `ValueError` when using `Flag` (Pycord-Development#2759)

* 🐛 Fix `dataclasses.field` can't be reused

* 📝 CHANGELOG.md

* Update CHANGELOG.md

Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>

* ♻️ Move `_missing_field_factory` to flags.py and remove incorrect comment

---------

Signed-off-by: Paillat <me@paillat.dev>
Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>

* ci(deps): bump crowdin/github-action from 2.7.0 to 2.7.1 in the patch-version-bumps group (Pycord-Development#2805)

ci(deps): bump crowdin/github-action in the patch-version-bumps group

Bumps the patch-version-bumps group with 1 update: [crowdin/github-action](https://github.com/crowdin/github-action).


Updates `crowdin/github-action` from 2.7.0 to 2.7.1
- [Release notes](https://github.com/crowdin/github-action/releases)
- [Commits](crowdin/github-action@v2.7.0...v2.7.1)

---
updated-dependencies:
- dependency-name: crowdin/github-action
  dependency-version: 2.7.1
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: patch-version-bumps
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* fix: resolve regex library warnings (Pycord-Development#2807)

Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>

* fix: support emoji aliases like `:smile:` in PartialEmoji.from_str (Pycord-Development#2774)

* handle emoji_lib

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

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

* Update CHANGELOG.md

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* usage of dismoji

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* Update _.txt

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* removal of dismoji

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* Update _.txt

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

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

* NEED HELP 

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

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

* Update partial_emoji.py

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

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

* Add files via upload

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

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

* Update partial_emoji.py

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* Update discord/partial_emoji.py

Co-authored-by: plun1331 <plun1331@gmail.com>
Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* feature(partial_emoji): support :name: and name

* fix(partial_emoji): remove unnecessary data variable after processing emojis

* Update partial_emoji.py

Co-authored-by: Paillat <jeremiecotti@ik.me>
Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* reduce emoji.json weight

* Update emojis.json

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

* refactor: replace Path with importlib.resources for loading emojis.json

* Update emojis.json

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>

---------

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: plun1331 <plun1331@gmail.com>
Co-authored-by: Paillat <jeremiecotti@ik.me>
Co-authored-by: Lala Sabathil <lala@pycord.dev>

* Revert "fix: support emoji aliases like `😄` in PartialEmoji.from_str" (Pycord-Development#2814)

Revert "fix: support emoji aliases like `:smile:` in PartialEmoji.from_str (#…"

This reverts commit 735673b.

* Apply suggestions from code review

Signed-off-by: Paillat <jeremiecotti@ik.me>

* Update discord/utils.py

Signed-off-by: Paillat <jeremiecotti@ik.me>

* Update discord/utils.py

Signed-off-by: Paillat <jeremiecotti@ik.me>

* Update discord/ext/commands/flags.py

Signed-off-by: Paillat <jeremiecotti@ik.me>

* 🚨 Fix linter warnings

---------

Signed-off-by: Lumouille <144063653+Lumabots@users.noreply.github.com>
Signed-off-by: Hema2 <49586027+Hema2-official@users.noreply.github.com>
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Lala Sabathil <aiko@aitsys.dev>
Signed-off-by: Paillat <me@paillat.dev>
Signed-off-by: Paillat <jeremiecotti@ik.me>
Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Co-authored-by: Lumouille <144063653+Lumabots@users.noreply.github.com>
Co-authored-by: UK <41271523+NeloBlivion@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Hema2 <49586027+Hema2-official@users.noreply.github.com>
Co-authored-by: Lala Sabathil <lala@pycord.dev>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Lala Sabathil <aiko@aitsys.dev>
Co-authored-by: DA344 <108473820+DA-344@users.noreply.github.com>
Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
Co-authored-by: plun1331 <plun1331@gmail.com>
Co-authored-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
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.

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