When a player's attendance is updated — either via email (awp-cli check) or via the web toggle — an email is sent to the GM with: - who changed, what they changed to, and how (email or the site) - a summary count of attending/not attending/no response - the full current player status list Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
75 lines
1.5 KiB
Go
75 lines
1.5 KiB
Go
package data
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
DATE_FORMAT string = "Monday Jan 2, 2006 3:04pm"
|
|
)
|
|
|
|
type Player struct {
|
|
Name string `json:"name"`
|
|
Attending string `json:"attending"`
|
|
ToggleUrl string `json:"-"`
|
|
Email string `json:"email"`
|
|
Gm bool `json:"gm"`
|
|
}
|
|
|
|
type Session struct {
|
|
Date string `json:"date"`
|
|
Players []Player `json:"players"`
|
|
IncrementDays int `json:"inc_days"`
|
|
Status string `json:"status"`
|
|
Password string `json:"password"`
|
|
}
|
|
|
|
func (s *Session) GMEmail() string {
|
|
for _, p := range s.Players {
|
|
if p.Gm {
|
|
return p.Email
|
|
}
|
|
}
|
|
return ""
|
|
}
|
|
|
|
func (s *Session) FormatStatusUpdate(playerName, newStatus, source string) (string, string) {
|
|
subject := fmt.Sprintf("Player Status Update: %s → %s", playerName, newStatus)
|
|
|
|
var yes, no, unknown int
|
|
for _, p := range s.Players {
|
|
switch p.Attending {
|
|
case "yes":
|
|
yes++
|
|
case "no":
|
|
no++
|
|
default:
|
|
unknown++
|
|
}
|
|
}
|
|
|
|
var sb strings.Builder
|
|
fmt.Fprintf(&sb, "%s has updated their status to %q (via %s).\n\n", playerName, newStatus, source)
|
|
fmt.Fprintf(&sb, "Attending: %d | Not attending: %d | No response: %d\n\n", yes, no, unknown)
|
|
sb.WriteString("Current player status:\n")
|
|
for _, p := range s.Players {
|
|
role := ""
|
|
if p.Gm {
|
|
role = " (GM)"
|
|
}
|
|
fmt.Fprintf(&sb, " %s%s: %s\n", p.Name, role, p.Attending)
|
|
}
|
|
|
|
return subject, sb.String()
|
|
}
|
|
|
|
func (s *Session) GetPlayerByEmail(addr string) *Player {
|
|
for i, p := range s.Players {
|
|
if addr == p.Email {
|
|
return &s.Players[i]
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|