client revamp compilation fix

This commit is contained in:
shoopea 2019-07-31 14:19:09 +08:00
parent ad026c4b68
commit e775d55e2e
3 changed files with 17 additions and 13 deletions

18
bot.go
View File

@ -166,7 +166,7 @@ func botGetClients(m *tb.Message) {
return
}
if clt, ok := getLockedClient(m.Chat.ID, false); ok {
clt.Unlock()
clt.Mux.Unlock()
muxClients.RLock()
var ret string
for id, c := range clients {
@ -213,7 +213,7 @@ func botMsgRescan(m *tb.Message) {
TGCmdQueue <- c
return
}
clt.Unlock()
clt.Mux.Unlock()
if clt.TGUserID64 != cfg.Bot.Admin {
c := TGCommand{
Type: commandReplyMsg,
@ -275,7 +275,7 @@ func botMsgRescanAll(m *tb.Message) {
TGCmdQueue <- c
return
}
clt.Unlock()
clt.Mux.Unlock()
if clt.TGUserID64 != cfg.Bot.Admin {
c := TGCommand{
Type: commandReplyMsg,
@ -330,7 +330,7 @@ func botBackupExport(m *tb.Message) {
TGCmdQueue <- c
return
}
clt.Unlock()
clt.Mux.Unlock()
if clt.TGUserID64 != cfg.Bot.Admin {
c := TGCommand{
Type: commandReplyMsg,
@ -368,7 +368,7 @@ func botBackupImport(m *tb.Message) {
TGCmdQueue <- c
return
}
clt.Unlock()
clt.Mux.Unlock()
if clt.TGUserID64 != cfg.Bot.Admin {
c := TGCommand{
Type: commandReplyMsg,
@ -419,7 +419,7 @@ func botMsgDump(m *tb.Message) {
TGCmdQueue <- c
return
}
clt.Unlock()
clt.Mux.Unlock()
if clt.TGUserID64 != cfg.Bot.Admin {
c := TGCommand{
Type: commandReplyMsg,
@ -476,7 +476,7 @@ func botListParsingRules(m *tb.Message) {
TGCmdQueue <- c
return
}
clt.Unlock()
clt.Mux.Unlock()
if clt.TGUserID64 != cfg.Bot.Admin {
c := TGCommand{
Type: commandReplyMsg,
@ -517,7 +517,7 @@ func botListParsingRule(m *tb.Message) {
TGCmdQueue <- c
return
}
clt.Unlock()
clt.Mux.Unlock()
if clt.TGUserID64 != cfg.Bot.Admin {
c := TGCommand{
Type: commandReplyMsg,
@ -598,7 +598,7 @@ func botTimer(m *tb.Message) {
TGCmdQueue <- c
return
}
clt.Unlock()
clt.Mux.Unlock()
r := regexp.MustCompile("^(?P<Duration>([0-9]*(s|m|h))+) \"(?P<Msg>(.*))\"$")
if r.MatchString(m.Payload) {

View File

@ -9,18 +9,22 @@ func getLockedClient(id int64, createMissing bool) (*ChirpClient, bool) {
muxClients.RLock()
if c, ok := clients[id]; ok {
c.Mux.Lock()
muxClients.RUnlock()
return c, true
} else if createMissing {
c := new(ChirpClient)
clients[id] = c
c.TGUserID64 = id
c.Active = false
c.Lock()
muxClients.RUnlock()
muxClients.Lock()
clients[id] = c
muxClients.Unlock()
return c, true
} else {
muxClients.RUnlock()
return 0, false
}
defer muxClients.RUnlock()
}
func clientSendCWMsg(userID64 int64, s string) {

View File

@ -203,7 +203,7 @@ func MQKeepAliveWorker() {
}
}
}
clt.Unlock()
clt.Mux.Unlock()
c := TGCommand{
Type: commandSendMsg,
@ -286,7 +286,7 @@ func MQTGCmdWorker(id int, cmds <-chan TGCommand) {
})
logOnError(err, "MQTGCmdWorker["+strconv.Itoa(id)+"] : Publishing message.")
//log.Printf("MQTGCmdWorker[" + strconv.Itoa(id) + "] : Message published.")
clt.Unlock()
clt.Mux.Unlock()
} else {
log.Printf("MQTGCmdWorker["+strconv.Itoa(id)+"] : client %d offline.\n", c.FromUserID64)
}