|
|
@ -6,6 +6,8 @@ import ( |
|
|
|
"strings" |
|
|
|
"strings" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this is a global var set by flag that indicates whether emoji shortnames should be reprinted as unicode emojis
|
|
|
|
|
|
|
|
// some systems may support this
|
|
|
|
var UNICODE_EMOJI_SUPPORT bool = false |
|
|
|
var UNICODE_EMOJI_SUPPORT bool = false |
|
|
|
|
|
|
|
|
|
|
|
type emojiData struct { |
|
|
|
type emojiData struct { |
|
|
@ -15,7 +17,9 @@ type emojiData struct { |
|
|
|
Alias []string |
|
|
|
Alias []string |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this converts shortname emojis to unicode emojis when they can be found in the data map
|
|
|
|
func emojiUnicodeConvert(s string) string { |
|
|
|
func emojiUnicodeConvert(s string) string { |
|
|
|
|
|
|
|
// currently fails to find newlines and replace them needs fixed
|
|
|
|
pStr := strings.Fields(s) |
|
|
|
pStr := strings.Fields(s) |
|
|
|
reeMatch := regexp.MustCompile(`:\w+:`) |
|
|
|
reeMatch := regexp.MustCompile(`:\w+:`) |
|
|
|
for i, word := range pStr { |
|
|
|
for i, word := range pStr { |
|
|
@ -32,6 +36,8 @@ func emojiUnicodeConvert(s string) string { |
|
|
|
return strings.Join(pStr, " ") |
|
|
|
return strings.Join(pStr, " ") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this resolves emoji aliases back to the root emoji that actually renders to a picture
|
|
|
|
|
|
|
|
// for example `:cheeseburger:` => `:hamburger:`
|
|
|
|
func resolveRootEmojis(s string) string { |
|
|
|
func resolveRootEmojis(s string) string { |
|
|
|
pStr := strings.Fields(s) |
|
|
|
pStr := strings.Fields(s) |
|
|
|
reMatch := regexp.MustCompile(`:\w+:`) |
|
|
|
reMatch := regexp.MustCompile(`:\w+:`) |
|
|
@ -46,6 +52,7 @@ func resolveRootEmojis(s string) string { |
|
|
|
return strings.Join(pStr, " ") |
|
|
|
return strings.Join(pStr, " ") |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// this is the actual internal function that parses the unicode data to a unicode string representing the emoji
|
|
|
|
func renderUnicodeEmoji(data emojiData) (string, error) { |
|
|
|
func renderUnicodeEmoji(data emojiData) (string, error) { |
|
|
|
emj, err := strconv.ParseInt(data.Unicode, 16, 32) |
|
|
|
emj, err := strconv.ParseInt(data.Unicode, 16, 32) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|