From f7ca0bb726e8522d154f33dcf064d62b7ae53df3 Mon Sep 17 00:00:00 2001 From: MeiMei <30769358+mei23@users.noreply.github.com> Date: Mon, 24 Aug 2020 20:33:42 +0900 Subject: [PATCH] Better emoji parser (#56) * Better emoji parser * Remove yarn.lock --- package.json | 3 ++- src/modules/emoji-react/index.ts | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index bd1a166..977db3f 100644 --- a/package.json +++ b/package.json @@ -13,12 +13,12 @@ "@types/random-seed": "0.3.3", "@types/request-promise-native": "1.0.17", "@types/seedrandom": "2.4.28", + "@types/twemoji-parser": "12.1.0", "@types/uuid": "8.3.0", "@types/ws": "7.2.6", "autobind-decorator": "2.4.0", "canvas": "2.6.1", "chalk": "4.1.0", - "emoji-regex": "9.0.0", "lokijs": "1.5.11", "mecab-async": "0.1.2", "misskey-reversi": "0.0.5", @@ -30,6 +30,7 @@ "seedrandom": "3.0.5", "timeout-as-promise": "1.0.0", "ts-node": "9.0.0", + "twemoji-parser": "13.0.0", "typescript": "4.0.2", "uuid": "8.3.0", "ws": "7.3.1" diff --git a/src/modules/emoji-react/index.ts b/src/modules/emoji-react/index.ts index dd81fd7..3534589 100644 --- a/src/modules/emoji-react/index.ts +++ b/src/modules/emoji-react/index.ts @@ -1,5 +1,5 @@ import autobind from 'autobind-decorator'; -const emojiRegex = require('emoji-regex'); +import { parse } from 'twemoji-parser'; import { Note } from '../../misskey/note'; import Module from '../../module'; @@ -44,8 +44,8 @@ export default class extends Module { return react(customEmojis[0]); } - const emojis = note.text.match(emojiRegex()); - if (emojis) { + const emojis = parse(note.text).map(x => x.text); + if (emojis.length > 0) { // 絵文字が複数種類ある場合はキャンセル if (!emojis.every((val, i, arr) => val === arr[0])) return;