remove inline meme text from post

This commit is contained in:
Ted Unangst 2019-06-30 19:04:37 -04:00
parent 2a440560d9
commit 227a6a38c4
2 changed files with 10 additions and 10 deletions

16
fun.go
View File

@ -192,10 +192,8 @@ func herdofemus(noise string) []Emu {
var re_memes = regexp.MustCompile("meme: ?([[:alnum:]_.-]+)") var re_memes = regexp.MustCompile("meme: ?([[:alnum:]_.-]+)")
func memetics(noise string) []*Donk { func memetize(honk *Honk) {
var donks []*Donk repl := func(x string) string {
m := re_memes.FindAllString(noise, -1)
for _, x := range m {
name := x[5:] name := x[5:]
if name[0] == ' ' { if name[0] == ' ' {
name = name[1:] name = name[1:]
@ -203,7 +201,7 @@ func memetics(noise string) []*Donk {
fd, err := os.Open("memes/" + name) fd, err := os.Open("memes/" + name)
if err != nil { if err != nil {
log.Printf("no meme for %s", name) log.Printf("no meme for %s", name)
continue return x
} }
var peek [512]byte var peek [512]byte
n, _ := fd.Read(peek[:]) n, _ := fd.Read(peek[:])
@ -214,7 +212,7 @@ func memetics(noise string) []*Donk {
res, err := stmtSaveFile.Exec("", name, url, ct, 0, "") res, err := stmtSaveFile.Exec("", name, url, ct, 0, "")
if err != nil { if err != nil {
log.Printf("error saving meme: %s", err) log.Printf("error saving meme: %s", err)
continue return x
} }
var d Donk var d Donk
d.FileID, _ = res.LastInsertId() d.FileID, _ = res.LastInsertId()
@ -223,9 +221,11 @@ func memetics(noise string) []*Donk {
d.Media = ct d.Media = ct
d.URL = url d.URL = url
d.Local = false 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)`) var re_bolder = regexp.MustCompile(`(^|\W)\*\*([\w\s,.!?'-]+)\*\*($|\W)`)

View File

@ -1047,7 +1047,7 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
honk.Donks = append(honk.Donks, donk) honk.Donks = append(honk.Donks, donk)
} }
} }
honk.Donks = append(honk.Donks, memetics(honk.Noise)...) memetize(&honk)
aud := strings.Join(honk.Audience, " ") aud := strings.Join(honk.Audience, " ")
whofore := 2 whofore := 2
@ -1069,7 +1069,7 @@ func savehonk(w http.ResponseWriter, r *http.Request) {
return return
} }
res, err := stmtSaveHonk.Exec(userinfo.UserID, what, honk.Honker, xid, rid, 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 { if err != nil {
log.Printf("error saving honk: %s", err) log.Printf("error saving honk: %s", err)
return return