From 1d13330a0652df116574210c0c651bdc08519fa6 Mon Sep 17 00:00:00 2001 From: Azareal Date: Thu, 11 Jul 2019 17:13:05 +1000 Subject: [PATCH] Move the emoji shortcode mappings into /config/emoji_default.json, custom emoji shortcodes can be defined in /config/emoji.json Add the ldflags to the advanced installation steps. --- common/extend.go | 3 + common/parser.go | 179 +++++++++++--------------------------- config/emoji_default.json | 129 +++++++++++++++++++++++++++ docs/installation.md | 8 +- 4 files changed, 189 insertions(+), 130 deletions(-) create mode 100644 config/emoji_default.json diff --git a/common/extend.go b/common/extend.go index 56987dbf..4251d4db 100644 --- a/common/extend.go +++ b/common/extend.go @@ -70,6 +70,9 @@ var hookTable = &HookTable{ "topic_create_frow_assign": nil, }, map[string]func(...interface{}) interface{}{ + //"convo_post_update":nil, + //"convo_post_create":nil, + "forum_trow_assign": nil, "topics_topic_row_assign": nil, //"topics_user_row_assign": nil, diff --git a/common/parser.go b/common/parser.go index ee7bc11f..bbddb4ff 100644 --- a/common/parser.go +++ b/common/parser.go @@ -7,6 +7,9 @@ import ( "regexp" "strconv" "strings" + "io/ioutil" + "os" + "encoding/json" "unicode/utf8" ) @@ -36,135 +39,59 @@ func init() { urlReg = regexp.MustCompile(urlPattern) } +var emojis map[string]string + +type emojiHolder struct { + Emojis []map[string]string `json:"emojis"` +} + +func InitEmoji() error { + data, err := ioutil.ReadFile("./config/emoji_default.json") + if err != nil { + return err + } + + var emoji emojiHolder + err = json.Unmarshal(data, &emoji) + if err != nil { + return err + } + + emojis = make(map[string]string, len(emoji.Emojis)) + for _, item := range emoji.Emojis { + for ikey, ival := range item { + emojis[ikey] = ival + } + } + + data, err = ioutil.ReadFile("./config/emoji.json") + if err == os.ErrPermission || err == os.ErrClosed { + return err + } else if err != nil { + return nil + } + + emoji = emojiHolder{} + err = json.Unmarshal(data, &emoji) + if err != nil { + return err + } + + for _, item := range emoji.Emojis { + for ikey, ival := range item { + emojis[ikey] = ival + } + } + + return nil +} + // TODO: Write a test for this func shortcodeToUnicode(msg string) string { //re := regexp.MustCompile(":(.):") - msg = strings.Replace(msg, ":grinning:", "😀", -1) - msg = strings.Replace(msg, ":grin:", "😁", -1) - msg = strings.Replace(msg, ":joy:", "😂", -1) - msg = strings.Replace(msg, ":rofl:", "đŸ¤Ŗ", -1) - msg = strings.Replace(msg, ":smiley:", "😃", -1) - msg = strings.Replace(msg, ":smile:", "😄", -1) - msg = strings.Replace(msg, ":sweat_smile:", "😅", -1) - msg = strings.Replace(msg, ":laughing:", "😆", -1) - msg = strings.Replace(msg, ":satisfied:", "😆", -1) - msg = strings.Replace(msg, ":wink:", "😉", -1) - msg = strings.Replace(msg, ":blush:", "😊", -1) - msg = strings.Replace(msg, ":yum:", "😋", -1) - msg = strings.Replace(msg, ":sunglasses:", "😎", -1) - msg = strings.Replace(msg, ":heart_eyes:", "😍", -1) - msg = strings.Replace(msg, ":kissing_heart:", "😘", -1) - msg = strings.Replace(msg, ":kissing:", "😗", -1) - msg = strings.Replace(msg, ":kissing_smiling_eyes:", "😙", -1) - msg = strings.Replace(msg, ":kissing_closed_eyes:", "😚", -1) - msg = strings.Replace(msg, ":relaxed:", "â˜ēī¸", -1) - msg = strings.Replace(msg, ":slight_smile:", "🙂", -1) - msg = strings.Replace(msg, ":hugging:", "🤗", -1) - msg = strings.Replace(msg, ":thinking:", "🤔", -1) - msg = strings.Replace(msg, ":neutral_face:", "😐", -1) - msg = strings.Replace(msg, ":expressionless:", "😑", -1) - msg = strings.Replace(msg, ":no_mouth:", "đŸ˜ļ", -1) - msg = strings.Replace(msg, ":rolling_eyes:", "🙄", -1) - msg = strings.Replace(msg, ":smirk:", "😏", -1) - msg = strings.Replace(msg, ":persevere:", "đŸ˜Ŗ", -1) - msg = strings.Replace(msg, ":disappointed_relieved:", "đŸ˜Ĩ", -1) - msg = strings.Replace(msg, ":open_mouth:", "😮", -1) - msg = strings.Replace(msg, ":zipper_mouth:", "🤐", -1) - msg = strings.Replace(msg, ":hushed:", "đŸ˜¯", -1) - msg = strings.Replace(msg, ":sleepy:", "đŸ˜Ē", -1) - msg = strings.Replace(msg, ":tired_face:", "đŸ˜Ģ", -1) - msg = strings.Replace(msg, ":sleeping:", "😴", -1) - msg = strings.Replace(msg, ":relieved:", "😌", -1) - msg = strings.Replace(msg, ":nerd:", "🤓", -1) - msg = strings.Replace(msg, ":stuck_out_tongue:", "😛", -1) - msg = strings.Replace(msg, ":worried:", "😟", -1) - msg = strings.Replace(msg, ":drooling_face:", "🤤", -1) - msg = strings.Replace(msg, ":disappointed:", "😞", -1) - msg = strings.Replace(msg, ":astonished:", "😲", -1) - msg = strings.Replace(msg, ":slight_frown:", "🙁", -1) - msg = strings.Replace(msg, ":skull_crossbones:", "☠ī¸", -1) - msg = strings.Replace(msg, ":skull:", "💀", -1) - msg = strings.Replace(msg, ":point_up:", "☝ī¸", -1) - msg = strings.Replace(msg, ":v:", "✌ī¸ī¸", -1) - msg = strings.Replace(msg, ":writing_hand:", "✍ī¸", -1) - msg = strings.Replace(msg, ":heart:", "❤ī¸ī¸", -1) - msg = strings.Replace(msg, ":heart_exclamation:", "âŖī¸", -1) - msg = strings.Replace(msg, ":hotsprings:", "♨ī¸", -1) - msg = strings.Replace(msg, ":airplane:", "✈ī¸ī¸", -1) - msg = strings.Replace(msg, ":hourglass:", "⌛", -1) - msg = strings.Replace(msg, ":watch:", "⌚", -1) - msg = strings.Replace(msg, ":comet:", "☄ī¸", -1) - msg = strings.Replace(msg, ":snowflake:", "❄ī¸", -1) - msg = strings.Replace(msg, ":cloud:", "☁ī¸", -1) - msg = strings.Replace(msg, ":sunny:", "☀ī¸", -1) - msg = strings.Replace(msg, ":spades:", "♠ī¸", -1) - msg = strings.Replace(msg, ":hearts:", "â™Ĩī¸ī¸", -1) - msg = strings.Replace(msg, ":diamonds:", "â™Ļī¸", -1) - msg = strings.Replace(msg, ":clubs:", "â™Ŗī¸", -1) - msg = strings.Replace(msg, ":phone:", "☎ī¸", -1) - msg = strings.Replace(msg, ":telephone:", "☎ī¸", -1) - msg = strings.Replace(msg, ":biohazard:", "â˜Ŗī¸", -1) - msg = strings.Replace(msg, ":radioactive:", "â˜ĸī¸", -1) - msg = strings.Replace(msg, ":scissors:", "✂ī¸", -1) - msg = strings.Replace(msg, ":arrow_upper_right:", "↗ī¸", -1) - msg = strings.Replace(msg, ":arrow_right:", "➡ī¸", -1) - msg = strings.Replace(msg, ":arrow_lower_right:", "↘ī¸", -1) - msg = strings.Replace(msg, ":arrow_lower_left:", "↙ī¸", -1) - msg = strings.Replace(msg, ":arrow_upper_left:", "↖ī¸", -1) - msg = strings.Replace(msg, ":arrow_up_down:", "↕ī¸", -1) - msg = strings.Replace(msg, ":left_right_arrow:", "↔ī¸", -1) - msg = strings.Replace(msg, ":leftwards_arrow_with_hook:", "↩ī¸", -1) - msg = strings.Replace(msg, ":arrow_right_hook:", "â†Ēī¸", -1) - msg = strings.Replace(msg, ":arrow_forward:", "â–ļī¸", -1) - msg = strings.Replace(msg, ":arrow_backward:", "◀ī¸", -1) - msg = strings.Replace(msg, ":female:", "♀ī¸", -1) - msg = strings.Replace(msg, ":male:", "♂ī¸", -1) - msg = strings.Replace(msg, ":ballot_box_with_check:", "☑ī¸", -1) - msg = strings.Replace(msg, ":heavy_check_mark:", "✔ī¸ī¸", -1) - msg = strings.Replace(msg, ":heavy_multiplication_x:", "✖ī¸", -1) - msg = strings.Replace(msg, ":pisces:", "♓", -1) - msg = strings.Replace(msg, ":aquarius:", "♒", -1) - msg = strings.Replace(msg, ":capricorn:", "♑", -1) - msg = strings.Replace(msg, ":sagittarius:", "♐", -1) - msg = strings.Replace(msg, ":scorpius:", "♏", -1) - msg = strings.Replace(msg, ":libra:", "♎", -1) - msg = strings.Replace(msg, ":virgo:", "♍", -1) - msg = strings.Replace(msg, ":leo:", "♌", -1) - msg = strings.Replace(msg, ":cancer:", "♋", -1) - msg = strings.Replace(msg, ":gemini:", "♊", -1) - msg = strings.Replace(msg, ":taurus:", "♉", -1) - msg = strings.Replace(msg, ":aries:", "♈", -1) - msg = strings.Replace(msg, ":peace:", "☎ī¸", -1) - msg = strings.Replace(msg, ":eight_spoked_asterisk:", "âœŗī¸", -1) - msg = strings.Replace(msg, ":eight_pointed_black_star:", "✴ī¸", -1) - msg = strings.Replace(msg, ":snowman2:", "☃ī¸", -1) - msg = strings.Replace(msg, ":umbrella2:", "☂ī¸", -1) - msg = strings.Replace(msg, ":pencil2:", "✏ī¸", -1) - msg = strings.Replace(msg, ":black_nib:", "✒ī¸", -1) - msg = strings.Replace(msg, ":email:", "✉ī¸", -1) - msg = strings.Replace(msg, ":envelope:", "✉ī¸", -1) - msg = strings.Replace(msg, ":keyboard:", "⌨ī¸", -1) - msg = strings.Replace(msg, ":white_small_square:", "â–Ģī¸", -1) - msg = strings.Replace(msg, ":black_small_square:", "â–Ēī¸", -1) - msg = strings.Replace(msg, ":secret:", "㊙ī¸", -1) - msg = strings.Replace(msg, ":congratulations:", "㊗ī¸", -1) - msg = strings.Replace(msg, ":m:", "Ⓜī¸", -1) - msg = strings.Replace(msg, ":tm:", "â„ĸī¸ī¸", -1) - msg = strings.Replace(msg, ":registered:", "ÂŽī¸", -1) - msg = strings.Replace(msg, ":copyright:", "Šī¸", -1) - msg = strings.Replace(msg, ":wavy_dash:", "〰ī¸", -1) - msg = strings.Replace(msg, ":bangbang:", "â€ŧī¸", -1) - msg = strings.Replace(msg, ":sparkle:", "❇ī¸", -1) - msg = strings.Replace(msg, ":star_of_david:", "✡ī¸", -1) - msg = strings.Replace(msg, ":wheel_of_dharma:", "☸ī¸", -1) - msg = strings.Replace(msg, ":yin_yang:", "☯ī¸", -1) - msg = strings.Replace(msg, ":cross:", "✝ī¸", -1) - msg = strings.Replace(msg, ":orthodox_cross:", "â˜Ļī¸", -1) - msg = strings.Replace(msg, ":star_and_crescent:", "â˜Ēī¸", -1) - msg = strings.Replace(msg, ":frowning2:", "☚ī¸", -1) - msg = strings.Replace(msg, ":information_source:", "ℹī¸", -1) - msg = strings.Replace(msg, ":interrobang:", "⁉ī¸", -1) - + for shortcode, emoji := range emojis { + msg = strings.Replace(msg, shortcode, emoji, -1) + } return msg } diff --git a/config/emoji_default.json b/config/emoji_default.json new file mode 100644 index 00000000..4dbe3197 --- /dev/null +++ b/config/emoji_default.json @@ -0,0 +1,129 @@ +{ + "emojis": [ + {":grinning:": "😀"}, + {":grin:": "😁"}, + {":joy:": "😂"}, + {":rofl:": "đŸ¤Ŗ"}, + {":smiley:": "😃"}, + {":smile:": "😄"}, + {":sweat_smile:": "😅"}, + {":laughing:": "😆"}, + {":satisfied:": "😆"}, + {":wink:": "😉"}, + {":blush:": "😊"}, + {":yum:": "😋"}, + {":sunglasses:": "😎"}, + {":heart_eyes:": "😍"}, + {":kissing_heart:": "😘"}, + {":kissing:": "😗"}, + {":kissing_smiling_eyes:": "😙"}, + {":kissing_closed_eyes:": "😚"}, + {":relaxed:": "â˜ēī¸"}, + {":slight_smile:": "🙂"}, + {":hugging:": "🤗"}, + {":thinking:": "🤔"}, + {":neutral_face:": "😐"}, + {":expressionless:": "😑"}, + {":no_mouth:": "đŸ˜ļ"}, + {":rolling_eyes:": "🙄"}, + {":smirk:": "😏"}, + {":persevere:": "đŸ˜Ŗ"}, + {":disappointed_relieved:": "đŸ˜Ĩ"}, + {":open_mouth:": "😮"}, + {":zipper_mouth:": "🤐"}, + {":hushed:": "đŸ˜¯"}, + {":sleepy:": "đŸ˜Ē"}, + {":tired_face:": "đŸ˜Ģ"}, + {":sleeping:": "😴"}, + {":relieved:": "😌"}, + {":nerd:": "🤓"}, + {":stuck_out_tongue:": "😛"}, + {":worried:": "😟"}, + {":drooling_face:": "🤤"}, + {":disappointed:": "😞"}, + {":astonished:": "😲"}, + {":slight_frown:": "🙁"}, + {":skull_crossbones:": "☠ī¸"}, + {":skull:": "💀"}, + {":point_up:": "☝ī¸"}, + {":v:": "✌ī¸ī¸"}, + {":writing_hand:": "✍ī¸"}, + {":heart:": "❤ī¸ī¸"}, + {":heart_exclamation:": "âŖī¸"}, + {":hotsprings:": "♨ī¸"}, + {":airplane:": "✈ī¸ī¸"}, + {":hourglass:": "⌛"}, + {":watch:": "⌚"}, + {":comet:": "☄ī¸"}, + {":snowflake:": "❄ī¸"}, + {":cloud:": "☁ī¸"}, + {":sunny:": "☀ī¸"}, + {":spades:": "♠ī¸"}, + {":hearts:": "â™Ĩī¸ī¸"}, + {":diamonds:": "â™Ļī¸"}, + {":clubs:": "â™Ŗī¸"}, + {":phone:": "☎ī¸"}, + {":telephone:": "☎ī¸"}, + {":biohazard:": "â˜Ŗī¸"}, + {":radioactive:": "â˜ĸī¸"}, + {":scissors:": "✂ī¸"}, + {":arrow_upper_right:": "↗ī¸"}, + {":arrow_right:": "➡ī¸"}, + {":arrow_lower_right:": "↘ī¸"}, + {":arrow_lower_left:": "↙ī¸"}, + {":arrow_upper_left:": "↖ī¸"}, + {":arrow_up_down:": "↕ī¸"}, + {":left_right_arrow:": "↔ī¸"}, + {":leftwards_arrow_with_hook:": "↩ī¸"}, + {":arrow_right_hook:": "â†Ēī¸"}, + {":arrow_forward:": "â–ļī¸"}, + {":arrow_backward:": "◀ī¸"}, + {":female:": "♀ī¸"}, + {":male:": "♂ī¸"}, + {":ballot_box_with_check:": "☑ī¸"}, + {":heavy_check_mark:": "✔ī¸ī¸"}, + {":heavy_multiplication_x:": "✖ī¸"}, + {":pisces:": "♓"}, + {":aquarius:": "♒"}, + {":capricorn:": "♑"}, + {":sagittarius:": "♐"}, + {":scorpius:": "♏"}, + {":libra:": "♎"}, + {":virgo:": "♍"}, + {":leo:": "♌"}, + {":cancer:": "♋"}, + {":gemini:": "♊"}, + {":taurus:": "♉"}, + {":aries:": "♈"}, + {":peace:": "☎ī¸"}, + {":eight_spoked_asterisk:": "âœŗī¸"}, + {":eight_pointed_black_star:": "✴ī¸"}, + {":snowman2:": "☃ī¸"}, + {":umbrella2:": "☂ī¸"}, + {":pencil2:": "✏ī¸"}, + {":black_nib:": "✒ī¸"}, + {":email:": "✉ī¸"}, + {":envelope:": "✉ī¸"}, + {":keyboard:": "⌨ī¸"}, + {":white_small_square:": "â–Ģī¸"}, + {":black_small_square:": "â–Ēī¸"}, + {":secret:": "㊙ī¸"}, + {":congratulations:": "㊗ī¸"}, + {":m:": "Ⓜī¸"}, + {":tm:": "â„ĸī¸ī¸"}, + {":registered:": "ÂŽī¸"}, + {":copyright:": "Šī¸"}, + {":wavy_dash:": "〰ī¸"}, + {":bangbang:": "â€ŧī¸"}, + {":sparkle:": "❇ī¸"}, + {":star_of_david:": "✡ī¸"}, + {":wheel_of_dharma:": "☸ī¸"}, + {":yin_yang:": "☯ī¸"}, + {":cross:": "✝ī¸"}, + {":orthodox_cross:": "â˜Ļī¸"}, + {":star_and_crescent:": "â˜Ēī¸"}, + {":frowning2:": "☚ī¸"}, + {":information_source:": "ℹī¸"}, + {":interrobang:": "⁉ī¸"} + ] +} \ No newline at end of file diff --git a/docs/installation.md b/docs/installation.md index a27bd719..6e741503 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -130,17 +130,17 @@ rm -f ./Gosora go generate -go build ./router_gen +go build -ldflags="-s -w" ./router_gen router_gen.exe -go build ./cmd/query_gen +go build -ldflags="-s -w" ./cmd/query_gen query_gen.exe -go build -o gosora.exe +go build -ldflags="-s -w" -o gosora.exe -go build "./cmd/install" +go build -ldflags="-s -w" "./cmd/install" install.exe