mirror of
https://github.com/statbate/special-pancake.git
synced 2026-08-11 03:12:42 +00:00
update
This commit is contained in:
parent
fd9906d0c1
commit
a95e549f4d
3 changed files with 33 additions and 7 deletions
16
app/main.go
16
app/main.go
|
|
@ -29,6 +29,8 @@ var (
|
||||||
|
|
||||||
json = jsoniter.ConfigCompatibleWithStandardLibrary
|
json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||||
|
|
||||||
|
socketServer = make(chan []byte, 100)
|
||||||
|
|
||||||
save = make(chan saveData, 100)
|
save = make(chan saveData, 100)
|
||||||
slog = make(chan saveLog, 100)
|
slog = make(chan saveLog, 100)
|
||||||
|
|
||||||
|
|
@ -54,6 +56,7 @@ func main() {
|
||||||
go announceCount()
|
go announceCount()
|
||||||
go saveDB()
|
go saveDB()
|
||||||
go saveLogs()
|
go saveLogs()
|
||||||
|
go socketHandler()
|
||||||
|
|
||||||
http.HandleFunc("/cmd/", cmdHandler)
|
http.HandleFunc("/cmd/", cmdHandler)
|
||||||
http.HandleFunc("/list/", listHandler)
|
http.HandleFunc("/list/", listHandler)
|
||||||
|
|
@ -88,6 +91,19 @@ func initClickhouse() {
|
||||||
Clickhouse = db
|
Clickhouse = db
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func socketHandler() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case b := <-socketServer:
|
||||||
|
conn, err := net.Dial("unix", "/tmp/echo.sock")
|
||||||
|
if err == nil {
|
||||||
|
conn.Write(b)
|
||||||
|
conn.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func randInt(min int, max int) int {
|
func randInt(min int, max int) int {
|
||||||
return min + rand.Intn(max-min)
|
return min + rand.Intn(max-min)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
12
app/save.go
12
app/save.go
|
|
@ -131,16 +131,18 @@ func saveDB() {
|
||||||
|
|
||||||
if m.Amount > 99 {
|
if m.Amount > 99 {
|
||||||
msg, err := json.Marshal(struct {
|
msg, err := json.Marshal(struct {
|
||||||
|
Chanel string `json:"chanel"`
|
||||||
Room string `json:"room"`
|
Room string `json:"room"`
|
||||||
Donator string `json:"donator"`
|
Donator string `json:"donator"`
|
||||||
Amount int64 `json:"amount"`
|
Amount int64 `json:"amount"`
|
||||||
}{
|
}{
|
||||||
|
Chanel: "chaturbate",
|
||||||
Room: m.Room,
|
Room: m.Room,
|
||||||
Donator: m.From,
|
Donator: m.From,
|
||||||
Amount: m.Amount,
|
Amount: m.Amount,
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
ws.Send <- msg
|
socketServer <- msg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -154,10 +156,14 @@ func saveDB() {
|
||||||
if minutes >= 5 && now > index["last"]+30 {
|
if minutes >= 5 && now > index["last"]+30 {
|
||||||
seconds += minutes * 60
|
seconds += minutes * 60
|
||||||
msg, err := json.Marshal(struct {
|
msg, err := json.Marshal(struct {
|
||||||
|
Chanel string `json:"chanel"`
|
||||||
Index int64 `json:"index"`
|
Index int64 `json:"index"`
|
||||||
}{Index: index["tokens"] / int64(seconds) * 3600 / 1000 * 5 / 100})
|
}{
|
||||||
|
Chanel: "chaturbate",
|
||||||
|
Index: index["tokens"] / int64(seconds) * 3600 / 1000 * 5 / 100
|
||||||
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
ws.Send <- msg
|
socketServer <- msg
|
||||||
}
|
}
|
||||||
index["last"] = now
|
index["last"] = now
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,10 +56,14 @@ func announceCount() {
|
||||||
rooms.Count <- 0
|
rooms.Count <- 0
|
||||||
l := <-rooms.Count
|
l := <-rooms.Count
|
||||||
msg, err := json.Marshal(struct {
|
msg, err := json.Marshal(struct {
|
||||||
|
Chanel string `json:"chanel"`
|
||||||
Count int `json:"count"`
|
Count int `json:"count"`
|
||||||
}{Count: l})
|
}{
|
||||||
|
Chanel: "chaturbate",
|
||||||
|
Count: l
|
||||||
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
ws.Send <- msg
|
socketServer <- msg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue