memes
This commit is contained in:
parent
600e6d47a3
commit
759f922736
39
fun.go
39
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?")
|
||||
|
|
13
honk.go
13
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(`<p><a href="%sd/%s">Attachment: %s</a>`,
|
||||
base, d.XID, html.EscapeString(d.Name))
|
||||
desc += fmt.Sprintf(`<p><a href="%s">Attachment: %s</a>`,
|
||||
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)
|
||||
|
|
|
@ -31,7 +31,15 @@ convoy: <a href="/t?c={{ .Convoy }}">{{ .Convoy }}</a>
|
|||
<p><a href="/d/{{ .XID }}"><img src="/d/{{ .XID }}" title="{{ .URL }}"></a>
|
||||
{{ end }}
|
||||
{{ else }}
|
||||
{{ if .XID }}
|
||||
<p><a href="{{ .URL }}">External Attachment: {{ .Name }}</a>
|
||||
{{ else }}
|
||||
{{ if eq .Media "video/mp4" }}
|
||||
<p><a href="{{ .URL }}"><video controls src="{{ .URL }}">{{ .Name }}</video></a>
|
||||
{{ else }}
|
||||
<p><a href="{{ .URL }}"><img src="{{ .URL }}" title="{{ .Name }}"></a>
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
{{ end }}
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue