custom emus

This commit is contained in:
Ted Unangst 2019-04-12 15:02:56 -04:00
parent 75cd95d751
commit f472979b2d
4 changed files with 84 additions and 10 deletions

2
README
View File

@ -8,6 +8,8 @@ evil empire.
Send honks. Receive honks. And not just honks.
Bonk, donk, tonk, all your favorite activities are here.
Custom emus.
Purple color scheme.
The button to submit a new honk says "it's gonna be honked".

View File

@ -433,6 +433,20 @@ func xonkxonk(item interface{}) *Honk {
}
}
}
tags, _ := jsongetarray(obj, "tag")
for _, tag := range tags {
tt, _ := jsongetstring(tag, "type")
name, _ := jsongetstring(tag, "name")
if tt == "Emoji" {
icon, _ := jsongetmap(tag, "icon")
mt, _ := jsongetstring(icon, "mediaType")
u, _ := jsongetstring(icon, "url")
donk := savedonk(u, name, mt)
if donk != nil {
xonk.Donks = append(xonk.Donks, donk)
}
}
}
}
audience = append(audience, who)
@ -534,9 +548,8 @@ func jonkjonk(user *WhatAbout, h *Honk) (map[string]interface{}, map[string]inte
jo["cc"] = h.Audience[1:]
}
jo["content"] = h.Noise
g := bunchofgrapes(h.Noise)
if len(g) > 0 {
var tags []interface{}
g := bunchofgrapes(h.Noise)
for _, m := range g {
t := NewJunk()
t["type"] = "Mention"
@ -544,6 +557,20 @@ func jonkjonk(user *WhatAbout, h *Honk) (map[string]interface{}, map[string]inte
t["href"] = m.where
tags = append(tags, t)
}
herd := herdofemus(h.Noise)
for _, e := range herd {
t := NewJunk()
t["id"] = e.ID
t["type"] = "Emoji"
t["name"] = e.Name
i := NewJunk()
i["type"] = "Image"
i["mediaType"] = "image/png"
i["url"] = e.ID
t["icon"] = i
tags = append(tags, t)
}
if len(tags) > 0 {
jo["tag"] = tags
}
var atts []interface{}

41
honk.go
View File

@ -156,7 +156,23 @@ func reverbolate(honks []*Honk) {
h.URL = h.XID
}
}
zap := make(map[*Donk]bool)
h.HTML = cleanstring(h.Noise)
emuxifier := func(e string) string {
for _, d := range h.Donks {
if d.Name == e {
zap[d] = true
return fmt.Sprintf(`<img class="emu" title="%s" src="/d/%s">`, d.Name, d.XID)
}
}
return e
}
h.HTML = template.HTML(re_emus.ReplaceAllStringFunc(string(h.HTML), emuxifier))
for i := 0; i < len(h.Donks); i++ {
if zap[h.Donks[i]] {
h.Donks = append(h.Donks[0:i], h.Donks[i+1:]...)
}
}
}
}
@ -798,7 +814,24 @@ func bunchofgrapes(s string) []Mention {
return mentions
}
type Emu struct {
ID string
Name string
}
var re_link = regexp.MustCompile(`https?://[^\s"]+[\w/)]`)
var re_emus = regexp.MustCompile(`:[[:alnum:]_]+:`)
func herdofemus(noise string) []Emu {
m := re_emus.FindAllString(noise, -1)
var emus []Emu
for _, e := range m {
fname := e[1 : len(e)-1]
url := fmt.Sprintf("https://%s/emu/%s.png", serverName, fname)
emus = append(emus, Emu{ID: url, Name: e})
}
return emus
}
func obfusbreak(s string) string {
s = strings.TrimSpace(s)
@ -1074,7 +1107,7 @@ func savehonker(w http.ResponseWriter, r *http.Request) {
func avatate(w http.ResponseWriter, r *http.Request) {
n := r.FormValue("a")
a := avatar(n)
w.Header().Set("Cache-Control", "max-age=76000")
w.Header().Set("Cache-Control", "max-age=432000")
w.Write(a)
}
@ -1089,6 +1122,11 @@ func servehtml(w http.ResponseWriter, r *http.Request) {
log.Print(err)
}
}
func serveemu(w http.ResponseWriter, r *http.Request) {
xid := mux.Vars(r)["xid"]
w.Header().Set("Cache-Control", "max-age=432000")
http.ServeFile(w, r, "emus/"+xid)
}
func servefile(w http.ResponseWriter, r *http.Request) {
xid := mux.Vars(r)["xid"]
@ -1145,6 +1183,7 @@ func serve() {
getters.HandleFunc("/u/{name:[[:alnum:]]+}/outbox", outbox)
getters.HandleFunc("/a", avatate)
getters.HandleFunc("/d/{xid:[[:alnum:].]+}", servefile)
getters.HandleFunc("/emu/{xid:[[:alnum:].]+}", serveemu)
getters.HandleFunc("/h/{name:[[:alnum:]]+}", viewhonker)
getters.HandleFunc("/.well-known/webfinger", fingerlicker)

View File

@ -144,3 +144,9 @@ button a {
img {
max-width: 100%
}
img.emu {
width: 1em;
height: 1em;
vertical-align: middle;
margin: -2px;
}