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

View File

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

View File

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