diff --git a/fun.go b/fun.go index f2e959b..5ae0941 100644 --- a/fun.go +++ b/fun.go @@ -62,6 +62,10 @@ func reverbolate(userid int64, honks []*Honk) { h.Style += " limited" } translate(h, false) + local := false + if (h.Whofore == 2 || h.Whofore == 3) || h.What != "bonked" { + local = true + } if h.Whofore == 2 || h.Whofore == 3 { h.URL = h.XID if h.What != "bonked" { @@ -130,6 +134,13 @@ func reverbolate(userid int64, honks []*Honk) { } } } + if local { + var emu Emu + emucache.Get(e, &emu) + if emu.ID != "" { + return fmt.Sprintf(``, emu.Name, emu.ID) + } + } return e } h.Precis = re_emus.ReplaceAllStringFunc(h.Precis, emuxifier) @@ -319,18 +330,27 @@ type Emu struct { 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 + } + url := fmt.Sprintf("https://%s/emu/%s.png", serverName, fname) + return Emu{ID: url, Name: ename}, true +}, Duration: 10 * time.Second}) + func herdofemus(noise string) []Emu { m := re_emus.FindAllString(noise, -1) m = oneofakind(m) var emus []Emu for _, e := range m { - fname := e[1 : len(e)-1] - _, err := os.Stat("emus/" + fname + ".png") - if err != nil { + var emu Emu + emucache.Get(e, &emu) + if emu.ID == "" { continue } - url := fmt.Sprintf("https://%s/emu/%s.png", serverName, fname) - emus = append(emus, Emu{ID: url, Name: e}) + emus = append(emus, emu) } return emus } diff --git a/web.go b/web.go index 12b04ff..ac964bf 100644 --- a/web.go +++ b/web.go @@ -1575,14 +1575,6 @@ func submithonk(w http.ResponseWriter, r *http.Request, isAPI bool) { log.Printf("can't find file: %s", xid) } } - herd := herdofemus(noise) - for _, e := range herd { - donk := savedonk(e.ID, e.Name, e.Name, "image/png", true) - if donk != nil { - donk.Name = e.Name - honk.Donks = append(honk.Donks, donk) - } - } memetize(honk) imaginate(honk)