This commit is contained in:
shoopea 2020-01-06 11:58:46 +08:00
parent 95d5b0cfc1
commit ed3f44efeb
5 changed files with 87 additions and 48 deletions

4
def.go
View File

@ -307,8 +307,8 @@ type MessageParsingRule struct {
Rule string `json:"rule"`
MsgType string `json:"msg_type"`
MsgTypeID64 int64
ChatID64 int64
SenderUserID64 int64
ChatID64 int64 `json:"chat_id"`
SenderUserID64 int64 `json:"sender_id"`
re *regexp.Regexp
}

106
job.go
View File

@ -1265,7 +1265,28 @@ func jobVaultUserStatus(j Job) {
}
func jobGWithdraw(j Job) {
var p JobPayloadGWithdraw
var (
p JobPayloadGWithdraw
reqTab map[int64]int64
doneTab map[int64]int64
)
reqTab = make(map[int64]int64)
reqTab[cacheObjSubType[`item_res`]] = 1 << 0
reqTab[cacheObjSubType[`item_alch`]] = 1 << 1
reqTab[cacheObjSubType[`item_misc`]] = 1 << 2
reqTab[cacheObjSubType[`item_recipe`]] = 1 << 3
reqTab[cacheObjSubType[`item_part`]] = 1 << 4
reqTab[cacheObjSubType[`item_other`]] = 1 << 5
doneTab = make(map[int64]int64)
doneTab[cacheObjSubType[`item_res`]] = 1 << 10
doneTab[cacheObjSubType[`item_alch`]] = 1 << 11
doneTab[cacheObjSubType[`item_misc`]] = 1 << 12
doneTab[cacheObjSubType[`item_recipe`]] = 1 << 13
doneTab[cacheObjSubType[`item_part`]] = 1 << 14
doneTab[cacheObjSubType[`item_other`]] = 1 << 15
err := setJobStart(j.ID64)
logOnError(err, "jobGWithdraw : setJobStart")
@ -1277,51 +1298,60 @@ func jobGWithdraw(j Job) {
id := getSilentObjItemID(item.Item, ``)
if id != 0 {
obj, _ := getObjItem(id)
switch obj.ItemTypeID {
case cacheObjSubType[`item_res`]:
p.Status = p.Status | 1
case cacheObjSubType[`item_alch`]:
p.Status = p.Status | 2
case cacheObjSubType[`item_misc`]:
p.Status = p.Status | 4
case cacheObjSubType[`item_recipe`]:
p.Status = p.Status | 8
case cacheObjSubType[`item_part`]:
p.Status = p.Status | 16
case cacheObjSubType[`item_other`]:
p.Status = p.Status | 32
default:
log.Printf("jobGWithdraw : No handler for item type #%d.\n", obj.ItemTypeID)
}
p.Status = p.Status | reqTab[obj.ItemTypeID]
} else if ok, _ := regexp.MatchString(`^u[0-9]+`, item.Item); ok {
p.Status = p.Status | 32
p.Status = p.Status | reqTab[cacheObjSubType[`item_other`]]
}
}
if p.Status&reqTab[cacheObjSubType[`item_res`]] == 0 {
p.Status = p.Status | doneTab[cacheObjSubType[`item_res`]]
}
if p.Status&reqTab[cacheObjSubType[`item_alch`]] == 0 {
p.Status = p.Status | doneTab[cacheObjSubType[`item_alch`]]
}
if p.Status&reqTab[cacheObjSubType[`item_misc`]] == 0 {
p.Status = p.Status | doneTab[cacheObjSubType[`item_misc`]]
}
if p.Status&reqTab[cacheObjSubType[`item_recipe`]] == 0 {
p.Status = p.Status | doneTab[cacheObjSubType[`item_recipe`]]
}
if p.Status&reqTab[cacheObjSubType[`item_part`]] == 0 {
p.Status = p.Status | doneTab[cacheObjSubType[`item_part`]]
}
if p.Status&reqTab[cacheObjSubType[`item_other`]] == 0 {
p.Status = p.Status | doneTab[cacheObjSubType[`item_other`]]
}
}
b, _ := json.Marshal(p)
log.Printf("jobGWithdraw : %s\n", string(b))
if (p.Status & 63) > 0 {
if (p.Status & 1) == 1 {
log.Printf("jobGWithdraw : Requesting res.\n")
p.Status = p.Status &^ 1
} else if (p.Status & 2) == 2 {
log.Printf("jobGWithdraw : Requesting alch.\n")
p.Status = p.Status &^ 2
} else if (p.Status & 4) == 4 {
log.Printf("jobGWithdraw : Requesting misc.\n")
p.Status = p.Status &^ 4
} else if (p.Status & 8) == 8 {
log.Printf("jobGWithdraw : Requesting recipe.\n")
p.Status = p.Status &^ 8
} else if (p.Status & 16) == 16 {
log.Printf("jobGWithdraw : Requesting part.\n")
p.Status = p.Status &^ 16
} else if (p.Status & 32) == 32 {
log.Printf("jobGWithdraw : Requesting other.\n")
p.Status = p.Status &^ 32
}
if (p.Status & reqTab[cacheObjSubType[`item_res`]]) == reqTab[cacheObjSubType[`item_res`]] {
log.Printf("jobGWithdraw : Requesting res.\n")
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_res`]]
p.Status = p.Status | doneTab[cacheObjSubType[`item_res`]]
} else if (p.Status & reqTab[cacheObjSubType[`item_alch`]]) == reqTab[cacheObjSubType[`item_alch`]] {
log.Printf("jobGWithdraw : Requesting alch.\n")
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_alch`]]
p.Status = p.Status | doneTab[cacheObjSubType[`item_alch`]]
} else if (p.Status & reqTab[cacheObjSubType[`item_misc`]]) == reqTab[cacheObjSubType[`item_misc`]] {
log.Printf("jobGWithdraw : Requesting misc.\n")
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_misc`]]
p.Status = p.Status | doneTab[cacheObjSubType[`item_misc`]]
} else if (p.Status & reqTab[cacheObjSubType[`item_recipe`]]) == reqTab[cacheObjSubType[`item_recipe`]] {
log.Printf("jobGWithdraw : Requesting recipe.\n")
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_recipe`]]
p.Status = p.Status | doneTab[cacheObjSubType[`item_recipe`]]
} else if (p.Status & reqTab[cacheObjSubType[`item_part`]]) == reqTab[cacheObjSubType[`item_part`]] {
log.Printf("jobGWithdraw : Requesting part.\n")
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_part`]]
p.Status = p.Status | doneTab[cacheObjSubType[`item_part`]]
} else if (p.Status & reqTab[cacheObjSubType[`item_other`]]) == reqTab[cacheObjSubType[`item_other`]] {
log.Printf("jobGWithdraw : Requesting other.\n")
p.Status = p.Status &^ reqTab[cacheObjSubType[`item_other`]]
p.Status = p.Status | doneTab[cacheObjSubType[`item_other`]]
}
err = setJobDone(j.ID64)

7
msg.go
View File

@ -11,7 +11,12 @@ import (
func getMsgParsingRule(m *ChatWarsMessage) (*MessageParsingRule, error) {
var i int
for i = 0; i < len(msgParsingRules) && msgParsingRules[i].re.FindStringSubmatch(m.Text) == nil; i++ {
for i = 0; i < len(msgParsingRules); i++ {
if msgParsingRules[i].re.FindStringSubmatch(m.Text) != nil {
if (msgParsingRules[i].ChatID64 == 0 || msgParsingRules[i].ChatID64 == m.ChatID64) && (msgParsingRules[i].SenderUserID64 == 0 || msgParsingRules[i].SenderUserID64 == m.TGSenderUserID64) {
break
}
}
}
if i == len(msgParsingRules) {

View File

@ -20,10 +20,12 @@ func resetMsgParsingRules() error {
for _, r := range rules {
r2 := MessageParsingRule{
Priority: r.Priority,
Description: r.Description,
Rule: r.Rule,
MsgType: r.MsgType,
Priority: r.Priority,
Description: r.Description,
Rule: r.Rule,
MsgType: r.MsgType,
ChatID64: r.ChatID64,
SenderUserID64: r.SenderUserID64,
}
r2.MsgTypeID64, err = codeObjSubTypeId(r2.MsgType)
@ -47,8 +49,8 @@ func resetMsgParsingRules() error {
return err
}
stmt, err := db.Prepare(`INSERT INTO msg_rules (prio, msg_type_id, descn, rule)
VALUES (?, ?, ?, ?);`)
stmt, err := db.Prepare(`INSERT INTO msg_rules (prio, msg_type_id, chat_id, sender_id, descn, rule)
VALUES (?, ?, ?, ?, ?, ?);`)
logOnError(err, "resetMsgParsingRules : prepare statement")
if err != nil {
return err
@ -57,7 +59,7 @@ func resetMsgParsingRules() error {
count = 0
for _, r2 := range rules2 {
_, err = stmt.Exec(r2.Priority, r2.MsgTypeID64, r2.Description, r2.Rule)
_, err = stmt.Exec(r2.Priority, r2.MsgTypeID64, r2.ChatID64, r2.SenderUserID64, r2.Description, r2.Rule)
logOnError(err, "resetMsgParsingRules : insert statement "+r2.Description)
if err != nil {
return err

2
sql.go
View File

@ -309,6 +309,8 @@ func initDB() {
,descn VARCHAR(32) NOT NULL
,rule VARCHAR(4096) NOT NULL
,msg_type_id SMALLINT UNSIGNED NOT NULL
,chat_id BIGINT NOT NULL
,user_id BIGINT NOT NULL
,UNIQUE KEY (id)
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
failOnError(err, "initDB : create table msg_rules")