Fix emoji to slack shortcode logic for skin tone variations

pull/21/head
Max Sandholm 2023-02-08 13:42:46 +02:00
parent 67b1e7b1ff
commit 94ee85e503
4 changed files with 31 additions and 28 deletions

View File

@ -38,12 +38,19 @@ func shortcodeToEmoji(code string) string {
}
func emojiToShortcode(emoji string) string {
for code, e := range emojis {
if emoji == e {
return code
var partCodes []string
for _, r := range emoji {
if r == '\ufe0f' { // ignore unicode variation selector
continue
}
for code, e := range emojis {
if string(r) == e {
partCodes = append(partCodes, code)
continue
}
}
}
return ""
return strings.Join(partCodes, "::")
}
func init() {

View File

@ -1,23 +0,0 @@
The file emoji.json is included from the project https://github.com/omnidan/node-emoji.
The MIT License (MIT)
Copyright (c) 2014 Daniel Bugl
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,19 @@
#!/usr/bin/python3
import requests
import json
def unified_to_unicode(unified: str) -> str:
return (
"".join(rf"\U{chunk:0>8}" for chunk in unified.split("-"))
.encode("ascii")
.decode("unicode_escape")
)
data = requests.get(
"https://raw.githubusercontent.com/iamcal/emoji-data/master/emoji.json"
).json()
emojis = {emoji["short_name"]: unified_to_unicode(emoji["unified"]) for emoji in data}
with open("emoji.json", "w") as file:
json.dump(emojis, file, ensure_ascii=False)