test alch stuff
This commit is contained in:
parent
4ee42d8d4a
commit
b265890b68
35
bot.go
35
bot.go
@ -934,6 +934,41 @@ func botUserConfig(m *ChatWarsMessage) {
|
||||
return
|
||||
}
|
||||
|
||||
func botAlchAll(m *ChatWarsMessage) {
|
||||
|
||||
p := JobPayloadAlchAll{
|
||||
MsgID64: m.ID64,
|
||||
ChatID64: m.ChatID64,
|
||||
Status: 0,
|
||||
Mana: 0,
|
||||
MaxMana: 0,
|
||||
}
|
||||
|
||||
b, _ := json.Marshal(p)
|
||||
t := time.Now().UTC().Add(1 * time.Second)
|
||||
_, err = createJob(cacheObjSubType[`job_alch_all`], objJobPriority, userID64, 0, t, b)
|
||||
|
||||
if err != nil {
|
||||
c := TGCommand{
|
||||
Type: commandReplyMsg,
|
||||
Text: fmt.Sprintf("%s", err),
|
||||
FromMsgID64: m.ID64,
|
||||
FromChatID64: m.ChatID64,
|
||||
}
|
||||
TGCmdQueue <- c
|
||||
} else {
|
||||
c := TGCommand{
|
||||
Type: commandReplyMsg,
|
||||
Text: "Alch all coming",
|
||||
FromMsgID64: m.ID64,
|
||||
FromChatID64: m.ChatID64,
|
||||
}
|
||||
TGCmdQueue <- c
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func botCraftAll(m *ChatWarsMessage, r *regexp.Regexp) {
|
||||
if hasUnfinishedJob(cacheObjSubType[`job_craft_all`]) {
|
||||
c := TGCommand{
|
||||
|
@ -689,6 +689,26 @@
|
||||
"name": "Peace Up Withdraw",
|
||||
"obj_type": "msg"
|
||||
},
|
||||
{
|
||||
"intl_id": "msg_bot_alch_all",
|
||||
"name": "Alch all",
|
||||
"obj_type": "msg"
|
||||
},
|
||||
{
|
||||
"intl_id": "msg_alch_stock_req",
|
||||
"name": "Alch stock req",
|
||||
"obj_type": "msg"
|
||||
},
|
||||
{
|
||||
"intl_id": "msg_alch_stock_ack",
|
||||
"name": "Alch stock ack",
|
||||
"obj_type": "msg"
|
||||
},
|
||||
{
|
||||
"intl_id": "msg_skill_too_low",
|
||||
"name": "Skill too low",
|
||||
"obj_type": "msg"
|
||||
},
|
||||
{
|
||||
"intl_id": "job_pillage",
|
||||
"name": "Pillage job",
|
||||
@ -799,6 +819,11 @@
|
||||
"name": "Craft all items summary job",
|
||||
"obj_type": "job"
|
||||
},
|
||||
{
|
||||
"intl_id": "job_alch_all",
|
||||
"name": "Craft all items in stock job",
|
||||
"obj_type": "job"
|
||||
},
|
||||
{
|
||||
"intl_id": "job_shops",
|
||||
"name": "Shops summary job",
|
||||
|
@ -129,7 +129,15 @@
|
||||
},
|
||||
{
|
||||
"prio": 5000,
|
||||
"descn": "Me request",
|
||||
"descn": "Me request #1",
|
||||
"rule": "^/me$",
|
||||
"msg_type": "msg_me_req",
|
||||
"chat_id": 0,
|
||||
"user_id": 0
|
||||
},
|
||||
{
|
||||
"prio": 5000,
|
||||
"descn": "Me request #2",
|
||||
"rule": "^🏅Me$",
|
||||
"msg_type": "msg_me_req",
|
||||
"chat_id": 0,
|
||||
@ -471,6 +479,30 @@
|
||||
"chat_id": 0,
|
||||
"user_id": 0
|
||||
},
|
||||
{
|
||||
"prio": 5000,
|
||||
"descn": "Alch stock Req",
|
||||
"rule": "^/alch$",
|
||||
"msg_type": "msg_alch_stock_req",
|
||||
"chat_id": 0,
|
||||
"user_id": 0
|
||||
},
|
||||
{
|
||||
"prio": 5000,
|
||||
"descn": "Alch stock Ack",
|
||||
"rule": "^📦Your stock:(?P<Stuff>(\\n/aa_[0-9]{2} [a-zA-Z ]+ x [0-9]+)+)$",
|
||||
"msg_type": "msg_alch_stock_ack",
|
||||
"chat_id": 0,
|
||||
"user_id": 0
|
||||
},
|
||||
{
|
||||
"prio": 5000,
|
||||
"descn": "Skill too low",
|
||||
"rule": "^[Skill level too low]$",
|
||||
"msg_type": "msg_skill_too_low",
|
||||
"chat_id": 0,
|
||||
"user_id": 0
|
||||
},
|
||||
{
|
||||
"prio": 5000,
|
||||
"descn": "Guild stock Req",
|
||||
|
10
def.go
10
def.go
@ -292,6 +292,8 @@ type ChatWarsMessageMeAck struct {
|
||||
Level int64 `json:"level"`
|
||||
ExpNow int64 `json:"exp_now"`
|
||||
ExpLvl int64 `json:"exp_lvl"`
|
||||
ManaNow int64 `json:"mana_now"`
|
||||
ManaMax int64 `json:"mana_max"`
|
||||
}
|
||||
|
||||
type ChatWarsMessageGRolesAck struct {
|
||||
@ -584,6 +586,14 @@ type JobPayloadCraftAll struct {
|
||||
VaultJobID64 int64 `json:"vault_job_id"`
|
||||
}
|
||||
|
||||
type JobPayloadAlchAll struct {
|
||||
MsgID64 int64 `json:"msg_id"`
|
||||
ChatID64 int64 `json:"chat_id"`
|
||||
Status int64 `json:"status"`
|
||||
Mana int64 `json:"mana"`
|
||||
MaxMana int64 `json:"max_mana"`
|
||||
}
|
||||
|
||||
type JobPayloadCheckVaultLimit struct {
|
||||
Status int64 `json:"status"`
|
||||
VaultJobID64 int64 `json:"vault_job_id"`
|
||||
|
81
job.go
81
job.go
@ -2029,6 +2029,87 @@ func jobCraftItem(j Job) {
|
||||
|
||||
}
|
||||
|
||||
func jobAlchAll(j Job) {
|
||||
var p JobPayloadAlchAll
|
||||
|
||||
err := setJobStart(j.ID64)
|
||||
logOnError(err, "jobAlchAll : setJobStart")
|
||||
|
||||
err = json.Unmarshal(j.Payload, &p)
|
||||
logOnError(err, "jobAlchAll : Unmarshal payload")
|
||||
|
||||
if p.Status == 0 {
|
||||
|
||||
p.Status = 1
|
||||
|
||||
err = setJobPayloadJSON(j.ID64, p)
|
||||
logOnError(err, "jobAlchAll : setJobPayloadJSON(p)")
|
||||
|
||||
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_me_ack`])
|
||||
rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
|
||||
clientSendCWMsgDelay(j.UserID64, "/me", 0*time.Second)
|
||||
return
|
||||
} else if p.Status == 1 && j.Trigger != 0 {
|
||||
m, err := getObjMsg(j.Trigger)
|
||||
logOnError(err, "jobAlchAll : getObjMsg("+strconv.FormatInt(j.Trigger, 10)+")")
|
||||
if err == nil {
|
||||
rule, err := getMsgParsingRule(&m)
|
||||
logOnError(err, "jobAlchAll : getMsgParsingRule")
|
||||
if rule.MsgTypeID64 == cacheObjSubType[`msg_me_ack`] {
|
||||
|
||||
cwm, err := parseSubTypeMessageMeAck(m, rule.re)
|
||||
p.Status = 2
|
||||
p.Mana = cwm.ManaNow
|
||||
p.ManaMax = cwm.ManaMax
|
||||
|
||||
err = setJobPayloadJSON(j.ID64, p)
|
||||
logOnError(err, "jobAlchAll : setJobPayloadJSON(p)")
|
||||
|
||||
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_skill_too_low`])
|
||||
setJobCallback(j.ID64, j.UserID64, cacheObjSubType[`msg_alch_stock_ack`])
|
||||
rescheduleJob(j.ID64, 0, time.Unix(maxUnixTimestamp, 0).UTC())
|
||||
clientSendCWMsgDelay(j.UserID64, "/alch", 2*time.Second)
|
||||
return
|
||||
}
|
||||
}
|
||||
} else if p.Status == 2 && j.Trigger != 0 {
|
||||
m, err := getObjMsg(j.Trigger)
|
||||
logOnError(err, "jobAlchAll : getObjMsg("+strconv.FormatInt(j.Trigger, 10)+")")
|
||||
if err == nil {
|
||||
rule, err := getMsgParsingRule(&m)
|
||||
logOnError(err, "jobAlchAll : getMsgParsingRule")
|
||||
if rule.MsgTypeID64 == cacheObjSubType[`msg_alch_stock_ack`] {
|
||||
c := TGCommand{
|
||||
Type: commandReplyMsg,
|
||||
Text: "Success.",
|
||||
FromMsgID64: p.MsgID64,
|
||||
FromChatID64: p.ChatID64,
|
||||
ParseMode: cmdParseModeHTML,
|
||||
}
|
||||
TGCmdQueue <- c
|
||||
err = setJobDone(j.ID64)
|
||||
logOnError(err, "jobAlchAll : setJobDone")
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c := TGCommand{
|
||||
Type: commandReplyMsg,
|
||||
Text: "Failed.",
|
||||
FromMsgID64: p.MsgID64,
|
||||
FromChatID64: p.ChatID64,
|
||||
ParseMode: cmdParseModeHTML,
|
||||
}
|
||||
TGCmdQueue <- c
|
||||
|
||||
err = setJobDone(j.ID64)
|
||||
logOnError(err, "jobAlchAll : setJobDone")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func jobCraftAll(j Job) {
|
||||
var (
|
||||
p JobPayloadCraftAll
|
||||
|
11
msg.go
11
msg.go
@ -409,7 +409,12 @@ func parseSubTypeMessageMeAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMe
|
||||
i, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${Level}"), 10, 64)
|
||||
cwm.Level = i
|
||||
|
||||
/*
|
||||
i, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${ManaNow}"), 10, 64)
|
||||
cwm.ManaNow = i
|
||||
|
||||
i, _ = strconv.ParseInt(r.ReplaceAllString(m.Text, "${ManaMax}"), 10, 64)
|
||||
cwm.ManaMax = i
|
||||
|
||||
log.Printf("parseSubTypeMessageMeAck : Me report identified\n")
|
||||
log.Printf("parseSubTypeMessageMeAck : Castle : %s\n", r.ReplaceAllString(m.Text, "${Castle}"))
|
||||
log.Printf("parseSubTypeMessageMeAck : Level : %s\n", r.ReplaceAllString(m.Text, "${Level}"))
|
||||
@ -420,6 +425,8 @@ func parseSubTypeMessageMeAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMe
|
||||
log.Printf("parseSubTypeMessageMeAck : ExpLvl : %s\n", r.ReplaceAllString(m.Text, "${ExpLvl}"))
|
||||
log.Printf("parseSubTypeMessageMeAck : StaminaNow : %s\n", r.ReplaceAllString(m.Text, "${StaminaNow}"))
|
||||
log.Printf("parseSubTypeMessageMeAck : StaminaMax : %s\n", r.ReplaceAllString(m.Text, "${StaminaMax}"))
|
||||
log.Printf("parseSubTypeMessageMeAck : ManaNow : %s\n", r.ReplaceAllString(m.Text, "${ManaNow}"))
|
||||
log.Printf("parseSubTypeMessageMeAck : ManaMax : %s\n", r.ReplaceAllString(m.Text, "${ManaMax}"))
|
||||
log.Printf("parseSubTypeMessageMeAck : Gold : %s\n", r.ReplaceAllString(m.Text, "${Gold}"))
|
||||
log.Printf("parseSubTypeMessageMeAck : Pogs : %s\n", r.ReplaceAllString(m.Text, "${Pogs}"))
|
||||
log.Printf("parseSubTypeMessageMeAck : Gems : %s\n", r.ReplaceAllString(m.Text, "${Gems}"))
|
||||
@ -427,7 +434,7 @@ func parseSubTypeMessageMeAck(m *ChatWarsMessage, r *regexp.Regexp) (*ChatWarsMe
|
||||
log.Printf("parseSubTypeMessageMeAck : DefGear : %s\n", r.ReplaceAllString(m.Text, "${DefGear}"))
|
||||
log.Printf("parseSubTypeMessageMeAck : BagUsed : %s\n", r.ReplaceAllString(m.Text, "${BagUsed}"))
|
||||
log.Printf("parseSubTypeMessageMeAck : BagDispo : %s\n", r.ReplaceAllString(m.Text, "${BagDispo}"))
|
||||
*/
|
||||
|
||||
cwm.Msg = m
|
||||
return &cwm, nil
|
||||
}
|
||||
|
10
rules.go
10
rules.go
@ -80,6 +80,16 @@ func resetMsgParsingRules() error {
|
||||
SenderUserID64: id,
|
||||
}
|
||||
rules2 = append(rules2, r)
|
||||
|
||||
r = MessageParsingRule{
|
||||
Priority: 9999,
|
||||
Description: "Alch your supply",
|
||||
Rule: "^/alch_all$",
|
||||
MsgTypeID64: cacheObjSubType[`msg_bot_alch_all`],
|
||||
ChatID64: chats[id],
|
||||
SenderUserID64: users[id],
|
||||
}
|
||||
rules2 = append(rules2, r)
|
||||
}
|
||||
}
|
||||
muxClients.RUnlock()
|
||||
|
@ -552,6 +552,8 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
|
||||
botShutdown()
|
||||
case cacheObjSubType[`msg_bot_rage_up`]:
|
||||
case cacheObjSubType[`msg_bot_peace_up`]:
|
||||
case cacheObjSubType[`msg_bot_alch_all`]:
|
||||
botAlchAll(m)
|
||||
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)
|
||||
}
|
||||
@ -658,6 +660,8 @@ func JobWorker(id int, jobs <-chan Job) {
|
||||
jobShops(j)
|
||||
case cacheObjSubType[`job_shops_slave`]:
|
||||
jobShopsSlave(j)
|
||||
case cacheObjSubType[`job_alch_all`]:
|
||||
jobAlchAll(j)
|
||||
default:
|
||||
log.Printf("jobWorker["+strconv.Itoa(id)+"] : No handler for job type #%d.\n", j.JobTypeID64)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user