2021-04-08 23:44:25 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2021-04-22 14:02:16 +00:00
|
|
|
"time"
|
2021-04-08 23:44:25 +00:00
|
|
|
|
|
|
|
"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,
|
2021-05-30 12:00:36 +00:00
|
|
|
"amount": 500,
|
|
|
|
"message": "ShowLove500 Thanks for the Stream! myuserHype",
|
2021-04-08 23:44:25 +00:00
|
|
|
"total_amount": 1337,
|
|
|
|
}
|
|
|
|
|
2021-05-04 17:13:08 +00:00
|
|
|
case msgTypeDonation:
|
|
|
|
data = map[string]interface{}{
|
|
|
|
"name": demoIssuer,
|
|
|
|
"amount": 6.66,
|
|
|
|
"message": "You rock!",
|
|
|
|
}
|
|
|
|
|
2021-04-22 14:02:16 +00:00
|
|
|
case msgTypeFollow:
|
|
|
|
data = map[string]interface{}{
|
|
|
|
"from": demoIssuer,
|
|
|
|
"followed_at": time.Now(),
|
|
|
|
}
|
|
|
|
|
2021-04-08 23:44:25 +00:00
|
|
|
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,
|
2021-05-27 22:29:50 +00:00
|
|
|
"message": "",
|
2021-04-08 23:44:25 +00:00
|
|
|
"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,
|
2021-05-27 22:29:50 +00:00
|
|
|
"message": "Already 12 months! PogChamp",
|
2021-04-08 23:44:25 +00:00
|
|
|
"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
|
|
|
|
}
|
|
|
|
|
2021-05-09 16:39:30 +00:00
|
|
|
if err := subscriptions.SendAllSockets(event, data, false, false); err != nil {
|
2021-04-08 23:44:25 +00:00
|
|
|
http.Error(w, errors.Wrap(err, "send to sockets").Error(), http.StatusInternalServerError)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
w.WriteHeader(http.StatusCreated)
|
|
|
|
}
|