diff --git a/fun.go b/fun.go index 0ceb202..e775f63 100644 --- a/fun.go +++ b/fun.go @@ -23,6 +23,7 @@ import ( "html/template" "log" "net/http" + "os" "regexp" "strings" "sync" @@ -182,6 +183,44 @@ func herdofemus(noise string) []Emu { return emus } +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 { + name := x[5:] + if name[0] == ' ' { + name = name[1:] + } + fd, err := os.Open("memes/" + name) + if err != nil { + log.Printf("no meme for %s", name) + continue + } + var peek [512]byte + n, _ := fd.Read(peek[:]) + ct := http.DetectContentType(peek[:n]) + fd.Close() + + url := fmt.Sprintf("https://%s/meme/%s", serverName, name) + res, err := stmtSaveFile.Exec("", name, url, ct, 0, "") + if err != nil { + log.Printf("error saving meme: %s", err) + continue + } + var d Donk + d.FileID, _ = res.LastInsertId() + d.XID = "" + d.Name = name + d.Media = ct + d.URL = url + d.Local = false + donks = append(donks, &d) + } + return donks +} + var re_bolder = regexp.MustCompile(`(^|\W)\*\*([\w\s,.!?'-]+)\*\*($|\W)`) var re_italicer = regexp.MustCompile(`(^|\W)\*([\w\s,.!?'-]+)\*($|\W)`) var re_bigcoder = regexp.MustCompile("```\n?((?s:.*?))\n?```\n?") diff --git a/honk.go b/honk.go index 369bf48..5940e67 100644 --- a/honk.go +++ b/honk.go @@ -183,8 +183,8 @@ func showrss(w http.ResponseWriter, r *http.Request) { for _, honk := range honks { desc := string(honk.HTML) for _, d := range honk.Donks { - desc += fmt.Sprintf(`
Attachment: %s`, - base, d.XID, html.EscapeString(d.Name)) + desc += fmt.Sprintf(`
Attachment: %s`, + d.URL, html.EscapeString(d.Name)) } feed.Items = append(feed.Items, &rss.Item{ @@ -919,6 +919,7 @@ func savehonk(w http.ResponseWriter, r *http.Request) { honk.Donks = append(honk.Donks, donk) } } + honk.Donks = append(honk.Donks, memetics(honk.Noise)...) aud := strings.Join(honk.Audience, " ") whofore := 2 @@ -1210,6 +1211,11 @@ func serveemu(w http.ResponseWriter, r *http.Request) { w.Header().Set("Cache-Control", "max-age="+somedays()) http.ServeFile(w, r, "emus/"+xid) } +func servememe(w http.ResponseWriter, r *http.Request) { + xid := mux.Vars(r)["xid"] + w.Header().Set("Cache-Control", "max-age="+somedays()) + http.ServeFile(w, r, "memes/"+xid) +} func servefile(w http.ResponseWriter, r *http.Request) { xid := mux.Vars(r)["xid"] @@ -1278,7 +1284,8 @@ func serve() { getters.HandleFunc("/a", avatate) getters.HandleFunc("/t", showconvoy) getters.HandleFunc("/d/{xid:[[:alnum:].]+}", servefile) - getters.HandleFunc("/emu/{xid:[[:alnum:]_.]+}", serveemu) + getters.HandleFunc("/emu/{xid:[[:alnum:]_.-]+}", serveemu) + getters.HandleFunc("/meme/{xid:[[:alnum:]_.-]+}", servememe) getters.HandleFunc("/.well-known/webfinger", fingerlicker) getters.HandleFunc("/style.css", servecss) diff --git a/views/honk.html b/views/honk.html index 71d9449..234a3d8 100644 --- a/views/honk.html +++ b/views/honk.html @@ -31,7 +31,15 @@ convoy: {{ .Convoy }}
{{ end }} {{ else }} +{{ if .XID }}
External Attachment: {{ .Name }} +{{ else }} +{{ if eq .Media "video/mp4" }} +