Skip to content

Commit 735673b

Browse files
Lumabotspre-commit-ci[bot]plun1331Paillat-devLulalaby
authored
fix: support emoji aliases like :smile: in PartialEmoji.from_str (#2774)
* handle emoji_lib Signed-off-by: Lumouille <[email protected]> * style(pre-commit): auto fixes from pre-commit.com hooks * Update CHANGELOG.md Signed-off-by: Lumouille <[email protected]> * usage of dismoji Signed-off-by: Lumouille <[email protected]> * Update _.txt Signed-off-by: Lumouille <[email protected]> * removal of dismoji Signed-off-by: Lumouille <[email protected]> * Update _.txt Signed-off-by: Lumouille <[email protected]> * style(pre-commit): auto fixes from pre-commit.com hooks * NEED HELP Signed-off-by: Lumouille <[email protected]> * style(pre-commit): auto fixes from pre-commit.com hooks * Update partial_emoji.py Signed-off-by: Lumouille <[email protected]> * style(pre-commit): auto fixes from pre-commit.com hooks * Add files via upload Signed-off-by: Lumouille <[email protected]> * style(pre-commit): auto fixes from pre-commit.com hooks * Update partial_emoji.py Signed-off-by: Lumouille <[email protected]> * Update discord/partial_emoji.py Co-authored-by: plun1331 <[email protected]> Signed-off-by: Lumouille <[email protected]> * 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 <[email protected]> Signed-off-by: Lumouille <[email protected]> * reduce emoji.json weight * Update emojis.json Signed-off-by: Lumouille <[email protected]> * refactor: replace Path with importlib.resources for loading emojis.json * Update emojis.json Signed-off-by: Lumouille <[email protected]> --------- Signed-off-by: Lumouille <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: plun1331 <[email protected]> Co-authored-by: Paillat <[email protected]> Co-authored-by: Lala Sabathil <[email protected]>
1 parent 8e97cb5 commit 735673b

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ These changes are available on the `master` branch, but have not yet been releas
113113
([#2761](https://github.com/Pycord-Development/pycord/pull/2761))
114114
- Updated `valid_locales` to support `in` and `es-419`.
115115
([#2767](https://github.com/Pycord-Development/pycord/pull/2767))
116+
- Fixed support emoji aliases like `:smile:` in PartialEmoji.from_str.
117+
([#2774](https://github.com/Pycord-Development/pycord/pull/2774))
116118
- Fixed `Webhook.edit` not working with `attachments=[]`.
117119
([#2779](https://github.com/Pycord-Development/pycord/pull/2779))
118120
- Fixed GIF-based `Sticker` returning the wrong `url`.

discord/emojis.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

discord/partial_emoji.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,22 @@
2525

2626
from __future__ import annotations
2727

28+
import importlib.resources
29+
import json
2830
import re
2931
from typing import TYPE_CHECKING, Any, TypedDict, TypeVar
3032

3133
from . import utils
3234
from .asset import Asset, AssetMixin
3335
from .errors import InvalidArgument
3436

37+
with (
38+
importlib.resources.files(__package__)
39+
.joinpath("emojis.json")
40+
.open(encoding="utf-8") as f
41+
):
42+
EMOJIS_MAP = json.load(f)
43+
3544
__all__ = ("PartialEmoji",)
3645

3746
if TYPE_CHECKING:
@@ -127,7 +136,7 @@ def from_str(cls: type[PE], value: str) -> PE:
127136
- ``name:id``
128137
- ``<:name:id>``
129138
130-
If the format does not match then it is assumed to be a unicode emoji.
139+
If the format does not match then it is assumed to be a unicode emoji, either as Unicode characters or as a Discord alias (``:smile:``).
131140
132141
.. versionadded:: 2.0
133142
@@ -141,6 +150,12 @@ def from_str(cls: type[PE], value: str) -> PE:
141150
:class:`PartialEmoji`
142151
The partial emoji from this string.
143152
"""
153+
if value.startswith(":") and value.endswith(":"):
154+
name = value[1:-1]
155+
unicode_emoji = EMOJIS_MAP.get(name)
156+
if unicode_emoji:
157+
return cls(name=unicode_emoji, id=None, animated=False)
158+
144159
match = cls._CUSTOM_EMOJI_RE.match(value)
145160
if match is not None:
146161
groups = match.groupdict()

0 commit comments

Comments
 (0)