mirror of
https://github.com/Luzifer/twitch-manager.git
synced 2024-12-21 04:11:17 +00:00
Add demo-alert endpoint
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
65af5de2e1
commit
6e62d32832
2 changed files with 83 additions and 0 deletions
1
api.go
1
api.go
|
@ -101,6 +101,7 @@ var upgrader = websocket.Upgrader{
|
||||||
func registerAPI(r *mux.Router) {
|
func registerAPI(r *mux.Router) {
|
||||||
r.HandleFunc("/api/custom-alert", handleCustomAlert).Methods(http.MethodPost)
|
r.HandleFunc("/api/custom-alert", handleCustomAlert).Methods(http.MethodPost)
|
||||||
r.HandleFunc("/api/custom-event", handleCustomEvent).Methods(http.MethodPost)
|
r.HandleFunc("/api/custom-event", handleCustomEvent).Methods(http.MethodPost)
|
||||||
|
r.HandleFunc("/api/demo/{event}", handleDemoAlert).Methods(http.MethodPut)
|
||||||
r.HandleFunc("/api/follows/clear-last", handleSetLastFollower).Methods(http.MethodPut)
|
r.HandleFunc("/api/follows/clear-last", handleSetLastFollower).Methods(http.MethodPut)
|
||||||
r.HandleFunc("/api/follows/set-last/{name}", handleSetLastFollower).Methods(http.MethodPut)
|
r.HandleFunc("/api/follows/set-last/{name}", handleSetLastFollower).Methods(http.MethodPut)
|
||||||
r.HandleFunc("/api/subscribe", handleUpdateSocket).Methods(http.MethodGet)
|
r.HandleFunc("/api/subscribe", handleUpdateSocket).Methods(http.MethodGet)
|
||||||
|
|
82
demo.go
Normal file
82
demo.go
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gorilla/mux"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
const demoIssuer = "Twitch-Manager"
|
||||||
|
|
||||||
|
func handleDemoAlert(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var (
|
||||||
|
vars = mux.Vars(r)
|
||||||
|
event = vars["event"]
|
||||||
|
data interface{}
|
||||||
|
)
|
||||||
|
|
||||||
|
switch event {
|
||||||
|
case msgTypeBits:
|
||||||
|
data = map[string]interface{}{
|
||||||
|
"from": demoIssuer,
|
||||||
|
"amount": 5,
|
||||||
|
"total_amount": 1337,
|
||||||
|
}
|
||||||
|
|
||||||
|
case msgTypeHost:
|
||||||
|
data = map[string]interface{}{
|
||||||
|
"from": demoIssuer,
|
||||||
|
"viewerCount": 5,
|
||||||
|
}
|
||||||
|
|
||||||
|
case msgTypeRaid:
|
||||||
|
data = map[string]interface{}{
|
||||||
|
"from": demoIssuer,
|
||||||
|
"viewerCount": 5,
|
||||||
|
}
|
||||||
|
|
||||||
|
case msgTypeSub:
|
||||||
|
data = map[string]interface{}{
|
||||||
|
"from": demoIssuer,
|
||||||
|
"is_resub": false,
|
||||||
|
"paid_for": "1",
|
||||||
|
"streak": "1",
|
||||||
|
"tier": "1000",
|
||||||
|
"total": "1",
|
||||||
|
}
|
||||||
|
|
||||||
|
case "resub": // Execption to the known types to trigger resubs
|
||||||
|
event = msgTypeSub
|
||||||
|
data = map[string]interface{}{
|
||||||
|
"from": demoIssuer,
|
||||||
|
"is_resub": true,
|
||||||
|
"paid_for": "1",
|
||||||
|
"streak": "12",
|
||||||
|
"tier": "1000",
|
||||||
|
"total": "12",
|
||||||
|
}
|
||||||
|
|
||||||
|
case msgTypeSubGift:
|
||||||
|
data = map[string]interface{}{
|
||||||
|
"from": demoIssuer,
|
||||||
|
"is_anon": false,
|
||||||
|
"gift_to": "Tester",
|
||||||
|
"paid_for": 1,
|
||||||
|
"streak": 1,
|
||||||
|
"tier": "1000",
|
||||||
|
"total": 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
http.Error(w, "Event not found", http.StatusNotFound)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := subscriptions.SendAllSockets(event, data); err != nil {
|
||||||
|
http.Error(w, errors.Wrap(err, "send to sockets").Error(), http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
w.WriteHeader(http.StatusCreated)
|
||||||
|
}
|
Loading…
Reference in a new issue