mirror of
https://github.com/Luzifer/twitch-manager.git
synced 2024-11-09 18:00:05 +00:00
Allow to customize event parameters
Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
parent
35d70b5f7d
commit
276df367d7
1 changed files with 60 additions and 22 deletions
82
demo.go
82
demo.go
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
@ -21,16 +22,16 @@ func handleDemoAlert(w http.ResponseWriter, r *http.Request) {
|
||||||
case msgTypeBits:
|
case msgTypeBits:
|
||||||
data = map[string]interface{}{
|
data = map[string]interface{}{
|
||||||
"from": demoIssuer,
|
"from": demoIssuer,
|
||||||
"amount": 500,
|
"amount": demoGetParamInt(r, "amount", 500),
|
||||||
"message": "ShowLove500 Thanks for the Stream! myuserHype",
|
"message": demoGetParamStr(r, "message", "ShowLove500 Thanks for the Stream! myuserHype"),
|
||||||
"total_amount": 1337,
|
"total_amount": demoGetParamInt(r, "total_amount", 1337),
|
||||||
}
|
}
|
||||||
|
|
||||||
case msgTypeDonation:
|
case msgTypeDonation:
|
||||||
data = map[string]interface{}{
|
data = map[string]interface{}{
|
||||||
"name": demoIssuer,
|
"name": demoIssuer,
|
||||||
"amount": 6.66,
|
"amount": demoGetParamFloat(r, "amount", 6.66),
|
||||||
"message": "You rock!",
|
"message": demoGetParamStr(r, "message", "You rock!"),
|
||||||
}
|
}
|
||||||
|
|
||||||
case msgTypeFollow:
|
case msgTypeFollow:
|
||||||
|
@ -42,13 +43,13 @@ func handleDemoAlert(w http.ResponseWriter, r *http.Request) {
|
||||||
case msgTypeHost:
|
case msgTypeHost:
|
||||||
data = map[string]interface{}{
|
data = map[string]interface{}{
|
||||||
"from": demoIssuer,
|
"from": demoIssuer,
|
||||||
"viewerCount": 5,
|
"viewerCount": demoGetParamInt(r, "viewerCount", 5),
|
||||||
}
|
}
|
||||||
|
|
||||||
case msgTypeRaid:
|
case msgTypeRaid:
|
||||||
data = map[string]interface{}{
|
data = map[string]interface{}{
|
||||||
"from": demoIssuer,
|
"from": demoIssuer,
|
||||||
"viewerCount": 5,
|
"viewerCount": demoGetParamInt(r, "viewerCount", 5),
|
||||||
}
|
}
|
||||||
|
|
||||||
case msgTypeSub:
|
case msgTypeSub:
|
||||||
|
@ -56,10 +57,10 @@ func handleDemoAlert(w http.ResponseWriter, r *http.Request) {
|
||||||
"from": demoIssuer,
|
"from": demoIssuer,
|
||||||
"is_resub": false,
|
"is_resub": false,
|
||||||
"message": "",
|
"message": "",
|
||||||
"paid_for": "1",
|
"paid_for": demoGetParamInt(r, "paid_for", 1),
|
||||||
"streak": "1",
|
"streak": demoGetParamInt(r, "streak", 1),
|
||||||
"tier": "1000",
|
"tier": demoGetParamStr(r, "tier", "1000"),
|
||||||
"total": "1",
|
"total": 1,
|
||||||
}
|
}
|
||||||
|
|
||||||
case "resub": // Execption to the known types to trigger resubs
|
case "resub": // Execption to the known types to trigger resubs
|
||||||
|
@ -67,22 +68,22 @@ func handleDemoAlert(w http.ResponseWriter, r *http.Request) {
|
||||||
data = map[string]interface{}{
|
data = map[string]interface{}{
|
||||||
"from": demoIssuer,
|
"from": demoIssuer,
|
||||||
"is_resub": true,
|
"is_resub": true,
|
||||||
"message": "Already 12 months! PogChamp",
|
"message": demoGetParamStr(r, "message", "Already 12 months! PogChamp"),
|
||||||
"paid_for": "1",
|
"paid_for": demoGetParamInt(r, "paid_for", 1),
|
||||||
"streak": "12",
|
"streak": demoGetParamInt(r, "streak", 12),
|
||||||
"tier": "1000",
|
"tier": demoGetParamStr(r, "tier", "1000"),
|
||||||
"total": "12",
|
"total": demoGetParamInt(r, "total", 12),
|
||||||
}
|
}
|
||||||
|
|
||||||
case msgTypeSubGift:
|
case msgTypeSubGift:
|
||||||
data = map[string]interface{}{
|
data = map[string]interface{}{
|
||||||
"from": demoIssuer,
|
"from": demoIssuer,
|
||||||
"is_anon": false,
|
"is_anon": demoGetParamStr(r, "is_anon", "false") == "true",
|
||||||
"gift_to": "Tester",
|
"gift_to": demoGetParamStr(r, "gift_to", "Tester"),
|
||||||
"paid_for": 1,
|
"paid_for": demoGetParamInt(r, "paid_for", 1),
|
||||||
"streak": 1,
|
"streak": demoGetParamInt(r, "streak", 12),
|
||||||
"tier": "1000",
|
"tier": demoGetParamStr(r, "tier", "1000"),
|
||||||
"total": 1,
|
"total": demoGetParamInt(r, "total", 12),
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -97,3 +98,40 @@ func handleDemoAlert(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
w.WriteHeader(http.StatusCreated)
|
w.WriteHeader(http.StatusCreated)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func demoGetParamFloat(r *http.Request, key string, fallback float64) float64 {
|
||||||
|
v := r.FormValue(key)
|
||||||
|
if v == "" {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
vi, err := strconv.ParseFloat(v, 64)
|
||||||
|
if err != nil {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
return vi
|
||||||
|
}
|
||||||
|
|
||||||
|
func demoGetParamInt(r *http.Request, key string, fallback int) int {
|
||||||
|
v := r.FormValue(key)
|
||||||
|
if v == "" {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
vi, err := strconv.Atoi(v)
|
||||||
|
if err != nil {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
return vi
|
||||||
|
}
|
||||||
|
|
||||||
|
func demoGetParamStr(r *http.Request, key, fallback string) string {
|
||||||
|
v := r.FormValue(key)
|
||||||
|
if v == "" {
|
||||||
|
return fallback
|
||||||
|
}
|
||||||
|
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue