Skip to content

Commit 293c5ed

Browse files
Revert 2814 revert 2774 emoji (#2820)
* 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 <144063653+Lumabots@users.noreply.github.com> * Update converter.py * fix(utils): update UNICODE_EMOJIS to use values from EMOJIS_MAP --------- 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>
1 parent 3143637 commit 293c5ed

3 files changed

Lines changed: 15 additions & 12 deletions

File tree

discord/ext/commands/converter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
)
4242

4343
import discord
44-
from discord.partial_emoji import EMOJIS_MAP
44+
from discord.utils import UNICODE_EMOJIS
4545

4646
from .errors import *
4747

@@ -874,7 +874,7 @@ async def convert(self, ctx: Context, argument: str) -> discord.PartialEmoji:
874874
id=emoji_id,
875875
)
876876

877-
if argument in EMOJIS_MAP.values():
877+
if argument in UNICODE_EMOJIS:
878878
return discord.PartialEmoji.with_state(
879879
ctx.bot._connection,
880880
animated=False,

discord/partial_emoji.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,13 @@
2525

2626
from __future__ import annotations
2727

28-
import importlib.resources
29-
import json
3028
import re
3129
from typing import TYPE_CHECKING, Any, TypedDict, TypeVar
3230

3331
from . import utils
3432
from .asset import Asset, AssetMixin
3533
from .errors import InvalidArgument
3634

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-
4435
__all__ = ("PartialEmoji",)
4536

4637
if TYPE_CHECKING:
@@ -152,7 +143,7 @@ def from_str(cls: type[PE], value: str) -> PE:
152143
"""
153144
if value.startswith(":") and value.endswith(":") and len(value) > 2:
154145
name = value[1:-1]
155-
if unicode_emoji := EMOJIS_MAP.get(name):
146+
if unicode_emoji := utils.EMOJIS_MAP.get(name):
156147
return cls(name=unicode_emoji, id=None, animated=False)
157148
match = cls._CUSTOM_EMOJI_RE.match(value)
158149
if match is not None:

discord/utils.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import collections.abc
3131
import datetime
3232
import functools
33+
import importlib.resources
3334
import itertools
3435
import json
3536
import re
@@ -97,10 +98,21 @@
9798
"generate_snowflake",
9899
"basic_autocomplete",
99100
"filter_params",
101+
"EMOJIS_MAP",
102+
"UNICODE_EMOJIS",
100103
)
101104

102105
DISCORD_EPOCH = 1420070400000
103106

107+
with (
108+
importlib.resources.files(__package__)
109+
.joinpath("emojis.json")
110+
.open(encoding="utf-8") as f
111+
):
112+
EMOJIS_MAP = json.load(f)
113+
114+
UNICODE_EMOJIS = set(EMOJIS_MAP.values())
115+
104116

105117
class _MissingSentinel:
106118
def __eq__(self, other) -> bool:

0 commit comments

Comments
 (0)