diff --git a/bot.go b/bot.go index a542ccd..8b70279 100644 --- a/bot.go +++ b/bot.go @@ -953,9 +953,10 @@ func botGWithdraw(m *tb.Message) { if r.MatchString(m.Payload) { rx := regexp.MustCompile("(?P[a-z0-9]+) (?P[0-9]+)") p := JobPayloadGWithdraw{ - MsgID64: int64(m.ID), - ChatID64: m.Chat.ID, - Status: 0, + MsgID64: int64(m.ID), + ChatID64: m.Chat.ID, + Status: 0, + Validated: false, } items := []JobPayloadGWithdrawItem{} for _, l := range rx.FindAllStringSubmatch(m.Payload, -1) { diff --git a/client.go b/client.go index 2302555..c4fc402 100644 --- a/client.go +++ b/client.go @@ -8,6 +8,30 @@ import ( "time" ) +func getLockedRoleClient(role string) (*ChirpClient, error) { + muxClients.RLock() + defer muxClients.RUnlock() + + ids := make([]int64, 0) + for _, c := range clients { + if c.CWRole == role { + ids = append(ids, c.TGUserID64) + fmt.Printf("getLockedRoleClient(%s) : appending %s (%d).\n", role, c.Login, c.TGUserID64) + } + } + if len(ids) == 0 { + return nil, errors.New("No %s client.", role) + } + + RndMux.Lock() + id := RndSrc.Intn(len(ids)) + RndMux.Unlock() + + clients[ids[id]].Mux.Lock() + + return clients[ids[id]], nil +} + func getLockedRandomClient() (*ChirpClient, error) { muxClients.RLock() ids := make([]int64, 0) diff --git a/def.go b/def.go index cf7a6ff..e9f7e70 100644 --- a/def.go +++ b/def.go @@ -405,10 +405,12 @@ type JobPayloadGWithdrawItem struct { } type JobPayloadGWithdraw struct { - MsgID64 int64 `json:"msg_id"` - ChatID64 int64 `json:"chat_id"` - Items []JobPayloadGWithdrawItem `json:"items"` - Status int64 `json:"status"` + MsgID64 int64 `json:"msg_id"` + ChatID64 int64 `json:"chat_id"` + Items []JobPayloadGWithdrawItem `json:"items"` + Status int64 `json:"status"` + CleanupMsg []ChatWarsMessage `json:"cleanup_msg"` + Validated bool `json:"validated"` } type JobPayloadGDeposit struct { diff --git a/job.go b/job.go index 2da369c..4650f10 100644 --- a/job.go +++ b/job.go @@ -1558,6 +1558,8 @@ func jobGWithdraw(j Job) { createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute) clientSendCWMsg(j.UserID64, `/g_stock_other`) } else { + c, err := getLockedRoleClient(`Commander`) + logOnError(err, "jobGWithdraw: getLockedRoleClient(Commander)") b, _ := json.Marshal(p) log.Printf("jobGWithdraw[%d] : got all the info\n%s\n", j.ID64, string(b)) }