mirror of
https://github.com/statbate/shiny-potato.git
synced 2026-08-11 03:12:42 +00:00
initial work
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
commit
2ef3e1fc8d
12 changed files with 1100 additions and 0 deletions
77
test/main.go
Normal file
77
test/main.go
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 4 {
|
||||
fmt.Println("./test room server proxy")
|
||||
return
|
||||
}
|
||||
|
||||
room := os.Args[1]
|
||||
server := os.Args[2]
|
||||
proxy := os.Args[3]
|
||||
|
||||
u, token, id := getToken(room)
|
||||
|
||||
startRoom(room, server, proxy, u, token, id)
|
||||
}
|
||||
|
||||
func getToken(room string) (*url.URL, string, string) {
|
||||
req, err := http.NewRequestWithContext(context.TODO(), http.MethodGet, "https://ru.stripchat.com/"+room, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
req.Header.Add("User-Agent", "Mozilla/5.0 (X11; Linux x86_64; rv:33.0) Gecko/20100101 Firefox/33.0")
|
||||
req.Header.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8")
|
||||
req.Header.Add("Accept-Language", "en-US,en;q=0.5")
|
||||
req.Header.Add("Connection", "keep-alive")
|
||||
req.Header.Add("Referer", "https://ru.stripchat.com")
|
||||
rsp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
} else if rsp.StatusCode != http.StatusOK {
|
||||
panic("failed to get rsp")
|
||||
}
|
||||
|
||||
defer rsp.Body.Close()
|
||||
|
||||
buf, err := ioutil.ReadAll(rsp.Body)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
re := regexp.MustCompile(`"websocketUrl":"*(.*?)\s*"`)
|
||||
m := re.FindSubmatch(buf)
|
||||
if len(m) != 2 {
|
||||
panic("not match")
|
||||
}
|
||||
r := bytes.ReplaceAll(m[1], []byte(`\u002F`), []byte(`/`))
|
||||
u, err := url.Parse(string(r))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
re = regexp.MustCompile(`"token":"*(.*?)\s*"`)
|
||||
m = re.FindSubmatch(buf)
|
||||
if len(m) != 2 {
|
||||
panic("not match")
|
||||
}
|
||||
|
||||
re = regexp.MustCompile(`img.strpst.com/thumbs/*(.*?)\s*"`)
|
||||
id := re.FindSubmatch(buf)
|
||||
if len(id) != 2 {
|
||||
panic("not match")
|
||||
}
|
||||
xid := string(id[1])
|
||||
return u, string(m[1]), xid[strings.Index(xid, "/")+1:]
|
||||
}
|
||||
142
test/worker.go
Normal file
142
test/worker.go
Normal file
|
|
@ -0,0 +1,142 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
var messages [][]byte
|
||||
|
||||
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-userBanned:XID","method":"PUT","url":"/front/clients/CLIENT_ID/subscriptions/userBanned:XID"}`))
|
||||
messages = append(messages, []byte(`{"id":"1660248194970-sub-goalChanged:XID","method":"PUT","url":"/front/clients/CLIENT_ID/subscriptions/goalChanged:XID"}`))
|
||||
messages = append(messages, []byte(`{"id":"1660248194970-sub-modelStatusChanged:XID","method":"PUT","url":"/front/clients/CLIENT_ID/subscriptions/modelStatusChanged:XID"}`))
|
||||
messages = append(messages, []byte(`{"id":"1660248194971-sub-broadcastSettingsChanged:XID","method":"PUT","url":"/front/clients/CLIENT_ID/subscriptions/broadcastSettingsChanged:XID"}`))
|
||||
messages = append(messages, []byte(`{"id":"1660248194971-sub-tipMenuUpdated:XID","method":"PUT","url":"/front/clients/CLIENT_ID/subscriptions/tipMenuUpdated:XID"}`))
|
||||
messages = append(messages, []byte(`{"id":"1660248194971-sub-topicChanged:XID","method":"PUT","url":"/front/clients/CLIENT_ID/subscriptions/topicChanged:XID"}`))
|
||||
messages = append(messages, []byte(`{"id":"1660248194971-sub-userUpdated:XID","method":"PUT","url":"/front/clients/CLIENT_ID/subscriptions/userUpdated:XID"}`))
|
||||
messages = append(messages, []byte(`{"id":"1660248194971-sub-interactiveToyStatusChanged:XID","method":"PUT","url":"/front/clients/CLIENT_ID/subscriptions/interactiveToyStatusChanged:XID"}`))
|
||||
messages = append(messages, []byte(`{"id":"1660248194971-sub-groupShow:XID","method":"PUT","url":"/front/clients/CLIENT_ID/subscriptions/groupShow:XID"}`))
|
||||
messages = append(messages, []byte(`{"id":"1660248194971-sub-deleteChatMessages:XID","method":"PUT","url":"/front/clients/CLIENT_ID/subscriptions/deleteChatMessages:XID"}`))
|
||||
messages = append(messages, []byte(`{"id":"1660248194971-sub-tipLeaderboardSettingsUpdated:XID","method":"PUT","url":"/front/clients/CLIENT_ID/subscriptions/tipLeaderboardSettingsUpdated:XID"}`))
|
||||
messages = append(messages, []byte(`{"id":"1660248194971-sub-modelAppUpdated:XID","method":"PUT","url":"/front/clients/CLIENT_ID/subscriptions/modelAppUpdated:XID"}`))
|
||||
messages = append(messages, []byte(`{"id":"1660248194972-sub-newKing:XID","method":"PUT","url":"/front/clients/CLIENT_ID/subscriptions/newKing:XID"}`))
|
||||
messages = append(messages, []byte(`{"id":"1660248194972-sub-privateMessageSettingsChanged:XID","method":"PUT","url":"/front/clients/CLIENT_ID/subscriptions/privateMessageSettingsChanged:XID"}`))
|
||||
messages = append(messages, []byte(`{"id":"1660248194972-sub-newChatMessage:XID","method":"PUT","url":"/front/clients/CLIENT_ID/subscriptions/newChatMessage:XID"}`))
|
||||
messages = append(messages, []byte(`{"id":"1660248194972-sub-fanClubUpdated:XID","method":"PUT","url":"/front/clients/CLIENT_ID/subscriptions/fanClubUpdated:XID"}`))
|
||||
messages = append(messages, []byte(`{"id":"1660248194972-sub-viewServerChanged:hls-07","method":"PUT","url":"/front/clients/CLIENT_ID/subscriptions/viewServerChanged:hls-07"}`))
|
||||
}
|
||||
|
||||
type ServerResponse struct {
|
||||
SubscriptionKey string `json:"subscriptionKey,omitempty"`
|
||||
Params struct {
|
||||
ClientId string `json:"clientId,omitempty"`
|
||||
Message struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
Userdata struct {
|
||||
Username string `json:"username,omitempty"`
|
||||
} `json:"userdata,omitempty"`
|
||||
Details struct {
|
||||
Amount float64 `json:"amount,omitempty"`
|
||||
LovenseDetails struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
Detail struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Amount float64 `json:"amount,omitempty"`
|
||||
} `json:"detail,omitempty"`
|
||||
} `json:"lovenseDetails"`
|
||||
} `json:"details,omitempty"`
|
||||
} `json:"message,omitempty"`
|
||||
} `json:"params,omitempty"`
|
||||
}
|
||||
|
||||
func startRoom(room, server, proxy string, u *url.URL, token string, id string) {
|
||||
// curl -vvv -X POST -H "Content-Type: application/x-www-form-urlencoded; charset=UTF-8" -H "X-Requested-With: XMLHttpRequest" -d "method=getRoomData" -d "args[]=Icehotangel" "https://rt.bongocams.com/tools/amf.php?res=771840&t=1654437233142"
|
||||
fmt.Printf("token %s id %s\n", token, id)
|
||||
fmt.Println("Start", room, "server", server, "proxy", proxy)
|
||||
|
||||
Dialer := *websocket.DefaultDialer
|
||||
|
||||
proxyMap := make(map[string]string)
|
||||
proxyMap["us"] = "aaa:port"
|
||||
proxyMap["fi"] = "bbb:port"
|
||||
|
||||
if _, ok := proxyMap[proxy]; ok {
|
||||
Dialer = websocket.Dialer{
|
||||
Proxy: http.ProxyURL(&url.URL{
|
||||
Scheme: "http", // or "https" depending on your proxy
|
||||
Host: proxyMap[proxy],
|
||||
Path: "/",
|
||||
}),
|
||||
HandshakeTimeout: 45 * time.Second, // https://pkg.go.dev/github.com/gorilla/websocket
|
||||
}
|
||||
}
|
||||
|
||||
c, _, err := Dialer.Dial(u.String(), nil)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
defer c.Close()
|
||||
|
||||
ws, _, err := Dialer.Dial("wss://websocket.stripchat.com/connection/websocket", nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer ws.Close()
|
||||
|
||||
for {
|
||||
_, message, err := c.ReadMessage()
|
||||
if err != nil {
|
||||
fmt.Println("return " + err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(string(message))
|
||||
|
||||
m := &ServerResponse{}
|
||||
|
||||
if err = json.Unmarshal(message, m); err != nil {
|
||||
fmt.Println(err.Error())
|
||||
continue
|
||||
}
|
||||
|
||||
if m.SubscriptionKey == "connected" {
|
||||
fmt.Println("connected")
|
||||
for _, msg := range messages {
|
||||
b := bytes.ReplaceAll(msg, []byte(`CLIENT_ID`), []byte(m.Params.ClientId))
|
||||
b = bytes.ReplaceAll(b, []byte(`XID`), []byte(id))
|
||||
if err = c.WriteMessage(websocket.TextMessage, b); err != nil {
|
||||
fmt.Println("return " + err.Error())
|
||||
return
|
||||
}
|
||||
}
|
||||
if err = ws.WriteMessage(websocket.TextMessage, []byte(fmt.Sprintf(`{"params":{"token":"%s","name":"js"},"id":1}`, token))); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
if !strings.Contains(m.SubscriptionKey, "newChatMessage") {
|
||||
continue
|
||||
}
|
||||
|
||||
fmt.Println("proper msg")
|
||||
|
||||
if m.Params.Message.Type == "lovense" {
|
||||
fmt.Println("donate")
|
||||
fmt.Println(m.Params.Message.Details.LovenseDetails.Detail.Name, " send ", m.Params.Message.Details.LovenseDetails.Detail.Amount, "tokens")
|
||||
} else if m.Params.Message.Type == "tip" {
|
||||
fmt.Println("donate")
|
||||
fmt.Println(m.Params.Message.Userdata.Username, " send ", m.Params.Message.Details.Amount, "tokens")
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue