update g withdraw
This commit is contained in:
parent
bd18dfae73
commit
0017ae92fe
@ -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"
|
||||
},
|
||||
|
5
def.go
5
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"`
|
||||
|
28
job.go
28
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<code>%s</code>\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)
|
||||
|
9
main.go
9
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)
|
||||
|
||||
|
8
msg.go
8
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
|
||||
}
|
||||
|
8
rules.go
8
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<Ref>[a-f0-9]{32})$",
|
||||
MsgTypeID64: cacheObjSubType[`msg_job_gwithdraw_ack`],
|
||||
ChatID64: cfg.Bot.Mainchat,
|
||||
SenderUserID64: 0,
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user