mirror of
https://github.com/thelounge/thelounge.git
synced 2026-03-14 14:35:50 +01:00
Use @github's emoji data
This commit is contained in:
parent
9949fa9963
commit
b95c8236bd
5 changed files with 3344 additions and 4511 deletions
|
|
@ -3,36 +3,18 @@
|
|||
const got = require("got");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const fuzzy = require("fuzzy");
|
||||
|
||||
(async () => {
|
||||
const response = await got("https://raw.githubusercontent.com/emojione/emojione/master/extras/alpha-codes/eac.json");
|
||||
const response = await got("https://raw.githubusercontent.com/github/gemoji/master/db/emoji.json");
|
||||
const emojiStrategy = JSON.parse(response.body);
|
||||
const emojiMap = {};
|
||||
const fullNameEmojiMap = {};
|
||||
|
||||
for (const key in emojiStrategy) {
|
||||
if (emojiStrategy.hasOwnProperty(key)) {
|
||||
const shortname = prepareShortName(emojiStrategy[key].alpha_code);
|
||||
const unicode = stringToUnicode(emojiStrategy[key].output);
|
||||
fullNameEmojiMap[unicode] = emojiStrategy[key].name;
|
||||
for (const emoji of emojiStrategy) {
|
||||
fullNameEmojiMap[emoji.emoji] = emoji.description;
|
||||
|
||||
// Skip tones, at least for now
|
||||
if (shortname.includes("tone")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
emojiMap[shortname] = unicode;
|
||||
|
||||
for (let alternative of emojiStrategy[key].aliases.split("|")) {
|
||||
alternative = prepareShortName(alternative);
|
||||
|
||||
if (fuzzy.test(shortname, alternative) || fuzzy.test(alternative, shortname)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
emojiMap[alternative] = unicode;
|
||||
}
|
||||
for (const alias of emoji.aliases) {
|
||||
emojiMap[alias] = emoji.emoji;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -57,24 +39,3 @@ const fuzzy = require("fuzzy");
|
|||
"fullnamemap.json"
|
||||
)), fullNameEmojiMapOutput);
|
||||
})();
|
||||
|
||||
function stringToUnicode(key) {
|
||||
return key
|
||||
.split("-")
|
||||
.map((c) => String.fromCodePoint(`0x${c}`))
|
||||
.join("");
|
||||
}
|
||||
|
||||
function prepareShortName(shortname) {
|
||||
if (shortname === ":-1:") {
|
||||
// We replace dashes, but should keep :-1: working
|
||||
return "-1";
|
||||
} else if (shortname === ":e-mail:") {
|
||||
// :email: exists as an alternative, should figure out how to use it instead
|
||||
return "email";
|
||||
}
|
||||
|
||||
return shortname
|
||||
.slice(1, -1)
|
||||
.replace("-", "_");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue