handle user exit

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Vasiliy Tolstov 2022-08-12 14:21:57 +03:00
parent 64e2e8873c
commit 370e3bce07

View file

@ -6,6 +6,7 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"net/url" "net/url"
"strconv"
"strings" "strings"
"time" "time"
@ -14,6 +15,27 @@ import (
var messages [][]byte var messages [][]byte
type Amount struct {
value int
}
func (a Amount) Value() int {
return a.value
}
func (a *Amount) UnmarshalJSON(b []byte) error {
str := string(b)
s := 0
e := len(b)
if len(str) > 2 && str[0] == '"' && str[len(b)-1] == '"' {
s = 1
e = len(b) - 1
}
var err error
a.value, err = strconv.Atoi(str[s:e])
return err
}
func init() { func init() {
messages = append(messages, []byte(`{"id":"1660248194970-sub-lotteryChanged","method":"PUT","url":"/front/clients/CLIENT_ID/subscriptions/lotteryChanged"}`)) messages = append(messages, []byte(`{"id":"1660248194970-sub-lotteryChanged","method":"PUT","url":"/front/clients/CLIENT_ID/subscriptions/lotteryChanged"}`))
messages = append(messages, []byte(`{"id":"1660248194970-sub-userBanned:XID","method":"PUT","url":"/front/clients/CLIENT_ID/subscriptions/userBanned:XID"}`)) messages = append(messages, []byte(`{"id":"1660248194970-sub-userBanned:XID","method":"PUT","url":"/front/clients/CLIENT_ID/subscriptions/userBanned:XID"}`))
@ -37,7 +59,14 @@ func init() {
type ServerResponse struct { type ServerResponse struct {
SubscriptionKey string `json:"subscriptionKey,omitempty"` SubscriptionKey string `json:"subscriptionKey,omitempty"`
Params struct {
Params struct {
Model struct {
Status string `json:"status,omitempty"`
} `json:"model,omitempty"`
User struct {
Status string `json:"status,omitempty"`
} `json:"user,omitempty"`
ClientId string `json:"clientId,omitempty"` ClientId string `json:"clientId,omitempty"`
Message struct { Message struct {
Type string `json:"type,omitempty"` Type string `json:"type,omitempty"`
@ -45,12 +74,12 @@ type ServerResponse struct {
Username string `json:"username,omitempty"` Username string `json:"username,omitempty"`
} `json:"userdata,omitempty"` } `json:"userdata,omitempty"`
Details struct { Details struct {
Amount float64 `json:"amount,omitempty"` Amount Amount `json:"amount,omitempty"`
LovenseDetails struct { LovenseDetails struct {
Type string `json:"type,omitempty"` Type string `json:"type,omitempty"`
Detail struct { Detail struct {
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
Amount float64 `json:"amount,omitempty"` Amount Amount `json:"amount,omitempty"`
} `json:"detail,omitempty"` } `json:"detail,omitempty"`
} `json:"lovenseDetails"` } `json:"lovenseDetails"`
} `json:"details,omitempty"` } `json:"details,omitempty"`
@ -91,7 +120,7 @@ func startRoom(room, server, proxy string, u *url.URL, id string) {
for { for {
_, message, err := c.ReadMessage() _, message, err := c.ReadMessage()
if err != nil { if err != nil {
// fmt.Println("return " + err.Error()) fmt.Println("return " + err.Error())
return return
} }
@ -117,16 +146,27 @@ func startRoom(room, server, proxy string, u *url.URL, id string) {
} }
if strings.Contains(m.SubscriptionKey, "userUpdated") {
if m.Params.User.Status == "off" {
fmt.Println("user exiting")
return
}
} else if strings.Contains(m.SubscriptionKey, "modelStatusChanged") {
if m.Params.Model.Status == "off" {
fmt.Println("user exiting")
return
}
}
if !strings.Contains(m.SubscriptionKey, "newChatMessage") { if !strings.Contains(m.SubscriptionKey, "newChatMessage") {
continue continue
} }
if m.Params.Message.Type == "lovense" { if m.Params.Message.Type == "lovense" {
// fmt.Println("donate") // fmt.Println("donate")
fmt.Println(m.Params.Message.Details.LovenseDetails.Detail.Name, " send ", m.Params.Message.Details.LovenseDetails.Detail.Amount, "tokens") fmt.Println(m.Params.Message.Details.LovenseDetails.Detail.Name, " send ", m.Params.Message.Details.LovenseDetails.Detail.Amount.Value(), "tokens")
} else if m.Params.Message.Type == "tip" { } else if m.Params.Message.Type == "tip" {
// fmt.Println("donate") // fmt.Println("donate")
fmt.Println(m.Params.Message.Userdata.Username, " send ", m.Params.Message.Details.Amount, "tokens") fmt.Println(m.Params.Message.Userdata.Username, " send ", m.Params.Message.Details.Amount.Value(), "tokens")
} }
} }
} }