discordemojimap

package module
v2.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 3, 2024 License: BSD-3-Clause Imports: 1 Imported by: 1

README

Discord Emoji Map

Build status GoDoc codecov

This library allows you to substitute Discord emoji codes with their respective emoji.

Note that the tests require golang 1.22, due to the fact that they are parallelised, but don't shadow the loop variables.

Example

package main

import (
    "fmt"
    "github.com/Bios-Marcel/discordemojimap"
)

func main() {
    fmt.Println(discordemojimap.Replace("What a wonderful day :sun_with_face:, am I right?"))
}

Update Mapping

To regenerate mapping.go, run these commands:

wget http://discord.com/assets/5c193e4366261ef233e1.js
go run ./cmd/extractmap -path ./5c193e4366261ef233e1.js -out ./mapping.go

This was last updated on September 10th, 2023.

Note that the name of the asset containing the mapping may change in the future.

Documentation

Overview

Package discordemojimap provides a Replace function in order to escape emoji sequences with their respective emojis.

Index

Examples

Constants

This section is empty.

Variables

View Source
var EmojiMap = map[string]string{}/* 5467 elements not displayed */

Functions

func ContainsCode

func ContainsCode(emojiCode string) bool

ContainsCode returns true if emojiCode is mapped to an emoji. The search is case-insensitive.

Example
fmt.Println(ContainsCode("grimacing"))
Output:

true

func ContainsEmoji

func ContainsEmoji(emoji string) bool

ContainsEmoji returns true if that emoji is mapped to one or more key.

Example
fmt.Println(ContainsEmoji("😀"))
Output:

true

func GetEmoji

func GetEmoji(emojiCode string) string

GetEmoji returns the matching emoji or an empty string in case no match was found for the given code.

The function will search without accounting for colons. The search is case-insensitive.

Example
fmt.Println(GetEmoji("lion"))
Output:

🦁

func GetEmojiCodes

func GetEmojiCodes(emoji string) []string

GetEmojiCodes contains all codes for an emoji in an array. If no code could be found, then the resulting array will be empty.

Example
codes := GetEmojiCodes("🦁")
sort.Strings(codes)
fmt.Println(codes)
Output:

[lion lion_face]

func GetEntriesWithPrefix

func GetEntriesWithPrefix(prefix string) map[string]string

GetEntriesWithPrefix returns a map of all found emojis with the given prefix.

The function will search without accounting for leading colons. The search is case-insensitive.

Example
fmt.Printf("%+v\n", GetEntriesWithPrefix("lio"))
Output:

map[lion:🦁 lion_face:🦁]

func Replace

func Replace(input string) string

Replace all emoji sequences contained in the emoji map with their respective emojis. For example:

fmt.Println(Replace("Hello World :sun_with_face:"))
//Output: Hello World 🌞

This function is optimized for lowercased emoji sequence, meaning that sequences such as ":SUNGLASSES:" will consume slightly more memory and be slightly slower. However, the impact should be insignificant in most cases.

Types

This section is empty.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL