test clients backup
This commit is contained in:
parent
5e25478137
commit
1c44e5bc34
32
client.go
32
client.go
@ -6,8 +6,33 @@ import (
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/jinzhu/copier"
|
||||
)
|
||||
|
||||
func loadClients() {
|
||||
var clts []ChirpClient
|
||||
|
||||
b, err := ioutil.ReadFile("./clients.json")
|
||||
logOnError(err, "loadClients : ReadFile(./clients.json)")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(b, &clts)
|
||||
logOnError(err, "loadClients : Unmarshal(./clients.json)")
|
||||
|
||||
muxClients.Lock()
|
||||
for _, c := range clts {
|
||||
cx := ChirpClient{}
|
||||
copier.Copy(&cx, &c)
|
||||
cx.Active = false
|
||||
clients[cx.TGUserID64] = cx
|
||||
}
|
||||
muxClients.Unlock()
|
||||
|
||||
}
|
||||
|
||||
func getLockedRoleClient(role string) (*ChirpClient, error) {
|
||||
muxClients.RLock()
|
||||
defer muxClients.RUnlock()
|
||||
@ -119,9 +144,10 @@ func getLockedClient(id int64, createMissing bool) (*ChirpClient, bool) {
|
||||
muxClients.RUnlock()
|
||||
return c, true
|
||||
} else if createMissing {
|
||||
c := new(ChirpClient)
|
||||
c.TGUserID64 = id
|
||||
c.Active = false
|
||||
c := ChirpClient{
|
||||
TGUserID64: id,
|
||||
Active: false,
|
||||
}
|
||||
c.Mux.Lock()
|
||||
muxClients.RUnlock()
|
||||
muxClients.Lock()
|
||||
|
4
cron.go
4
cron.go
@ -99,6 +99,10 @@ func cronSaveClients() {
|
||||
}
|
||||
muxClients.RUnlock()
|
||||
|
||||
for k, _ := range clts {
|
||||
clts[k].Active = false
|
||||
}
|
||||
|
||||
b, err := json.Marshal(clts)
|
||||
logOnError(err, "cronSaveClients : Marshal")
|
||||
|
||||
|
16
main.go
16
main.go
@ -86,6 +86,14 @@ func main() {
|
||||
initDB()
|
||||
}
|
||||
|
||||
MQCWMsgQueue = make(chan ChatWarsMessage, MQCWMsgQueueSize)
|
||||
SQLMsgIdentifyQueue = make(chan int64, SQLMsgIdentifyQueueSize)
|
||||
TGCmdQueue = make(chan TGCommand, TGCmdQueueSize)
|
||||
MQTGCmdQueue = make(chan TGCommand, MQTGCmdQueueSize)
|
||||
JobQueue = make(chan Job, JobQueueSize)
|
||||
clients = make(map[int64]*ChirpClient)
|
||||
callbacks = make(map[int64]map[int64][]int64)
|
||||
|
||||
initCache(*initdb)
|
||||
|
||||
// Registering bot
|
||||
@ -108,14 +116,6 @@ func main() {
|
||||
|
||||
cr = startCron()
|
||||
|
||||
MQCWMsgQueue = make(chan ChatWarsMessage, MQCWMsgQueueSize)
|
||||
SQLMsgIdentifyQueue = make(chan int64, SQLMsgIdentifyQueueSize)
|
||||
TGCmdQueue = make(chan TGCommand, TGCmdQueueSize)
|
||||
MQTGCmdQueue = make(chan TGCommand, MQTGCmdQueueSize)
|
||||
JobQueue = make(chan Job, JobQueueSize)
|
||||
clients = make(map[int64]*ChirpClient)
|
||||
callbacks = make(map[int64]map[int64][]int64)
|
||||
|
||||
for w := 1; w <= MQGetMsgWorkers; w++ {
|
||||
go MQGetMsgWorker(w, MQCWMsgQueue)
|
||||
}
|
||||
|
30
workers.go
30
workers.go
@ -207,20 +207,24 @@ func MQKeepAliveWorker() {
|
||||
}
|
||||
clt.Mux.Unlock()
|
||||
if clt.Active {
|
||||
c := TGCommand{
|
||||
Type: commandSendMsg,
|
||||
ToUserID64: x.TGUserID64,
|
||||
Text: "Your client is connected.",
|
||||
}
|
||||
TGCmdQueue <- c
|
||||
c = TGCommand{
|
||||
Type: commandSendMsg,
|
||||
ToUserID64: cfg.Bot.Admin,
|
||||
Text: fmt.Sprintf("Client `%s` is connected.", x.Nickname),
|
||||
}
|
||||
TGCmdQueue <- c
|
||||
if clt.CWRole == `` {
|
||||
c := TGCommand{
|
||||
Type: commandSendMsg,
|
||||
ToUserID64: x.TGUserID64,
|
||||
Text: "Your client is connected.",
|
||||
}
|
||||
TGCmdQueue <- c
|
||||
c = TGCommand{
|
||||
Type: commandSendMsg,
|
||||
ToUserID64: cfg.Bot.Admin,
|
||||
Text: fmt.Sprintf("Client `%s` is connected.", x.Nickname),
|
||||
}
|
||||
TGCmdQueue <- c
|
||||
|
||||
clientSendCWMsg(x.TGUserID64, `🏅Me`)
|
||||
clientSendCWMsg(x.TGUserID64, `🏅Me`)
|
||||
} else {
|
||||
// silent reconnection
|
||||
}
|
||||
} else {
|
||||
c := TGCommand{
|
||||
Type: commandSendMsg,
|
||||
|
Loading…
Reference in New Issue
Block a user