mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-08-02 07:58:31 +00:00
store data from emoticon_uses command
This commit is contained in:
parent
2a6c36bba5
commit
d4afc3c4c7
2 changed files with 35 additions and 0 deletions
|
@ -4,6 +4,8 @@ import (
|
|||
"golang.org/x/net/websocket"
|
||||
"github.com/satori/go.uuid"
|
||||
"log"
|
||||
"sync"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
var ResponseSuccess = ClientMessage{Command: SuccessCommand}
|
||||
|
@ -114,7 +116,37 @@ func HandleTrackFollow(conn *websocket.Conn, client *ClientInfo, msg ClientMessa
|
|||
return ResponseSuccess, nil
|
||||
}
|
||||
|
||||
var AggregateEmoteUsage map[int]map[string]int = make(map[int]map[string]int)
|
||||
var AggregateEmoteUsageLock sync.Mutex
|
||||
|
||||
func HandleEmoticonUses(conn *websocket.Conn, client *ClientInfo, msg ClientMessage) (rmsg ClientMessage, err error) {
|
||||
// arguments is [1]map[EmoteId]map[RoomName]float64
|
||||
|
||||
mapRoot := msg.Arguments.([]interface{})[0].(map[string]interface{})
|
||||
|
||||
AggregateEmoteUsageLock.Lock()
|
||||
defer AggregateEmoteUsageLock.Unlock()
|
||||
|
||||
for strEmote, val1 := range mapRoot {
|
||||
var emoteId int
|
||||
emoteId, err = strconv.Atoi(strEmote)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
destMapInner, ok := AggregateEmoteUsage[emoteId]
|
||||
if !ok {
|
||||
destMapInner = make(map[string]int)
|
||||
AggregateEmoteUsage[emoteId] = destMapInner
|
||||
}
|
||||
|
||||
mapInner := val1.(map[string]interface{})
|
||||
for roomName, val2 := range mapInner {
|
||||
var count int = int(val2.(float64))
|
||||
destMapInner[roomName] += count
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return ResponseSuccess, nil
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ type Config struct {
|
|||
UseSSL bool
|
||||
|
||||
SocketOrigin string
|
||||
BackendUrl string
|
||||
}
|
||||
|
||||
// A command is how the client refers to a function on the server. It's just a string.
|
||||
|
@ -96,6 +97,8 @@ func SetupServer(config *Config) *websocket.Server {
|
|||
sockServer := &websocket.Server{}
|
||||
sockServer.Config = *sockConf
|
||||
sockServer.Handler = HandleSocketConnection
|
||||
|
||||
SetupBackend(config.BackendUrl)
|
||||
return sockServer
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue