diff --git a/gateway_xmpp/__init__.py b/gateway_xmpp/__init__.py index 79abe3f..1f520f1 100644 --- a/gateway_xmpp/__init__.py +++ b/gateway_xmpp/__init__.py @@ -6,6 +6,9 @@ from slixmpp.types import PresenceArgs import slixmpp.stanza import slixmpp.plugins.xep_0084.stanza import base64, time +NON_BMP_RE = re.compile(u"[^\U00000000-\U0000d7ff\U0000e000-\U0000ffff]", flags=re.UNICODE) +def non_bmp(s): + return NON_BMP_RE.sub(u'', s) class GatewayXMPP(ComponentXMPP): def __init__(self, plexus, settings, gateway_name, gateway_data): @@ -60,6 +63,8 @@ class GatewayXMPP(ComponentXMPP): # Ignore ours return + nick_name = non_bmp(nick_name) + puppet_data = { "identification": identification, "jid": f"{hashlib.sha256(str(identification).encode()).hexdigest()[:24]}@{self.pfrom}/mirror", @@ -113,6 +118,7 @@ class GatewayXMPP(ComponentXMPP): puppet_data["queue"].append(queue_callback) # If the user changed their nickname, try to update it on the puppet + nick_name = non_bmp(nick_name) if nick_name != puppet_data["nicknames"][muc_jid]["nick"]: assert puppet_data["nicknames"][muc_jid]["state"] == "joined" puppet_data["nicknames"][muc_jid]["state"] = "joining"