verbose user feedback

master
bel 2023-04-02 10:56:35 -06:00
parent 342e2eef93
commit 0903c01b9a
2 changed files with 40 additions and 26 deletions

View File

@ -92,7 +92,13 @@ func (v01 *V01) getUserFeedback(w http.ResponseWriter, r *http.Request) {
msg = fmt.Sprintf("%s (Your secret word is '%s'. Make **someone else** say it!)", msg, alias)
}
w.Write([]byte(msg))
w.Write([]byte(msg + "\n\n"))
v01.serveGMStatus(w)
if v01.cfg.Quiet {
w.Write([]byte("\n\n"))
v01.serveGMVoteRead(w)
}
}
func (v01 *V01) servePutBroadcast(w http.ResponseWriter, r *http.Request) {
@ -170,7 +176,7 @@ func (v01 *V01) serveGlobalQueryRefresh(r *http.Request) {
func (v01 *V01) serveGM(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/gm/rpc/status":
v01.serveGMStatus(w, r)
v01.serveGMStatus(w)
case "/gm/rpc/broadcastSomeoneSaidAlias":
v01.serveGMSomeoneSaidAlias(w, r)
case "/gm/rpc/fillNonPlayerAliases":
@ -192,7 +198,7 @@ func (v01 *V01) serveGM(w http.ResponseWriter, r *http.Request) {
}
}
func (v01 *V01) serveGMStatus(w http.ResponseWriter, r *http.Request) {
func (v01 *V01) serveGMStatus(w io.Writer) {
users := map[string]struct {
Lag time.Duration `yaml:"lag,omitempty"`
Player int `yaml:"player,omitempty"`
@ -291,6 +297,13 @@ func (v01 *V01) serveGMElect(w http.ResponseWriter, r *http.Request) {
func (v01 *V01) serveGMVote(w http.ResponseWriter, r *http.Request) {
switch r.URL.Query().Get("payload") {
case "":
v01.serveGMVoteRead(w)
default:
v01.serveGMVoteWrite(w, r)
}
}
func (v01 *V01) serveGMVoteRead(w io.Writer) {
counts := map[string]string{}
for k, v := range v01.cfg.Users {
if v.State.GM.Vote != "" {
@ -300,7 +313,9 @@ func (v01 *V01) serveGMVote(w http.ResponseWriter, r *http.Request) {
}
}
yaml.NewEncoder(w).Encode(counts)
default:
}
func (v01 *V01) serveGMVoteWrite(w http.ResponseWriter, r *http.Request) {
voter := r.URL.Query().Get("user")
candidate := r.URL.Query().Get("payload")
v, ok := v01.cfg.Users[voter]
@ -310,7 +325,6 @@ func (v01 *V01) serveGMVote(w http.ResponseWriter, r *http.Request) {
}
v.State.GM.Vote = candidate
v01.cfg.Users[voter] = v
}
}
func (v01 *V01) serveGMShuffle(r *http.Request) {

View File

@ -123,8 +123,8 @@ func TestV01Feedback(t *testing.T) {
}
defer resp.Body.Close()
b, _ := io.ReadAll(resp.Body)
if string(b) != "to bel" {
t.Error(b)
if !strings.HasPrefix(string(b), "to bel") {
t.Error(string(b))
}
})
@ -135,8 +135,8 @@ func TestV01Feedback(t *testing.T) {
}
defer resp.Body.Close()
b, _ := io.ReadAll(resp.Body)
if string(b) != "to everyone" {
t.Error(b)
if !strings.HasPrefix(string(b), "to everyone") {
t.Error(string(b))
}
})
@ -155,7 +155,7 @@ func TestV01Feedback(t *testing.T) {
}
defer resp.Body.Close()
b, _ := io.ReadAll(resp.Body)
if string(b) != want {
if !strings.HasPrefix(string(b), want) {
t.Error(string(b))
}
})