Update repository to be an importable module
Use edb.prebuilt.json from emojibot2 Provide example usage Update readme to reflect chanegs Simplify code/directory structure new file: .gitignore modified: Emojipasta.go modified: README.md deleted: assets/emojis.json new file: edb.prebuilt.json new file: example/main.go deleted: generator/generator.go
This commit is contained in:
7 files changed
+279
-99262
No files matched your search
+207
@@ -0,0 +1,207 @@
|
||||
### NotepadPP template
|
||||
# Notepad++ backups #
|
||||
*.bak
|
||||
|
||||
### VisualStudioCode template
|
||||
.vscode/*
|
||||
!.vscode/settings.json
|
||||
!.vscode/tasks.json
|
||||
!.vscode/launch.json
|
||||
!.vscode/extensions.json
|
||||
*.code-workspace
|
||||
|
||||
# Local History for Visual Studio Code
|
||||
.history/
|
||||
|
||||
### JetBrains template
|
||||
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
|
||||
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||
|
||||
# User-specific stuff
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
|
||||
# Generated files
|
||||
.idea/**/contentModel.xml
|
||||
|
||||
# Sensitive or high-churn files
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
|
||||
# Gradle
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
|
||||
# Gradle and Maven with auto-import
|
||||
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||
# since they will be recreated, and may cause churn. Uncomment if using
|
||||
# auto-import.
|
||||
# .idea/artifacts
|
||||
# .idea/compiler.xml
|
||||
# .idea/jarRepositories.xml
|
||||
# .idea/modules.xml
|
||||
# .idea/*.iml
|
||||
# .idea/modules
|
||||
# *.iml
|
||||
# *.ipr
|
||||
|
||||
# CMake
|
||||
cmake-build-*/
|
||||
|
||||
# Mongo Explorer plugin
|
||||
.idea/**/mongoSettings.xml
|
||||
|
||||
# File-based project format
|
||||
*.iws
|
||||
|
||||
# IntelliJ
|
||||
out/
|
||||
|
||||
# mpeltonen/sbt-idea plugin
|
||||
.idea_modules/
|
||||
|
||||
# JIRA plugin
|
||||
atlassian-ide-plugin.xml
|
||||
|
||||
# Cursive Clojure plugin
|
||||
.idea/replstate.xml
|
||||
|
||||
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
|
||||
# Editor-based Rest Client
|
||||
.idea/httpRequests
|
||||
|
||||
# Android studio 3.1+ serialized cache file
|
||||
.idea/caches/build_file_checksums.ser
|
||||
|
||||
### Linux template
|
||||
*~
|
||||
|
||||
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||
.fuse_hidden*
|
||||
|
||||
# KDE directory preferences
|
||||
.directory
|
||||
|
||||
# Linux trash folder which might appear on any partition or disk
|
||||
.Trash-*
|
||||
|
||||
# .nfs files are created when an open file is removed but is still being accessed
|
||||
.nfs*
|
||||
|
||||
### Go template
|
||||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.exe~
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Test binary, built with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
# Dependency directories (remove the comment below to include it)
|
||||
# vendor/
|
||||
|
||||
### Windows template
|
||||
# Windows thumbnail cache files
|
||||
Thumbs.db
|
||||
Thumbs.db:encryptable
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
|
||||
# Dump file
|
||||
*.stackdump
|
||||
|
||||
# Folder config file
|
||||
[Dd]esktop.ini
|
||||
|
||||
# Recycle Bin used on file shares
|
||||
$RECYCLE.BIN/
|
||||
|
||||
# Windows Installer files
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
|
||||
# Windows shortcuts
|
||||
*.lnk
|
||||
|
||||
### macOS template
|
||||
# General
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
|
||||
# Icon must end with two \r
|
||||
Icon
|
||||
|
||||
# Thumbnails
|
||||
._*
|
||||
|
||||
# Files that might appear in the root of a volume
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
|
||||
# Directories potentially created on remote AFP share
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
||||
|
||||
### SublimeText template
|
||||
# Cache files for Sublime Text
|
||||
*.tmlanguage.cache
|
||||
*.tmPreferences.cache
|
||||
*.stTheme.cache
|
||||
|
||||
# Workspace files are user-specific
|
||||
*.sublime-workspace
|
||||
|
||||
# Project files should be checked into the repository, unless a significant
|
||||
# proportion of contributors will probably not be using Sublime Text
|
||||
# *.sublime-project
|
||||
|
||||
# SFTP configuration file
|
||||
sftp-config.json
|
||||
sftp-config-alt*.json
|
||||
|
||||
# Package control specific files
|
||||
Package Control.last-run
|
||||
Package Control.ca-list
|
||||
Package Control.ca-bundle
|
||||
Package Control.system-ca-bundle
|
||||
Package Control.cache/
|
||||
Package Control.ca-certs/
|
||||
Package Control.merged-ca-bundle
|
||||
Package Control.user-ca-bundle
|
||||
oscrypto-ca-bundle.crt
|
||||
bh_unicode_properties.cache
|
||||
|
||||
# Sublime-github package stores a github token in this file
|
||||
# https://packagecontrol.io/packages/sublime-github
|
||||
GitHub.sublime-settings
|
||||
|
||||
+35
-14
@@ -1,23 +1,44 @@
|
||||
package main
|
||||
package emojipasta
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/xerosic/emojipasta/generator"
|
||||
_ "embed"
|
||||
"encoding/json"
|
||||
"math/rand"
|
||||
"time"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Generate(phrase string, config generator.EmojipastaConfig) string{
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
splitWords := generator.SplitWordByDelimiter(phrase, config.WordDelimiter)
|
||||
return generator.AddEmojisToSlice(splitWords, config.MaxEmojisPerWord, config.FixedEmojiNumber)
|
||||
var (
|
||||
//go:embed edb.prebuilt.json
|
||||
_jsonFile []byte
|
||||
_emojiDB map[string][]string
|
||||
_matchBrackets = regexp.MustCompile("[\\[\\]]")
|
||||
)
|
||||
|
||||
func init() {
|
||||
if err := json.Unmarshal(_jsonFile, &_emojiDB); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
cfg := generator.EmojipastaConfig{
|
||||
WordDelimiter: " ",
|
||||
MaxEmojisPerWord: 2,
|
||||
FixedEmojiNumber: false,
|
||||
func Generate(input []string, maxEmojisPerWord int, fixedEmojiNumber bool) (output string) {
|
||||
emojisPerWord := maxEmojisPerWord
|
||||
for k, word := range input {
|
||||
if k > 0 {
|
||||
output += " "
|
||||
}
|
||||
output += word
|
||||
|
||||
if !fixedEmojiNumber {
|
||||
emojisPerWord = rand.Intn(maxEmojisPerWord)
|
||||
}
|
||||
|
||||
if emojis, ok := _emojiDB[strings.ToLower(word)]; ok {
|
||||
for i := 0; i <= emojisPerWord; i++ {
|
||||
output += emojis[rand.Intn(len(emojis))]
|
||||
}
|
||||
}
|
||||
}
|
||||
fmt.Println(Generate("This library allows you to create emojipastas like this one", cfg))
|
||||
|
||||
return _matchBrackets.ReplaceAllString(output, "")
|
||||
}
|
||||
@@ -2,4 +2,25 @@
|
||||
This:arrow_up: library allows you:point_right: to:blush::two_men_holding_hands::speak_no_evil: create:calling::calling::calling: emojipastas:smiley::smiley: like:triumph::grin: this❓🏻 one:triumph::wheelchair:
|
||||
|
||||
## This is just a porting of a [porting](https://github.com/DavideGalilei/emojipasta) that a friend of mine made.
|
||||
The code is trash and was done just for fun, this thing is not optimized. Have fun with it!
|
||||
- The code is trash and was done just for fun, this thing is not optimized. Have fun with it!
|
||||
|
||||
- Uses [edb.prebuilt.json](https://github.com/oldpepper12/emojibot2/blob/master/edb.prebuilt.json) from [emojibot2](https://github.com/oldpepper12/emojibot2)
|
||||
|
||||
## Example Code
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/xerosic/emojipasta"
|
||||
)
|
||||
|
||||
func main() {
|
||||
input := "This library allows you to create emojipastas like this one"
|
||||
output := emojipasta.Generate(strings.Split(input, " "), 3, false)
|
||||
fmt.Println(output)
|
||||
}
|
||||
```
|
||||
-99169
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1 @@
|
||||
{"way":["➕","😊","🥰","🙌","😳","😫","😍","↕","➿","➿","➿","↕","↕","↕","💫","💫","💫","🇲","🇽","🧱","🇺","🇸","↕","👋","↕","💰","↕","↕","↕","↕","↕","↕","↕","↕","👏","👏","👏","🚈","💫","💫","💫","🤔","🤔","🤔","🛣","↕","↕","↕","↕","↕","🤣","💫","💫","💫","🛣","🛣","🙅♀️","↕","↕","👉","👉","🚹","🏅","⬇","✋🏼","👨","👉","👉","🤔","🤔","↕","↕","↕","↕","✋","✋","✋","✋","🚘","🚘","👏","👏","➡","➡","➡","➡","⬆","⬆","⬆","🔀","➡","➡","⬆","⬆","⬆","🔀","➡","➡","❤","❤","❤","❤","🛤","⬆","⬆","⬆","🔀","➡","➡","💫","🏃🏻","💫","💫","💫","💫","💫","💫","💫","💫","⤵","↕","↔","⏳","🥖","↖","👉🏻","😶","😶","🐮","🍼","😨","😭","😜","🌱","🤗","🌵","➡","😝","➡","😩","💦","⬅","➡","🚷","⬅","⬅","⬅","⬅","‼","🙅","↕","↕","⚖","⚖","🚓","🚕","🚙","↕","↕","↕","↕","↕","↕","😉","😉","😉","😉","😉","😉","😉","😉","😉","😉","😉","😉","😉","😉","👅","😈","😏","🔜","👆","👆","👆","➡","😝","➡","😝","🔨","🔨","💀","💀","💀","👋","👋","🛣","🚶","😒","↕"],"ebony":["⚫","🦷","🦷","👩🏿","💋","👩🏿","💋","👩🏿","💋","👩🏿","💋","👩🏿","💋","👩🏿","💋"],"with":["💜","☠","☠","💪","👍","👌","😫","➕","💼","🅰","🅰","🅰","📩","🆓","➕","👏","👏","👏","👏","👏","👏","👏","👏","👏","🙊","👩","👩","👉","👌","💦","😎","💘","👏","👀","😂","🐝","😶","🎃","👻","😼","👌","💥","😼","👌","💥","🖐🏻","💥","🖐🏻","💥","👅","👅","🐭","👏","👏","👏","👏","👏","👏","👏","👏","👏","👏","👏","👏","👏","👏","👏","👏","👏","👏","🍓","🔚","👉","👏","👏","👏","👏","👏","👏","👏","👏","👏","🕚","👏","👏","👊🏽","👋🏾","💅🏼","🍆","🍥","😔","6⃣","😭","😭","👉","🤘","🚶","🚶","😎","😎","👉🏽","😣","👌","📝","👏","👏","👏","👏","👏","👏","👏","👏","👏","🤝","🤝","🎉","6⃣","💢","🙊","👈","💩","🌕","🛀🏼","👵","👃🏾","🏇🏽","👦","♠","😭","👌","👐","👥","👯♀️","🅰","🅰","👨","👏","👏","👏","👏","👏","😠","😣","👏","👻","😫","👦","♠","😭","👌","👅","👏","🏢","👉","😂","🍴","😂","🍴","👦","♠","😭","👌","💰","👏","👏","😎","➡","🙌","🙌","🆕","🆕","➡","😤","🤤","👯♀️","💕","👏🏼","👽","👏","👏","👻","😏","🏢","👦","👦","👏","👏","👏","👏","👏","👏","👩","👏","🙆","💪","👥","😂","👊","👏","👏","👏","👏","👏","👏","👏","👏","😍","👌","👙","👄","💗","❤","👏","5️⃣","✈","👏","👏","👏","👏","👏","👏","👏","👏","🏙","👏","👏","🅰","👏","👏","👏","👏","😱","😱","📎","📝","🖇","👏","👏","👌","💯","👎","👏","👏","👏","👏","👏","👏","👏","👏","😏","🅰","🙊","👏","👏","👏","🅱","👏","👏","👏","👅","👸","👏","👏","👏","👏","👏","👏","👏","👏","👏","💉","💰","😒","😕","🆕","🆕","🆕","🆕","🆕","🆕","🆕","🆕","😁","😎","💸","💰","💎","💵","💦","🤑","🖕","⛽","👏🏻","👏🏻","😍","✡","💁","🍆","🍆","🙋","🎆","👏","👏","👏","🙎🏻","👌","👩","👌","👩","😜","🗣","😘","👍","❤","🅰","💉","❗","👊","🔥","⚡","◀","😋","🚣","😋","🚣","🅰","🅰","🔥","🅰","🅰","👀","🚫","🙀","😏","😏","😏","😏","😏","💔","👀","👀","1️⃣","🎉","📍","😉","📺","👊","💥","🔥","⚡","👀","🏹","🤔","😫","➡","👀","💰","😍","👏","💥","👏","👯","😍","💰","😣","👦","👏","🙀","👻","👏","♀","👏","🎉","👏","❌","😂","👉🏾","👌🏾","🅱","🅱","🅰","👏","👏","👏"],"streaks":["➕","🔴","🏃","💨","😱","😳","😏","🏃","💨","😱","😳","😏"],"mid-":["🔙","➕"],"icy":["🔵","👀","❄","❄"],"limpid":["😂","➕"],"of":["👥","🗣","🚞","♾","🙃","🤗","🤡","🤒","🤒","🈸","🥗","💨","💿","💦","💖","👏🏻","💰","💰","😭","😭","😭","🔎","😤","💦","💦","💦","💦","💦","💦","💦","💦","💦","💦","💦","💦","💦","💦","💦","💦","✨","🐻","🍚","🍚","👱","🚲","🔥","🔥","😍","😳","💢","✨","👯","👪","😤","💰","💦","👪","💦","💦","👪","💯","😼","👌","💥","😼","👌","💥","😼","👌","💥","😼","👌","💥","🏠","🅱","💰","🗼","📷","📷","🏠","🅱","❤","🅱","Line truncated
|
||||
@@ -0,0 +1,14 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/xerosic/emojipasta"
|
||||
)
|
||||
|
||||
func main() {
|
||||
input := "This library allows you to create emojipastas like this one"
|
||||
output := emojipasta.Generate(strings.Split(input, " "), 3, false)
|
||||
fmt.Println(output)
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
package generator
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"os"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type EmojipastaConfig struct {
|
||||
WordDelimiter string
|
||||
MaxEmojisPerWord int
|
||||
FixedEmojiNumber bool
|
||||
}
|
||||
|
||||
func SplitWordByDelimiter(word string, delimiter string) []string {
|
||||
return strings.Split(word, delimiter)
|
||||
}
|
||||
|
||||
func AddEmojisToSlice(phrase []string, maxEmojisPerWord int, fixedEmojiNumber bool) string {
|
||||
jsonFile, err := os.Open("assets/emojis.json")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
defer jsonFile.Close()
|
||||
|
||||
byteValue, _ := ioutil.ReadAll(jsonFile)
|
||||
|
||||
var result map[string]interface{}
|
||||
var emojis []string
|
||||
|
||||
var finalString string
|
||||
|
||||
err2 := json.Unmarshal(byteValue, &result)
|
||||
if err2 != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
if fixedEmojiNumber {
|
||||
for j, word := range phrase {
|
||||
if j == 0 {
|
||||
finalString += word
|
||||
} else {
|
||||
finalString += " " + word
|
||||
}
|
||||
|
||||
emojis = strings.Split(fmt.Sprintf("%v", result[strings.ToLower(word)]), " ")
|
||||
for i := 1; i <= maxEmojisPerWord; i++ {
|
||||
index := rand.Intn(len(emojis))
|
||||
if emojis[index] != "<nil>" {
|
||||
finalString += emojis[index]
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
rnd := rand.Intn(maxEmojisPerWord)
|
||||
for j, word := range phrase {
|
||||
if j == 0 {
|
||||
finalString += word
|
||||
} else {
|
||||
finalString += " " + word
|
||||
}
|
||||
|
||||
emojis = strings.Split(fmt.Sprintf("%v", result[strings.ToLower(word)]), " ")
|
||||
for i := 0; i <= rnd; i++ {
|
||||
index := rand.Intn(len(emojis))
|
||||
if emojis[index] != "<nil>" {
|
||||
finalString += emojis[index]
|
||||
}
|
||||
}
|
||||
rnd = rand.Intn(maxEmojisPerWord)
|
||||
}
|
||||
}
|
||||
return strings.ReplaceAll(strings.ReplaceAll(finalString, "[", ""), "]", "")
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user