Add support for gif emus

This commit is contained in:
Peter Sanchez 2022-05-11 14:15:40 -06:00
parent 093eb20aee
commit cbeb18b3e7
3 changed files with 13 additions and 8 deletions

View File

@ -1166,7 +1166,7 @@ func jonkjonk(user *WhatAbout, h *Honk) (junk.Junk, junk.Junk) {
t["name"] = e.Name t["name"] = e.Name
i := junk.New() i := junk.New()
i["type"] = "Image" i["type"] = "Image"
i["mediaType"] = "image/png" i["mediaType"] = e.Type
i["url"] = e.ID i["url"] = e.ID
t["icon"] = i t["icon"] = i
tags = append(tags, t) tags = append(tags, t)
@ -1339,7 +1339,7 @@ func chonkifymsg(user *WhatAbout, ch *Chonk) []byte {
t["name"] = e.Name t["name"] = e.Name
i := junk.New() i := junk.New()
i["type"] = "Image" i["type"] = "Image"
i["mediaType"] = "image/png" i["mediaType"] = e.Type
i["url"] = e.ID i["url"] = e.ID
t["icon"] = i t["icon"] = i
tags = append(tags, t) tags = append(tags, t)

View File

@ -102,7 +102,7 @@ Image and video files are supported.
Add custom emus (emoji) to the Add custom emus (emoji) to the
.Pa emus .Pa emus
data directory. data directory.
PNG files are supported. PNG and GIF files are supported.
.Pp .Pp
Site CSS may be overridden by creating a Site CSS may be overridden by creating a
.Pa views/local.css .Pa views/local.css

13
fun.go
View File

@ -378,18 +378,23 @@ func bunchofgrapes(m []string) []Mention {
type Emu struct { type Emu struct {
ID string ID string
Name string Name string
Type string
} }
var re_emus = regexp.MustCompile(`:[[:alnum:]_-]+:`) var re_emus = regexp.MustCompile(`:[[:alnum:]_-]+:`)
var emucache = cache.New(cache.Options{Filler: func(ename string) (Emu, bool) { var emucache = cache.New(cache.Options{Filler: func(ename string) (Emu, bool) {
fname := ename[1 : len(ename)-1] fname := ename[1 : len(ename)-1]
_, err := os.Stat(dataDir + "/emus/" + fname + ".png") exts := []string{".png", ".gif"}
for _, ext := range exts {
_, err := os.Stat(dataDir + "/emus/" + fname + ext)
if err != nil { if err != nil {
return Emu{Name: ename, ID: ""}, true continue
} }
url := fmt.Sprintf("https://%s/emu/%s.png", serverName, fname) url := fmt.Sprintf("https://%s/emu/%s%s", serverName, fname, ext)
return Emu{ID: url, Name: ename}, true return Emu{ID: url, Name: ename, Type: "image/" + ext[1:]}, true
}
return Emu{Name: ename, ID: "", Type: "image/png"}, true
}, Duration: 10 * time.Second}) }, Duration: 10 * time.Second})
func herdofemus(noise string) []Emu { func herdofemus(noise string) []Emu {