bel 2023-04-19 18:29:02 -06:00
commit 8eae7ae9a6
8 changed files with 96 additions and 26 deletions

View File

@ -15,6 +15,16 @@ type (
Players []configPlayer
Quiet bool
Broadcast configBroadcast
GM configGM
}
configGM struct {
Hotwords map[string]configGMHotword
}
configGMHotword struct {
Call string
Args []string
}
configBroadcast struct {

View File

@ -7,6 +7,7 @@ import (
"io"
"log"
"math/rand"
"mayhem-party/src/device/input/button"
"mayhem-party/src/device/input/wrap"
"net/http"
"os"
@ -178,7 +179,7 @@ func (v01 *V01) serveGM(w http.ResponseWriter, r *http.Request) {
case "/gm/rpc/status":
v01.serveGMStatus(w)
case "/gm/rpc/broadcastSomeoneSaidAlias":
v01.serveGMSomeoneSaidAlias(w, r)
v01.serveGMSomeoneSaid(w, r)
case "/gm/rpc/fillNonPlayerAliases":
v01.serveGMFillNonPlayerAliases(w, r)
case "/gm/rpc/vote":
@ -223,6 +224,30 @@ func (v01 *V01) serveGMStatus(w io.Writer) {
w.Write(b)
}
func (v01 *V01) serveGMSomeoneSaid(w http.ResponseWriter, r *http.Request) {
if gmHotword, ok := v01.cfg.GM.Hotwords[r.URL.Query().Get("message")]; ok {
v01.serveGMSomeoneSaidGMHotword(w, r, gmHotword)
}
v01.serveGMSomeoneSaidAlias(w, r)
}
func (v01 *V01) serveGMSomeoneSaidGMHotword(w http.ResponseWriter, r *http.Request, gmHotword configGMHotword) {
switch gmHotword.Call {
case "tap":
args := append([]string{}, gmHotword.Args...)
if len(args) < 1 || len(args[0]) < 1 {
return
}
btn := args[0][0]
go func() {
v01.alt <- []button.Button{button.Button{Down: true, Char: btn}}
v01.alt <- []button.Button{button.Button{Down: false, Char: btn}}
}()
default:
http.NotFound(w, r)
}
}
func (v01 *V01) serveGMSomeoneSaidAlias(w http.ResponseWriter, r *http.Request) {
v01.cfg.Quiet = true
for k, v := range v01.cfg.Users {

View File

@ -97,11 +97,7 @@ func TestServeGM(t *testing.T) {
v01 := NewV01(ctx, nil)
var result struct {
Players int `yaml:"Players"`
Users map[string]struct {
Player int
Lag string
IdleFor string `yaml:"idle_for"`
} `yaml:"Users"`
Users map[string]string `yaml:"Users"`
}
t.Run("empty", func(t *testing.T) {
@ -157,22 +153,46 @@ func TestServeGM(t *testing.T) {
if len(result.Users) != 7 {
t.Error(result.Users)
}
if d, err := time.ParseDuration(result.Users["bel"].Lag); err != nil {
t.Error(err)
} else if d != time.Second {
t.Error(d)
}
if d, err := time.ParseDuration(result.Users["bel"].IdleFor); err != nil {
t.Error(err)
} else if d < time.Minute || d > 2*time.Minute {
t.Error(d)
}
if result.Users["bel"].Player != 3 {
t.Error(result.Users["bel"].Player)
if result.Users["bel"] == "" || result.Users["bel"] == "..." {
t.Error(result.Users["bel"])
}
})
})
t.Run("broadcastSomeoneSaidAlias to hotword tap", func(t *testing.T) {
v01 := NewV01(ctx, nil)
v01.cfg.GM = configGM{
Hotwords: map[string]configGMHotword{
"hotword": configGMHotword{
Call: "tap",
Args: []string{"a"},
},
},
}
do(v01, "/gm/rpc/broadcastSomeoneSaidAlias?message=hotword", "")
for i := 0; i < 2; i++ {
select {
case btn := <-v01.alt:
if len(btn) != 1 {
t.Error(btn)
} else if btn[0].Down != (i == 0) {
t.Error(btn[0])
} else if btn[0].Char != 'a' {
t.Error(btn[0].Char)
}
case <-time.After(time.Second):
t.Fatal("nothing in alt")
}
}
do(v01, "/gm/rpc/broadcastSomeoneSaidAlias?message=hotword", "")
time.Sleep(time.Millisecond * 150)
if got := v01.Read(); len(got) != 1 || !got[0].Down || got[0].Char != 'a' {
t.Error(got)
} else if got := v01.Read(); len(got) != 1 || got[0].Down || got[0].Char != 'a' {
t.Error(got)
}
})
t.Run("broadcastSomeoneSaidAlias", func(t *testing.T) {
v01 := NewV01(ctx, nil)
v01.cfg.Quiet = false

View File

@ -18,3 +18,11 @@ players:
quiet: false
broadcast:
message: hi
gm:
hotwords:
coin:
call: tap
args: ['!']
star:
call: tap
args: ['?']

View File

@ -26,6 +26,7 @@ type (
src raw.Raw
cfg config
telemetryc chan message
alt chan []button.Button
}
)
@ -41,6 +42,7 @@ func NewV01(ctx context.Context, src raw.Raw) *V01 {
src: src,
cfg: cfg,
telemetryc: make(chan message),
alt: make(chan []button.Button, 2),
}
go result.listen()
go result.dotelemetry()
@ -58,6 +60,11 @@ func (v01 *V01) Close() {
}
func (v01 *V01) Read() []button.Button {
select {
case alt := <-v01.alt:
return alt
default:
}
line := v01.src.Read()
var msg message
if err := json.Unmarshal(line, &msg); err != nil {

View File

@ -38,9 +38,8 @@ if (key == requiredKey) {
});
function showSecrets() {
console.log("Hi")
var element = document.getElementById("konami")
console.log(element)
element.style = "display:block"
element.lastElementChild.src = "https://www.youtube.com/embed/V4oJ62xrFZo?autoplay=1"
var e = new Event("onKonami")
element.dispatchEvent(new Event("onKonami"))
}

View File

@ -3,7 +3,7 @@ function onYouTubeIframeAPIReady() {
var player;
player = new YT.Player('konami', {
videoId: '_cB8CE_Q3Yk', // 👈 video id.
videoId: 'V4oJ62xrFZo', // 👈 video id.
width: 560,
height: 316,
playerVars: {
@ -19,6 +19,7 @@ function onYouTubeIframeAPIReady() {
events: {
'onReady': function (e) {
e.target.setVolume(33); // For max value, set value to 100.
document.getElementById("konami").addEventListener("onKonami", () => {e.target.playVideo()})
}
}
});

View File

@ -3,6 +3,8 @@
<header>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/water.css@2/out/dark.css">
<script src="konami.js"></script>
<script src="lowerVolume.js"></script>
<script async src="https://www.youtube.com/iframe_api"></script>
<script>
function formsay(message) {
console.log(`say '${message}'`)
@ -110,9 +112,7 @@
</div>
<div id="ntfy"></div>
<div id="ws"></div>
<div id="konami" style="display:none">
<iframe width="560" height="315" src="https://www.youtube.com/embed/V4oJ62xrFZo" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>
</div>
<div id="konami" style="display:none"></div>
</body>
<footer>
<script>