update g withdraw

This commit is contained in:
shoopea 2020-01-17 10:47:03 +08:00
parent bd18dfae73
commit 0017ae92fe
7 changed files with 55 additions and 12 deletions

View File

@ -25,12 +25,12 @@
"obj_type": "msg" "obj_type": "msg"
}, },
{ {
"intl_id": "msg_guild_gwithdraw_req", "intl_id": "msg_job_gwithdraw_req",
"name": "Guild withdraw conf req", "name": "Guild withdraw conf req",
"obj_type": "msg" "obj_type": "msg"
}, },
{ {
"intl_id": "msg_guild_gwithdraw_ack", "intl_id": "msg_job_gwithdraw_ack",
"name": "Guild withdraw conf ack", "name": "Guild withdraw conf ack",
"obj_type": "msg" "obj_type": "msg"
}, },

5
def.go
View File

@ -334,6 +334,11 @@ type ChatWarsMessageTimeAck struct {
WeatherNext string `json:"weather_next"` WeatherNext string `json:"weather_next"`
} }
type ChatWarsMessageJobGWithdrawAck struct {
Msg *ChatWarsMessage `json:"msg"`
Ref string `json:"ref"`
}
type MessageParsingRule struct { type MessageParsingRule struct {
ID int32 ID int32
Priority int32 `json:"prio"` Priority int32 `json:"prio"`

28
job.go
View File

@ -1594,11 +1594,16 @@ func jobGWithdraw(j Job) {
in = append(in, buf...) in = append(in, buf...)
out := make([]byte, len(in)) out := make([]byte, len(in))
ref := hex.EncodeToString(in)
log.Printf("jobGWithdraw[%d] : in string : %s.\n", j.ID64, ref)
c.Encrypt(out, in) c.Encrypt(out, in)
ref = hex.EncodeToString(out)
log.Printf("jobGWithdraw[%d] : out string : %s.\n", j.ID64, ref)
ref := hex.EncodeToString(out) ref := hex.EncodeToString(out)
b, err = json.Marshal(p) 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<code>%s</code>\n/withdraw_%s", p.User, stock, string(ref)) msg := fmt.Sprintf("Click to validate @%s's withdrawal of<code>%s</code>\n/withdraw_%s", p.User, stock, string(ref))
@ -1628,6 +1633,27 @@ func jobGWithdraw(j Job) {
return 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) { func jobSetDef(j Job) {
var p JobPayloadSetDef var p JobPayloadSetDef
err := setJobStart(j.ID64) err := setJobStart(j.ID64)

View File

@ -21,9 +21,8 @@ var (
config = flag.String("config", "config.json", "config file path") config = flag.String("config", "config.json", "config file path")
initdb = flag.Bool("initdb", false, "initialize bot database") initdb = flag.Bool("initdb", false, "initialize bot database")
db *sql.DB db *sql.DB
bot *tb.Bot bot *tb.Bot
botUserID64 int64
cr *cron.Cron cr *cron.Cron
@ -95,8 +94,6 @@ func main() {
clients = make(map[int64]*ChirpClient) clients = make(map[int64]*ChirpClient)
callbacks = make(map[int64]map[int64][]int64) callbacks = make(map[int64]map[int64][]int64)
initCache(*initdb)
// Registering bot // Registering bot
bot, err = tb.NewBot(tb.Settings{ bot, err = tb.NewBot(tb.Settings{
Token: cfg.Telegram.Token, Token: cfg.Telegram.Token,
@ -106,6 +103,8 @@ func main() {
failOnError(err, "Registering bot") failOnError(err, "Registering bot")
log.Println("Bot registered") log.Println("Bot registered")
initCache(*initdb)
log.Printf("URL : %s\n", bot.URL) log.Printf("URL : %s\n", bot.URL)
log.Printf("Token : %s\n", bot.Token) log.Printf("Token : %s\n", bot.Token)

8
msg.go
View File

@ -493,3 +493,11 @@ func parseSubTypeMessagePillageInc(m *ChatWarsMessage, r *regexp.Regexp) (*ChatW
return &cwm, nil 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
}

View File

@ -23,17 +23,17 @@ func resetMsgParsingRules() error {
Priority: 9999, Priority: 9999,
Description: "Withdrawal request", Description: "Withdrawal request",
Rule: "^To validate (@[A-Za-z0-9]*) withdrawal of\n([0-9]+ x .*\n)+(Click /withdraw_[a-f0-9]{32})$", 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, ChatID64: cfg.Bot.Mainchat,
SenderUserID64: botUserID64, SenderUserID64: int64(bot.Me.ID),
} }
rules2 = append(rules2, r) rules2 = append(rules2, r)
r = MessageParsingRule{ r = MessageParsingRule{
Priority: 9999, Priority: 9999,
Description: "Withdrawal acknowledgment", Description: "Withdrawal acknowledgment",
Rule: "^/withdraw_[a-f0-9]{32}$", Rule: "^/withdraw_(?P<Ref>[a-f0-9]{32})$",
MsgTypeID64: cacheObjSubType[`msg_guild_gwithdraw_ack`], MsgTypeID64: cacheObjSubType[`msg_job_gwithdraw_ack`],
ChatID64: cfg.Bot.Mainchat, ChatID64: cfg.Bot.Mainchat,
SenderUserID64: 0, SenderUserID64: 0,
} }

View File

@ -505,6 +505,11 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing cacheObjSubType[`msg_quest_res`]") logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : Parsing cacheObjSubType[`msg_quest_res`]")
err = setClientIdle(m.TGUserID64, m.Date) err = setClientIdle(m.TGUserID64, m.Date)
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setClientIdle") 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: 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) //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)
} }