Skip to content

Commit

Permalink
EmojiMap is now exposed
Browse files Browse the repository at this point in the history
  • Loading branch information
Bios-Marcel committed Nov 23, 2019
1 parent ae2145e commit 8c80533
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
5 changes: 4 additions & 1 deletion mapping.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package discordemojimap

var emojiMap = map[string]string{
// EmojiMap is the full list of emoji codes to their respective unicode
// symbols. This is map is public in order to allow memory efficient usage.
// Be careful and do not adjust this map!
var EmojiMap = map[string]string{
"grinning": "😀",
"grimacing": "😬",
"grin": "😁",
Expand Down
10 changes: 5 additions & 5 deletions query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "strings"

// ContainsEmoji returns true if that emoji is mapped to one or more key.
func ContainsEmoji(emoji string) bool {
for _, emojiInMap := range emojiMap {
for _, emojiInMap := range EmojiMap {
if emojiInMap == emoji {
return true
}
Expand All @@ -15,15 +15,15 @@ func ContainsEmoji(emoji string) bool {

// ContainsCode returns true if that emojicode is mapped to an emoji.
func ContainsCode(emojiCode string) bool {
_, contains := emojiMap[emojiCode]
_, contains := EmojiMap[emojiCode]
return contains
}

// GetEmojiCodes contains all codes for an emoji in an array. If no code could
// be found, then the resulting array will be empty.
func GetEmojiCodes(emoji string) []string {
codes := make([]string, 0)
for code, emojiInMap := range emojiMap {
for code, emojiInMap := range EmojiMap {
if emojiInMap == emoji {
codes = append(codes, code)
}
Expand All @@ -35,7 +35,7 @@ func GetEmojiCodes(emoji string) []string {
// GetEmoji returns the matching emoji or an empty string in case no match was
// found for the given code.
func GetEmoji(emojiCode string) string {
emoji, _ := emojiMap[emojiCode]
emoji, _ := EmojiMap[emojiCode]
return emoji
}

Expand All @@ -50,7 +50,7 @@ func GetEntriesStartingWith(startsWith string) map[string]string {

searchTerm := strings.TrimSuffix(startsWith, ":")

for emojiCode, emoji := range emojiMap {
for emojiCode, emoji := range EmojiMap {
if strings.HasPrefix(emojiCode, searchTerm) {
matches[emojiCode] = emoji
}
Expand Down
2 changes: 1 addition & 1 deletion replacer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func Replace(input string) string {
}

replacedEmojis := emojiCodeRegex.ReplaceAllStringFunc(input, func(match string) string {
emojified, contains := emojiMap[strings.ToLower(match[1:len(match)-1])]
emojified, contains := EmojiMap[strings.ToLower(match[1:len(match)-1])]
if !contains {
return match
}
Expand Down

0 comments on commit 8c80533

Please sign in to comment.