From 81349e8d43e5f396879ebbba752a50259423771d Mon Sep 17 00:00:00 2001 From: Jonathan Zhang Date: Sat, 24 Apr 2021 19:40:44 -0700 Subject: [PATCH 1/9] fix emoji with zwj handling --- ircbot/plugin/wide.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ircbot/plugin/wide.py b/ircbot/plugin/wide.py index 0e5e71f..8192285 100644 --- a/ircbot/plugin/wide.py +++ b/ircbot/plugin/wide.py @@ -60,6 +60,13 @@ def get_text(bot, msg): return text.strip() +def is_emoji(c): + if ord(c) in range(0x1f300, 0x1fadf): + return True + else: + return False + + def widetextify(bot, msg, width, translation=WIDETEXT_MAP): """welcome to the ocf @@ -71,5 +78,5 @@ def widetextify(bot, msg, width, translation=WIDETEXT_MAP): text = get_text(bot, msg) if text: - response = (c.translate(translation) + WIDE_SPACE_CHAR * width for c in text) + response = (c.translate(translation) + WIDE_SPACE_CHAR * width if ord(c) is not 0x200d and not is_emoji(c) else c for c in text) msg.respond(''.join(response), ping=False) From 3e4688e1e3c9e8df4a7b6c6c2391a1f7759d244b Mon Sep 17 00:00:00 2001 From: Jonathan Zhang Date: Sat, 24 Apr 2021 20:15:31 -0700 Subject: [PATCH 2/9] rework --- ircbot/plugin/wide.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ircbot/plugin/wide.py b/ircbot/plugin/wide.py index 8192285..7f792ba 100644 --- a/ircbot/plugin/wide.py +++ b/ircbot/plugin/wide.py @@ -61,7 +61,7 @@ def get_text(bot, msg): return text.strip() def is_emoji(c): - if ord(c) in range(0x1f300, 0x1fadf): + if ord(c) in range(0x1f300, 0x1fadf) or ord(c) in range(0x2700, 0x27bf): return True else: return False @@ -76,7 +76,19 @@ def widetextify(bot, msg, width, translation=WIDETEXT_MAP): message in the channel. """ text = get_text(bot, msg) - + response = '' + char_is_emoji = False if text: - response = (c.translate(translation) + WIDE_SPACE_CHAR * width if ord(c) is not 0x200d and not is_emoji(c) else c for c in text) + + for i in range(len(text)): + if is_emoji(text[i]) and i < len(text): + if ord(text[i + 1]) == 0x200d or ord(text[i + 1]) == 0xfe0f: + response += text[i] + else: + response += text[i] + WIDE_SPACE_CHAR * width + elif text[i] == 0x200d: + response += text[i] + else: + response += text[i] + WIDE_SPACE_CHAR * width + msg.respond(''.join(response), ping=False) From 8c5a061f686fdb1e1ab09f62216d95008c53b1ff Mon Sep 17 00:00:00 2001 From: Jonathan Zhang Date: Sat, 24 Apr 2021 20:16:57 -0700 Subject: [PATCH 3/9] missed ord --- ircbot/plugin/wide.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ircbot/plugin/wide.py b/ircbot/plugin/wide.py index 7f792ba..00bb09c 100644 --- a/ircbot/plugin/wide.py +++ b/ircbot/plugin/wide.py @@ -86,7 +86,7 @@ def widetextify(bot, msg, width, translation=WIDETEXT_MAP): response += text[i] else: response += text[i] + WIDE_SPACE_CHAR * width - elif text[i] == 0x200d: + elif ord(text[i]) == 0x200d: response += text[i] else: response += text[i] + WIDE_SPACE_CHAR * width From 5b291f711650aca900e125f011a6678f98cb3e97 Mon Sep 17 00:00:00 2001 From: Jonathan Zhang Date: Sat, 24 Apr 2021 20:17:44 -0700 Subject: [PATCH 4/9] oops --- ircbot/plugin/wide.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ircbot/plugin/wide.py b/ircbot/plugin/wide.py index 00bb09c..c10d149 100644 --- a/ircbot/plugin/wide.py +++ b/ircbot/plugin/wide.py @@ -81,7 +81,7 @@ def widetextify(bot, msg, width, translation=WIDETEXT_MAP): if text: for i in range(len(text)): - if is_emoji(text[i]) and i < len(text): + if is_emoji(text[i]) and i < len(text) - 1: if ord(text[i + 1]) == 0x200d or ord(text[i + 1]) == 0xfe0f: response += text[i] else: From e0d5a6b6dacce3d7fb2b7ac326e9913b03b59537 Mon Sep 17 00:00:00 2001 From: Jonathan Zhang Date: Sat, 24 Apr 2021 20:20:24 -0700 Subject: [PATCH 5/9] oops --- ircbot/plugin/wide.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ircbot/plugin/wide.py b/ircbot/plugin/wide.py index c10d149..72a4ca3 100644 --- a/ircbot/plugin/wide.py +++ b/ircbot/plugin/wide.py @@ -89,6 +89,6 @@ def widetextify(bot, msg, width, translation=WIDETEXT_MAP): elif ord(text[i]) == 0x200d: response += text[i] else: - response += text[i] + WIDE_SPACE_CHAR * width + response += c.translate(translation) + WIDE_SPACE_CHAR * width msg.respond(''.join(response), ping=False) From fe62a4ae5155fb18a44ace2511e8a078f342750f Mon Sep 17 00:00:00 2001 From: Jonathan Zhang Date: Sat, 24 Apr 2021 20:20:55 -0700 Subject: [PATCH 6/9] oooops --- ircbot/plugin/wide.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ircbot/plugin/wide.py b/ircbot/plugin/wide.py index 72a4ca3..d4e05b2 100644 --- a/ircbot/plugin/wide.py +++ b/ircbot/plugin/wide.py @@ -89,6 +89,6 @@ def widetextify(bot, msg, width, translation=WIDETEXT_MAP): elif ord(text[i]) == 0x200d: response += text[i] else: - response += c.translate(translation) + WIDE_SPACE_CHAR * width + response += text[i].translate(translation) + WIDE_SPACE_CHAR * width msg.respond(''.join(response), ping=False) From cf289091b3146ad09ed241ad5021a885cce19158 Mon Sep 17 00:00:00 2001 From: Jonathan Zhang Date: Sat, 24 Apr 2021 20:24:29 -0700 Subject: [PATCH 7/9] cleanup --- ircbot/plugin/wide.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/ircbot/plugin/wide.py b/ircbot/plugin/wide.py index d4e05b2..dd52da1 100644 --- a/ircbot/plugin/wide.py +++ b/ircbot/plugin/wide.py @@ -77,9 +77,7 @@ def widetextify(bot, msg, width, translation=WIDETEXT_MAP): """ text = get_text(bot, msg) response = '' - char_is_emoji = False if text: - for i in range(len(text)): if is_emoji(text[i]) and i < len(text) - 1: if ord(text[i + 1]) == 0x200d or ord(text[i + 1]) == 0xfe0f: From 8e60b2e92b0e8058348fe311f2d99c66fc1be61f Mon Sep 17 00:00:00 2001 From: Jonathan Zhang Date: Sat, 24 Apr 2021 20:32:21 -0700 Subject: [PATCH 8/9] consistency --- ircbot/plugin/wide.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ircbot/plugin/wide.py b/ircbot/plugin/wide.py index dd52da1..ed1052f 100644 --- a/ircbot/plugin/wide.py +++ b/ircbot/plugin/wide.py @@ -84,7 +84,7 @@ def widetextify(bot, msg, width, translation=WIDETEXT_MAP): response += text[i] else: response += text[i] + WIDE_SPACE_CHAR * width - elif ord(text[i]) == 0x200d: + elif ord(text[i]) == 0x200d and i < len(text) - 1: response += text[i] else: response += text[i].translate(translation) + WIDE_SPACE_CHAR * width From 5bdeca53c9c2fdef26e84fd107a141519dba20fb Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 25 Apr 2021 03:36:38 +0000 Subject: [PATCH 9/9] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- ircbot/plugin/wide.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ircbot/plugin/wide.py b/ircbot/plugin/wide.py index ed1052f..4f4d0ac 100644 --- a/ircbot/plugin/wide.py +++ b/ircbot/plugin/wide.py @@ -60,6 +60,7 @@ def get_text(bot, msg): return text.strip() + def is_emoji(c): if ord(c) in range(0x1f300, 0x1fadf) or ord(c) in range(0x2700, 0x27bf): return True @@ -67,7 +68,6 @@ def is_emoji(c): return False - def widetextify(bot, msg, width, translation=WIDETEXT_MAP): """welcome to the ocf @@ -85,8 +85,8 @@ def widetextify(bot, msg, width, translation=WIDETEXT_MAP): else: response += text[i] + WIDE_SPACE_CHAR * width elif ord(text[i]) == 0x200d and i < len(text) - 1: - response += text[i] + response += text[i] else: - response += text[i].translate(translation) + WIDE_SPACE_CHAR * width + response += text[i].translate(translation) + WIDE_SPACE_CHAR * width msg.respond(''.join(response), ping=False)