Add emoji support

This commit is contained in:
Hamcha 2018-11-16 12:27:42 +01:00
parent 63dd6b79c7
commit dfc3b5f2ba
Signed by: hamcha
GPG key ID: A40413D21021EAEE
5 changed files with 26 additions and 11 deletions

1
.gitignore vendored
View file

@ -6,3 +6,4 @@ clessy-stats
clessy-stats-import
stats-web/Chart.bundle.js
impact.ttf
noto_emojis

View file

@ -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()

View file

@ -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)

View file

@ -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()

View file

@ -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)