custom emus
This commit is contained in:
parent
75cd95d751
commit
f472979b2d
2
README
2
README
|
@ -8,6 +8,8 @@ evil empire.
|
||||||
Send honks. Receive honks. And not just honks.
|
Send honks. Receive honks. And not just honks.
|
||||||
Bonk, donk, tonk, all your favorite activities are here.
|
Bonk, donk, tonk, all your favorite activities are here.
|
||||||
|
|
||||||
|
Custom emus.
|
||||||
|
|
||||||
Purple color scheme.
|
Purple color scheme.
|
||||||
|
|
||||||
The button to submit a new honk says "it's gonna be honked".
|
The button to submit a new honk says "it's gonna be honked".
|
||||||
|
|
45
activity.go
45
activity.go
|
@ -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)
|
audience = append(audience, who)
|
||||||
|
|
||||||
|
@ -534,16 +548,29 @@ func jonkjonk(user *WhatAbout, h *Honk) (map[string]interface{}, map[string]inte
|
||||||
jo["cc"] = h.Audience[1:]
|
jo["cc"] = h.Audience[1:]
|
||||||
}
|
}
|
||||||
jo["content"] = h.Noise
|
jo["content"] = h.Noise
|
||||||
|
var tags []interface{}
|
||||||
g := bunchofgrapes(h.Noise)
|
g := bunchofgrapes(h.Noise)
|
||||||
if len(g) > 0 {
|
for _, m := range g {
|
||||||
var tags []interface{}
|
t := NewJunk()
|
||||||
for _, m := range g {
|
t["type"] = "Mention"
|
||||||
t := NewJunk()
|
t["name"] = m.who
|
||||||
t["type"] = "Mention"
|
t["href"] = m.where
|
||||||
t["name"] = m.who
|
tags = append(tags, t)
|
||||||
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
|
jo["tag"] = tags
|
||||||
}
|
}
|
||||||
var atts []interface{}
|
var atts []interface{}
|
||||||
|
|
41
honk.go
41
honk.go
|
@ -156,7 +156,23 @@ func reverbolate(honks []*Honk) {
|
||||||
h.URL = h.XID
|
h.URL = h.XID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
zap := make(map[*Donk]bool)
|
||||||
h.HTML = cleanstring(h.Noise)
|
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
|
return mentions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Emu struct {
|
||||||
|
ID string
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
var re_link = regexp.MustCompile(`https?://[^\s"]+[\w/)]`)
|
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 {
|
func obfusbreak(s string) string {
|
||||||
s = strings.TrimSpace(s)
|
s = strings.TrimSpace(s)
|
||||||
|
@ -1074,7 +1107,7 @@ func savehonker(w http.ResponseWriter, r *http.Request) {
|
||||||
func avatate(w http.ResponseWriter, r *http.Request) {
|
func avatate(w http.ResponseWriter, r *http.Request) {
|
||||||
n := r.FormValue("a")
|
n := r.FormValue("a")
|
||||||
a := avatar(n)
|
a := avatar(n)
|
||||||
w.Header().Set("Cache-Control", "max-age=76000")
|
w.Header().Set("Cache-Control", "max-age=432000")
|
||||||
w.Write(a)
|
w.Write(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1089,6 +1122,11 @@ func servehtml(w http.ResponseWriter, r *http.Request) {
|
||||||
log.Print(err)
|
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) {
|
func servefile(w http.ResponseWriter, r *http.Request) {
|
||||||
xid := mux.Vars(r)["xid"]
|
xid := mux.Vars(r)["xid"]
|
||||||
|
@ -1145,6 +1183,7 @@ func serve() {
|
||||||
getters.HandleFunc("/u/{name:[[:alnum:]]+}/outbox", outbox)
|
getters.HandleFunc("/u/{name:[[:alnum:]]+}/outbox", outbox)
|
||||||
getters.HandleFunc("/a", avatate)
|
getters.HandleFunc("/a", avatate)
|
||||||
getters.HandleFunc("/d/{xid:[[:alnum:].]+}", servefile)
|
getters.HandleFunc("/d/{xid:[[:alnum:].]+}", servefile)
|
||||||
|
getters.HandleFunc("/emu/{xid:[[:alnum:].]+}", serveemu)
|
||||||
getters.HandleFunc("/h/{name:[[:alnum:]]+}", viewhonker)
|
getters.HandleFunc("/h/{name:[[:alnum:]]+}", viewhonker)
|
||||||
getters.HandleFunc("/.well-known/webfinger", fingerlicker)
|
getters.HandleFunc("/.well-known/webfinger", fingerlicker)
|
||||||
|
|
||||||
|
|
|
@ -144,3 +144,9 @@ button a {
|
||||||
img {
|
img {
|
||||||
max-width: 100%
|
max-width: 100%
|
||||||
}
|
}
|
||||||
|
img.emu {
|
||||||
|
width: 1em;
|
||||||
|
height: 1em;
|
||||||
|
vertical-align: middle;
|
||||||
|
margin: -2px;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue