From cbeb18b3e7475c7ea8dadf007fd80ec05e3ced79 Mon Sep 17 00:00:00 2001 From: Peter Sanchez Date: Wed, 11 May 2022 14:15:40 -0600 Subject: [PATCH] Add support for gif emus --- activity.go | 4 ++-- docs/honk.8 | 2 +- fun.go | 15 ++++++++++----- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/activity.go b/activity.go index 4ecfe73..c7f85e6 100644 --- a/activity.go +++ b/activity.go @@ -1166,7 +1166,7 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) { t["name"] = e.Name i := junk.New() i["type"] = "Image" - i["mediaType"] = "image/png" + i["mediaType"] = e.Type i["url"] = e.ID t["icon"] = i tags = append(tags, t) @@ -1339,7 +1339,7 @@ func chonkifymsg(user *WhatAbout, ch *Chonk) []byte { t["name"] = e.Name i := junk.New() i["type"] = "Image" - i["mediaType"] = "image/png" + i["mediaType"] = e.Type i["url"] = e.ID t["icon"] = i tags = append(tags, t) diff --git a/docs/honk.8 b/docs/honk.8 index c8364ea..8bb578d 100644 --- a/docs/honk.8 +++ b/docs/honk.8 @@ -102,7 +102,7 @@ Image and video files are supported. Add custom emus (emoji) to the .Pa emus data directory. -PNG files are supported. +PNG and GIF files are supported. .Pp Site CSS may be overridden by creating a .Pa views/local.css diff --git a/fun.go b/fun.go index 675a5df..e470957 100644 --- a/fun.go +++ b/fun.go @@ -378,18 +378,23 @@ func bunchofgrapes(m []string) []Mention { type Emu struct { ID string Name string + Type string } var re_emus = regexp.MustCompile(`:[[:alnum:]_-]+:`) var emucache = cache.New(cache.Options{Filler: func(ename string) (Emu, bool) { fname := ename[1 : len(ename)-1] - _, err := os.Stat(dataDir + "/emus/" + fname + ".png") - if err != nil { - return Emu{Name: ename, ID: ""}, true + exts := []string{".png", ".gif"} + for _, ext := range exts { + _, err := os.Stat(dataDir + "/emus/" + fname + ext) + if err != nil { + continue + } + url := fmt.Sprintf("https://%s/emu/%s%s", serverName, fname, ext) + return Emu{ID: url, Name: ename, Type: "image/" + ext[1:]}, true } - url := fmt.Sprintf("https://%s/emu/%s.png", serverName, fname) - return Emu{ID: url, Name: ename}, true + return Emu{Name: ename, ID: "", Type: "image/png"}, true }, Duration: 10 * time.Second}) func herdofemus(noise string) []Emu {