fix: support emoji aliases like `:smile:` in PartialEmoji.from_str
Summary
Information
- [x] This PR fixes an issue. Fixes #1582
- [ ] This PR adds something new (e.g. new method or parameters).
- [ ] This PR is a breaking change (e.g. methods or parameters removed/renamed).
- [ ] This PR is not a code change (e.g. documentation, README, typehinting, examples, ...).
Checklist
- [x] I have searched the open pull requests for duplicates.
- [x] If code changes were made then they have been tested.
- [x] I have updated the documentation to reflect the changes.
- [x] If
type: ignorecomments were used, a comment is also left explaining why. - [x] I have updated the changelog to include these changes.
fix of #1582
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 ?
@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 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 #1582so 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 ?
Im thinking else I can do a json file with every discord emoji so I can just replace it
@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.
I'm not sure this is really ideal; users are expected to pass actual unicode emojis, not :name:
Lala added a bug tag in the related issue so I assumed it was
should be ready for review using Paillait Lib dismoji
I'm strongly against adding a new dependency for this.
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.
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
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
@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())
should be ready for review
We'd have to maintain this huge json of emojis. It also just makes the package larger.
i managed to drop it to 250kb, so i think the size is no longer an issue, i dont think maintain it is gonna be an issue, paillat create a script to get all of that data, and discord does not upload new emojis often
If the issue is updating the blob I can handle that every 6 months when it's needed, ~~and if the issue is the size, maybe @Lumabots try preprocessing the json to see if you can make it even smaller (generate the name to surrogates and use that as json directly)~~
it as been tested and it works
@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 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)
@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