diff --git a/bot.go b/bot.go index 9e76916..916e262 100644 --- a/bot.go +++ b/bot.go @@ -139,7 +139,8 @@ func botTest(m *tb.Message) { if !m.Private() { return } - if _, ok := clientsKeepAlive.Load(m.Chat.ID); ok { + if clt, ok := getLockedClient(m.Chat.ID, false); ok { + clt.Mux.Unlock() clientSendCWMsg(m.Chat.ID, "🏅Me") c := TGCommand{ diff --git a/client.go b/client.go index a2396f8..fb2513e 100644 --- a/client.go +++ b/client.go @@ -23,7 +23,7 @@ func getLockedClient(id int64, createMissing bool) (*ChirpClient, bool) { return c, true } else { muxClients.RUnlock() - return 0, false + return nil, false } } @@ -60,7 +60,7 @@ func clientMsgMeAck(m *ChatWarsMessageMeAck) { } } } - clt.Unlock() + clt.Mux.Unlock() } } @@ -72,7 +72,7 @@ func clientMsgGoQuestAck(m *ChatWarsMessageGoQuestAck) { clt.CWBusyUntil = m.Msg.Date.Add(m.Duration) } } - clt.Unlock() + clt.Mux.Unlock() } } @@ -81,27 +81,27 @@ func clientMsgGRolesAck(m *ChatWarsMessageGRolesAck) { if clt.Active { if clt.CWLastUpdate.Before(m.Msg.Date) { if m.CommanderID64 == clt.CWUserID64 { - c.Role = `commander` + clt.CWRole = `commander` } else if m.BartenderID64 == clt.CWUserID64 { - c.Role = `bartender` + clt.CWRole = `bartender` } else if m.SquireID64 == clt.CWUserID64 { - c.Role = `squire` + clt.CWRole = `squire` } else if m.TreasurerID64 == clt.CWUserID64 { - c.Role = `treasurer` + clt.CWRole = `treasurer` } else { - c.Role = `none` + clt.CWRole = `none` } clt.CWLastUpdate = m.Msg.Date } } - clt.Unlock() + clt.Mux.Unlock() } } func clientGetCWUserID64(tgUserID64 int64) (int64, error) { if clt, ok := getLockedClient(m.Msg.UserID64, false); ok { i := clt.CWUserID64 - clt.Unlock() + clt.Mux.Unlock() return i, nil } return 0, errors.New("Unknown user_id.")