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

View File

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

15
fun.go
View File

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