This commit is contained in:
shoopea 2020-01-14 12:10:52 +08:00
parent 26b3368057
commit be3ec2d355
4 changed files with 36 additions and 7 deletions

7
bot.go
View File

@ -953,9 +953,10 @@ func botGWithdraw(m *tb.Message) {
if r.MatchString(m.Payload) { if r.MatchString(m.Payload) {
rx := regexp.MustCompile("(?P<Item>[a-z0-9]+) (?P<Quantity>[0-9]+)") rx := regexp.MustCompile("(?P<Item>[a-z0-9]+) (?P<Quantity>[0-9]+)")
p := JobPayloadGWithdraw{ p := JobPayloadGWithdraw{
MsgID64: int64(m.ID), MsgID64: int64(m.ID),
ChatID64: m.Chat.ID, ChatID64: m.Chat.ID,
Status: 0, Status: 0,
Validated: false,
} }
items := []JobPayloadGWithdrawItem{} items := []JobPayloadGWithdrawItem{}
for _, l := range rx.FindAllStringSubmatch(m.Payload, -1) { for _, l := range rx.FindAllStringSubmatch(m.Payload, -1) {

View File

@ -8,6 +8,30 @@ import (
"time" "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) { func getLockedRandomClient() (*ChirpClient, error) {
muxClients.RLock() muxClients.RLock()
ids := make([]int64, 0) ids := make([]int64, 0)

10
def.go
View File

@ -405,10 +405,12 @@ type JobPayloadGWithdrawItem struct {
} }
type JobPayloadGWithdraw struct { type JobPayloadGWithdraw struct {
MsgID64 int64 `json:"msg_id"` MsgID64 int64 `json:"msg_id"`
ChatID64 int64 `json:"chat_id"` ChatID64 int64 `json:"chat_id"`
Items []JobPayloadGWithdrawItem `json:"items"` Items []JobPayloadGWithdrawItem `json:"items"`
Status int64 `json:"status"` Status int64 `json:"status"`
CleanupMsg []ChatWarsMessage `json:"cleanup_msg"`
Validated bool `json:"validated"`
} }
type JobPayloadGDeposit struct { type JobPayloadGDeposit struct {

2
job.go
View File

@ -1558,6 +1558,8 @@ func jobGWithdraw(j Job) {
createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute) createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute)
clientSendCWMsg(j.UserID64, `/g_stock_other`) clientSendCWMsg(j.UserID64, `/g_stock_other`)
} else { } else {
c, err := getLockedRoleClient(`Commander`)
logOnError(err, "jobGWithdraw: getLockedRoleClient(Commander)")
b, _ := json.Marshal(p) b, _ := json.Marshal(p)
log.Printf("jobGWithdraw[%d] : got all the info\n%s\n", j.ID64, string(b)) log.Printf("jobGWithdraw[%d] : got all the info\n%s\n", j.ID64, string(b))
} }