add alt in fedi field
This commit is contained in:
parent
c01e3b3b88
commit
494985ed05
3 changed files with 55 additions and 38 deletions
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
@ -78,7 +79,13 @@ func handleHookCreateSwitch(h HookPayload) {
|
||||||
front = sw.Members[0]
|
front = sw.Members[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
go dsiApi.UpdateFrontField(front.Name)
|
extra := ""
|
||||||
|
alt, ok := fediAlts[front.Name]
|
||||||
|
if ok {
|
||||||
|
extra = fmt.Sprintf("%s (%s)", front.Name, alt)
|
||||||
|
}
|
||||||
|
|
||||||
|
go dsiApi.UpdateFrontField(front.Name + extra)
|
||||||
go promCountSwitches(h.SystemID, sw.Members)
|
go promCountSwitches(h.SystemID, sw.Members)
|
||||||
// TODO: discord nickname updates
|
// TODO: discord nickname updates
|
||||||
}
|
}
|
||||||
|
|
45
main.go
45
main.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
@ -10,9 +11,15 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
SigningToken = os.Getenv("SIGNING_TOKEN")
|
SigningToken = os.Getenv("SIGNING_TOKEN")
|
||||||
|
fediAlts = map[string]string{}
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
err := json.Unmarshal([]byte(os.Getenv("FEDI_ALTS")), &fediAlts)
|
||||||
|
if err != nil {
|
||||||
|
log.Println("fedi alts map failed to parse", err)
|
||||||
|
}
|
||||||
|
|
||||||
listenAddr := os.Getenv("LISTEN_ADDR")
|
listenAddr := os.Getenv("LISTEN_ADDR")
|
||||||
if listenAddr == "" {
|
if listenAddr == "" {
|
||||||
listenAddr = "0.0.0.0:8555"
|
listenAddr = "0.0.0.0:8555"
|
||||||
|
@ -30,48 +37,12 @@ func main() {
|
||||||
mux.Handle("/metrics", promhttp.Handler())
|
mux.Handle("/metrics", promhttp.Handler())
|
||||||
|
|
||||||
log.Println("[main] http server listening on", listenAddr)
|
log.Println("[main] http server listening on", listenAddr)
|
||||||
err := http.ListenAndServe(listenAddr, mux)
|
err = http.ListenAndServe(listenAddr, mux)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln("[main] http server errored", err)
|
log.Fatalln("[main] http server errored", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func errMethodNotAllowed(rw http.ResponseWriter) {
|
|
||||||
rw.Header().Add("content-type", "text/plain")
|
|
||||||
rw.WriteHeader(http.StatusMethodNotAllowed)
|
|
||||||
rw.Write([]byte("405 Method Not Allowed"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func errStatusInternalServerError(rw http.ResponseWriter) {
|
|
||||||
rw.Header().Add("content-type", "text/plain")
|
|
||||||
rw.WriteHeader(http.StatusInternalServerError)
|
|
||||||
rw.Write([]byte("500 Internal Server Error"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func errUnauthorized(rw http.ResponseWriter) {
|
|
||||||
rw.Header().Add("content-type", "text/plain")
|
|
||||||
rw.WriteHeader(http.StatusUnauthorized)
|
|
||||||
rw.Write([]byte("401 Unauthorized"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func errBadRequest(rw http.ResponseWriter) {
|
|
||||||
rw.Header().Add("content-type", "text/plain")
|
|
||||||
rw.WriteHeader(http.StatusBadRequest)
|
|
||||||
rw.Write([]byte("401 Bad Request"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func basicOk(rw http.ResponseWriter) {
|
|
||||||
rw.Header().Add("content-type", "text/plain")
|
|
||||||
rw.WriteHeader(http.StatusOK)
|
|
||||||
rw.Write([]byte("200 Aight Request"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func basicNoContent(rw http.ResponseWriter) {
|
|
||||||
rw.Header().Add("content-type", "text/plain")
|
|
||||||
rw.WriteHeader(http.StatusNoContent)
|
|
||||||
rw.Write([]byte("204 No Content (debug: likely not handled)"))
|
|
||||||
}
|
|
||||||
|
|
||||||
func getHealthcheck(rw http.ResponseWriter, req *http.Request) {
|
func getHealthcheck(rw http.ResponseWriter, req *http.Request) {
|
||||||
_, err := pkApi.GetMember("iodbz")
|
_, err := pkApi.GetMember("iodbz")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
39
responses.go
Normal file
39
responses.go
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "net/http"
|
||||||
|
|
||||||
|
func errMethodNotAllowed(rw http.ResponseWriter) {
|
||||||
|
rw.Header().Add("content-type", "text/plain")
|
||||||
|
rw.WriteHeader(http.StatusMethodNotAllowed)
|
||||||
|
rw.Write([]byte("405 Method Not Allowed"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func errStatusInternalServerError(rw http.ResponseWriter) {
|
||||||
|
rw.Header().Add("content-type", "text/plain")
|
||||||
|
rw.WriteHeader(http.StatusInternalServerError)
|
||||||
|
rw.Write([]byte("500 Internal Server Error"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func errUnauthorized(rw http.ResponseWriter) {
|
||||||
|
rw.Header().Add("content-type", "text/plain")
|
||||||
|
rw.WriteHeader(http.StatusUnauthorized)
|
||||||
|
rw.Write([]byte("401 Unauthorized"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func errBadRequest(rw http.ResponseWriter) {
|
||||||
|
rw.Header().Add("content-type", "text/plain")
|
||||||
|
rw.WriteHeader(http.StatusBadRequest)
|
||||||
|
rw.Write([]byte("401 Bad Request"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func basicOk(rw http.ResponseWriter) {
|
||||||
|
rw.Header().Add("content-type", "text/plain")
|
||||||
|
rw.WriteHeader(http.StatusOK)
|
||||||
|
rw.Write([]byte("200 Aight Request"))
|
||||||
|
}
|
||||||
|
|
||||||
|
func basicNoContent(rw http.ResponseWriter) {
|
||||||
|
rw.Header().Add("content-type", "text/plain")
|
||||||
|
rw.WriteHeader(http.StatusNoContent)
|
||||||
|
rw.Write([]byte("204 No Content (debug: likely not handled)"))
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue