From dfc3b5f2bac00cc04eb0c8742478eca048111fd5 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Fri, 16 Nov 2018 12:27:42 +0100 Subject: [PATCH] Add emoji support --- .gitignore | 3 ++- mods/main.go | 13 ++++++++++++- mods/memegen.go | 7 ++++--- mods/snapchat.go | 7 ++++--- mods/unsplash.go | 7 ++++--- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 77de716..b8dd968 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,5 @@ clessy-mods clessy-stats clessy-stats-import stats-web/Chart.bundle.js -impact.ttf \ No newline at end of file +impact.ttf +noto_emojis \ No newline at end of file diff --git a/mods/main.go b/mods/main.go index 354f97e..fc5ed45 100644 --- a/mods/main.go +++ b/mods/main.go @@ -8,6 +8,7 @@ import ( "strings" "time" + "git.fromouter.space/crunchy-rocks/emoji" "git.fromouter.space/hamcha/tg" ) @@ -155,6 +156,7 @@ var gapifile *string var gapikey *string var gapiCtx context.Context var oropath *string +var emojis emoji.Table func main() { brokerAddr := flag.String("broker", "localhost:7314", "Broker address:port") @@ -172,10 +174,20 @@ func main() { oropath = flag.String("oropath", "/astri", "Path to oroscopo corpus directory") disable := flag.String("disable", "", "Blacklist mods (separated by comma)") enable := flag.String("enable", "", "Whitelist mods (separated by comma)") + emojipath := flag.String("emojis", "noto_emojis", "Path to emoji directory") flag.Parse() gapiCtx = context.Background() + log.Println("[x-emoji] Loading emojis...") + emojis, err := emoji.ScanEmojiDirectory(*emojipath) + if err != nil { + log.Printf("[x-emoji] Error while loading emojis: %s\n", err.Error()) + log.Println("[x-emoji] Emoji support will be disabled") + } else { + log.Printf("[x-emoji] Loaded %d emojis\n", len(emojis)) + } + if *disable != "" { for _, modname := range strings.Split(*disable, ",") { modname = strings.TrimSpace(modname) @@ -193,7 +205,6 @@ func main() { initmods() - var err error broker, err = tg.ConnectToBroker(*brokerAddr) assert(err) defer broker.Close() diff --git a/mods/memegen.go b/mods/memegen.go index 6c2753a..60f9e62 100644 --- a/mods/memegen.go +++ b/mods/memegen.go @@ -12,10 +12,10 @@ import ( "os" "strings" + "git.fromouter.space/crunchy-rocks/draw2d" + "git.fromouter.space/crunchy-rocks/draw2d/draw2dimg" + "git.fromouter.space/crunchy-rocks/freetype" "git.fromouter.space/hamcha/tg" - "github.com/golang/freetype" - "github.com/llgcode/draw2d" - "github.com/llgcode/draw2d/draw2dimg" ) var memeFontData draw2d.FontData @@ -97,6 +97,7 @@ func meme_message(broker *tg.Broker, update tg.APIMessage) { timg := image.NewRGBA(bounds) gc := draw2dimg.NewGraphicContext(timg) + gc.Emojis = emojis gc.SetStrokeColor(image.Black) gc.SetFillColor(image.White) gc.SetFontData(memeFontData) diff --git a/mods/snapchat.go b/mods/snapchat.go index 17f2997..f270ecd 100644 --- a/mods/snapchat.go +++ b/mods/snapchat.go @@ -17,10 +17,10 @@ import ( "time" + "git.fromouter.space/crunchy-rocks/draw2d" + "git.fromouter.space/crunchy-rocks/draw2d/draw2dimg" + "git.fromouter.space/crunchy-rocks/freetype" "git.fromouter.space/hamcha/tg" - "github.com/golang/freetype" - "github.com/llgcode/draw2d" - "github.com/llgcode/draw2d/draw2dimg" ) var snapFontData draw2d.FontData @@ -100,6 +100,7 @@ func snapchat_message(broker *tg.Broker, update tg.APIMessage) { timg := image.NewRGBA(image.Rect(0, 0, int(iwidth), int(iheight))) gc := draw2dimg.NewGraphicContext(timg) + gc.Emojis = emojis gc.SetFontData(snapFontData) gc.Save() diff --git a/mods/unsplash.go b/mods/unsplash.go index 7ed7333..2c5af44 100644 --- a/mods/unsplash.go +++ b/mods/unsplash.go @@ -12,10 +12,10 @@ import ( "os" "strings" + "git.fromouter.space/crunchy-rocks/draw2d" + "git.fromouter.space/crunchy-rocks/draw2d/draw2dimg" + "git.fromouter.space/crunchy-rocks/freetype" "git.fromouter.space/hamcha/tg" - "github.com/golang/freetype" - "github.com/llgcode/draw2d" - "github.com/llgcode/draw2d/draw2dimg" "github.com/disintegration/imaging" ) @@ -120,6 +120,7 @@ func unsplash_message(broker *tg.Broker, update tg.APIMessage) { timg := image.NewRGBA(bounds) gc := draw2dimg.NewGraphicContext(timg) + gc.Emojis = emojis gc.SetFontData(quoteFontData) gc.DrawImage(img) gc.SetStrokeColor(image.Black)