diff --git a/client.go b/client.go index e9904e6..1341aa3 100644 --- a/client.go +++ b/client.go @@ -55,24 +55,24 @@ func getLockedRandomClient() (*ChirpClient, error) { } func setClientBusy(userID64 int64, from time.Time, duration time.Duration) error { - if from.UTC().Add(duration).After(time.Now().UTC()) { - if clt, ok := getLockedClient(userID64, false); ok { + if clt, ok := getLockedClient(userID64, false); ok { + if from.UTC().Add(duration).After(time.Now().UTC()) { clt.CWIdle = false clt.CWBusyUntil = from.UTC().Add(duration) - clt.Mux.Unlock() log.Printf("setClientBusy[%s] : set for %s.\n", clt.Login, duration.String()) - return nil } else { - return errors.New("Client not found.") + log.Printf("setClientBusy[%s] : not updated.\n", clt.Login) } + clt.Mux.Unlock() + return nil + } else { + return errors.New("Client not found.") } - return nil } func setClientIdle(userID64 int64, from time.Time) error { if clt, ok := getLockedClient(userID64, false); ok { if from.UTC().After(clt.CWLastUpdate.UTC()) { - fmt.Printf("setClientIdle : updated.\n") clt.CWBusyUntil = from clt.CWIdle = true clt.CWLastUpdate = from diff --git a/cron.go b/cron.go index 3c81918..bb1741d 100644 --- a/cron.go +++ b/cron.go @@ -46,9 +46,7 @@ func cronTribute() { muxClients.RLock() for _, c := range clients { if c.Active { - log.Printf("cronTribute : class %s (%s)\n", c.CWClass, c.Login) if c.CWClass == `Knight` { - log.Printf("cronTribute : sending tribute\n", c.CWClass, c.Login) clientSendCWMsgDelay(c.TGUserID64, `/tributes`, 0) } } diff --git a/data/code_obj_sub_type.json b/data/code_obj_sub_type.json index 7910d6f..3f306e2 100644 --- a/data/code_obj_sub_type.json +++ b/data/code_obj_sub_type.json @@ -24,6 +24,16 @@ "name": "Guild deposit chat", "obj_type": "msg" }, + { + "intl_id": "msg_guild_gwithdraw_req", + "name": "Guild withdraw conf req", + "obj_type": "msg" + }, + { + "intl_id": "msg_guild_gwithdraw_ack", + "name": "Guild withdraw conf ack", + "obj_type": "msg" + }, { "intl_id": "msg_war", "name": "War report", diff --git a/job.go b/job.go index 395c8e5..b470ae6 100644 --- a/job.go +++ b/job.go @@ -4,6 +4,8 @@ import ( "archive/zip" "bytes" "compress/zlib" + "crypto/sha256" + "encoding/binary" "encoding/json" "errors" "fmt" @@ -15,6 +17,7 @@ import ( "strings" "time" + "github.com/lytics/base62" tb "gopkg.in/tucnak/telebot.v2" ) @@ -1556,10 +1559,33 @@ func jobGWithdraw(j Job) { createJobCallback(cacheObjSubType[`job_msg_del`], j.UserID64, p2.MsgTypeID64, b2, time.Minute) clientSendCWMsg(j.UserID64, `/g_stock_other`) } else { - _, err := getLockedRoleClient(`commander`) - logOnError(err, "jobGWithdraw: getLockedRoleClient(commander)") + /* + c, err := getLockedRoleClient(`commander`) + logOnError(err, "jobGWithdraw: getLockedRoleClient(commander)") + if err == nil { + c.Mux.Unlock() + } + */ + b, _ := json.Marshal(p) - log.Printf("jobGWithdraw[%d] : got all the info\n%s\n", j.ID64, string(b)) + id, err := createJob(cacheObjSubType[`job_gwithdraw`], objJobPriority, userID64, 0, time.Unix(maxUnixTimestamp, 0).UTC(), b) + + sha256 := sha256.Sum256([]byte(s)) + sha128 := sha256[:aes.BlockSize] + c, err := aes.NewCipher(sha128) + + in := make([]byte, 0) + buf := make([]byte, 8) + binary.LittleEndian.PutUint64(buf, uint64(id)) + in = append(in, buf) + binary.LittleEndian.PutUint64(buf, uint64(j.UserID64)) + in = append(in, buf) + out := make([]byte, len(in)) + + c.Encrypt(out, in) + ref := base62.StdEncoding.EncodeToString(out) + + log.Printf("jobGWithdraw[%d] : got all the info for ref %s\n", j.ID64, string(ref)) } err = setJobDone(j.ID64) diff --git a/rules.go b/rules.go index a1e7d52..c42d48c 100644 --- a/rules.go +++ b/rules.go @@ -19,6 +19,26 @@ func resetMsgParsingRules() error { err = json.Unmarshal(b, &rules) + r := MessageParsingRule{ + Priority: 9999, + Description: "Withdrawal request", + Rule: "^To validate (@[A-Za-z0-9]*) withdrawal of\n([0-9]+ x .*\n)+(Click /withdraw_[a-zA-Z0-9]{22})$", + MsgTypeID64: cacheObjSubType[`msg_guild_gwithdraw_req`], + ChatID64: cfg.Bot.Mainchat, + SenderUserID64: 0, + } + rules2 = append(rules2, r) + + r := MessageParsingRule{ + Priority: 9999, + Description: "Withdrawal acknowledgment", + Rule: "^/withdraw_[a-zA-Z0-9]{22}$", + MsgTypeID64: cacheObjSubType[`msg_guild_gwithdraw_ack`], + ChatID64: cfg.Bot.Mainchat, + SenderUserID64: 0, + } + rules2 = append(rules2, r) + r := MessageParsingRule{ Priority: 1, Description: "Default Main chat",