diff --git a/data/code_obj_sub_type.json b/data/code_obj_sub_type.json
index 3f306e2..2e9713b 100644
--- a/data/code_obj_sub_type.json
+++ b/data/code_obj_sub_type.json
@@ -25,12 +25,12 @@
"obj_type": "msg"
},
{
- "intl_id": "msg_guild_gwithdraw_req",
+ "intl_id": "msg_job_gwithdraw_req",
"name": "Guild withdraw conf req",
"obj_type": "msg"
},
{
- "intl_id": "msg_guild_gwithdraw_ack",
+ "intl_id": "msg_job_gwithdraw_ack",
"name": "Guild withdraw conf ack",
"obj_type": "msg"
},
diff --git a/def.go b/def.go
index 5b4751f..d051a75 100644
--- a/def.go
+++ b/def.go
@@ -334,6 +334,11 @@ type ChatWarsMessageTimeAck struct {
WeatherNext string `json:"weather_next"`
}
+type ChatWarsMessageJobGWithdrawAck struct {
+ Msg *ChatWarsMessage `json:"msg"`
+ Ref string `json:"ref"`
+}
+
type MessageParsingRule struct {
ID int32
Priority int32 `json:"prio"`
diff --git a/job.go b/job.go
index 9c5f14b..67f81f9 100644
--- a/job.go
+++ b/job.go
@@ -1594,11 +1594,16 @@ func jobGWithdraw(j Job) {
in = append(in, buf...)
out := make([]byte, len(in))
+ ref := hex.EncodeToString(in)
+ log.Printf("jobGWithdraw[%d] : in string : %s.\n", j.ID64, ref)
c.Encrypt(out, in)
+ ref = hex.EncodeToString(out)
+ log.Printf("jobGWithdraw[%d] : out string : %s.\n", j.ID64, ref)
+
ref := hex.EncodeToString(out)
b, err = json.Marshal(p)
- fmt.Printf("jobGWithdraw : %s\n", string(b))
+ log.Printf("jobGWithdraw[%d] : %s\n", string(b))
msg := fmt.Sprintf("Click to validate @%s's withdrawal of%s
\n/withdraw_%s", p.User, stock, string(ref))
@@ -1628,6 +1633,27 @@ func jobGWithdraw(j Job) {
return
}
+func msgJobGWithdrawAck(cwm *ChatWarsMessageJobGWithdrawAck) error {
+ in, err := hex.DecodeString(cwm.Ref)
+ logOnError(err, "msgJobGWithdrawAck : DecodeString")
+ if err != nil {
+ return err
+ }
+
+ sha256 := sha256.Sum256([]byte(cfg.Telegram.Token))
+ sha128 := sha256[:aes.BlockSize]
+ c, err := aes.NewCipher(sha128)
+
+ out := make([]byte, len(in))
+
+ c.Decrypt(out, in)
+ ref := hex.EncodeToString(out)
+ log.Printf("msgJobGWithdrawAck : out string : %s.\n", ref)
+
+ return nil
+
+}
+
func jobSetDef(j Job) {
var p JobPayloadSetDef
err := setJobStart(j.ID64)
diff --git a/main.go b/main.go
index a80857a..10a3fbe 100644
--- a/main.go
+++ b/main.go
@@ -21,9 +21,8 @@ var (
config = flag.String("config", "config.json", "config file path")
initdb = flag.Bool("initdb", false, "initialize bot database")
- db *sql.DB
- bot *tb.Bot
- botUserID64 int64
+ db *sql.DB
+ bot *tb.Bot
cr *cron.Cron
@@ -95,8 +94,6 @@ func main() {
clients = make(map[int64]*ChirpClient)
callbacks = make(map[int64]map[int64][]int64)
- initCache(*initdb)
-
// Registering bot
bot, err = tb.NewBot(tb.Settings{
Token: cfg.Telegram.Token,
@@ -106,6 +103,8 @@ func main() {
failOnError(err, "Registering bot")
log.Println("Bot registered")
+ initCache(*initdb)
+
log.Printf("URL : %s\n", bot.URL)
log.Printf("Token : %s\n", bot.Token)
diff --git a/msg.go b/msg.go
index 1b7446b..d9c5586 100644
--- a/msg.go
+++ b/msg.go
@@ -493,3 +493,11 @@ func parseSubTypeMessagePillageInc(m *ChatWarsMessage, r *regexp.Regexp) (*ChatW
return &cwm, nil
}
+
+func parseSubTypeMessageJobGWithdrawAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMessageJobGWithdrawAck, error) {
+ cwm := ChatWarsMessageJobGWithdrawAck{}
+ cwm.Ref = r.ReplaceAllString(m.Text, "${Ref}")
+ cwm.Msg = m
+
+ return &cwm, nil
+}
diff --git a/rules.go b/rules.go
index 133f0aa..2e46d9f 100644
--- a/rules.go
+++ b/rules.go
@@ -23,17 +23,17 @@ func resetMsgParsingRules() error {
Priority: 9999,
Description: "Withdrawal request",
Rule: "^To validate (@[A-Za-z0-9]*) withdrawal of\n([0-9]+ x .*\n)+(Click /withdraw_[a-f0-9]{32})$",
- MsgTypeID64: cacheObjSubType[`msg_guild_gwithdraw_req`],
+ MsgTypeID64: cacheObjSubType[`msg_job_gwithdraw_req`],
ChatID64: cfg.Bot.Mainchat,
- SenderUserID64: botUserID64,
+ SenderUserID64: int64(bot.Me.ID),
}
rules2 = append(rules2, r)
r = MessageParsingRule{
Priority: 9999,
Description: "Withdrawal acknowledgment",
- Rule: "^/withdraw_[a-f0-9]{32}$",
- MsgTypeID64: cacheObjSubType[`msg_guild_gwithdraw_ack`],
+ Rule: "^/withdraw_(?P[[a-f0-9]{32})$",
+ MsgTypeID64: cacheObjSubType[`msg_job_gwithdraw_ack`],
ChatID64: cfg.Bot.Mainchat,
SenderUserID64: 0,
}
diff --git a/workers.go b/workers.go
index 5bfb099..8e0f41a 100644
--- a/workers.go
+++ b/workers.go
@@ -505,6 +505,11 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing cacheObjSubType[`msg_quest_res`]")
err = setClientIdle(m.TGUserID64, m.Date)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setClientIdle")
+ case cacheObjSubType[`msg_job_gwithdraw_ack`]:
+ cwm, err := parseSubTypeMessageJobGWithdrawAck(m, rule.re)
+ logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing cacheObjSubType[`msg_quest_res`]")
+ err = msgJobGWithdrawAck(cwm)
+ logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : msgJobGWithdrawAck")
default:
//log.Printf("SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Unknwon message type in rule %d : %d (%d)\n%s\n", msgParsingRules[i].ID, msgParsingRules[i].MsgTypeID64, objId, m.Text)
}
]