From 227a6a38c478e1cc5d664c0c644af5c5131ae381 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Sun, 30 Jun 2019 19:04:37 -0400 Subject: [PATCH] remove inline meme text from post --- fun.go | 16 ++++++++-------- honk.go | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/fun.go b/fun.go index b0c280a..a044e84 100644 --- a/fun.go +++ b/fun.go @@ -192,10 +192,8 @@ func herdofemus(noise string) []Emu { var re_memes = regexp.MustCompile("meme: ?([[:alnum:]_.-]+)") -func memetics(noise string) []*Donk { - var donks []*Donk - m := re_memes.FindAllString(noise, -1) - for _, x := range m { +func memetize(honk *Honk) { + repl := func(x string) string { name := x[5:] if name[0] == ' ' { name = name[1:] @@ -203,7 +201,7 @@ func memetics(noise string) []*Donk { fd, err := os.Open("memes/" + name) if err != nil { log.Printf("no meme for %s", name) - continue + return x } var peek [512]byte n, _ := fd.Read(peek[:]) @@ -214,7 +212,7 @@ func memetics(noise string) []*Donk { res, err := stmtSaveFile.Exec("", name, url, ct, 0, "") if err != nil { log.Printf("error saving meme: %s", err) - continue + return x } var d Donk d.FileID, _ = res.LastInsertId() @@ -223,9 +221,11 @@ func memetics(noise string) []*Donk { d.Media = ct d.URL = url d.Local = false - donks = append(donks, &d) + honk.Donks = append(honk.Donks, &d) + log.Printf("replace with -") + return "" } - return donks + honk.Noise = re_memes.ReplaceAllStringFunc(honk.Noise, repl) } var re_bolder = regexp.MustCompile(`(^|\W)\*\*([\w\s,.!?'-]+)\*\*($|\W)`) diff --git a/honk.go b/honk.go index ce53333..50cf671 100644 --- a/honk.go +++ b/honk.go @@ -1047,7 +1047,7 @@ func savehonk(w http.ResponseWriter, r *http.Request) { honk.Donks = append(honk.Donks, donk) } } - honk.Donks = append(honk.Donks, memetics(honk.Noise)...) + memetize(&honk) aud := strings.Join(honk.Audience, " ") whofore := 2 @@ -1069,7 +1069,7 @@ func savehonk(w http.ResponseWriter, r *http.Request) { return } res, err := stmtSaveHonk.Exec(userinfo.UserID, what, honk.Honker, xid, rid, - dt.Format(dbtimeformat), "", aud, noise, convoy, whofore, "html", honk.Precis, honk.Oonker) + dt.Format(dbtimeformat), "", aud, honk.Noise, convoy, whofore, "html", honk.Precis, honk.Oonker) if err != nil { log.Printf("error saving honk: %s", err) return