test
This commit is contained in:
parent
2d31b02928
commit
ba6dc3e7ab
@ -1763,6 +1763,17 @@
|
||||
"Pumpkin"
|
||||
]
|
||||
},
|
||||
{
|
||||
"item_type": "item_misc",
|
||||
"code": "cst",
|
||||
"weight": -1,
|
||||
"exchange": "",
|
||||
"auction": false,
|
||||
"craftable": false,
|
||||
"names": [
|
||||
"Chaos stone"
|
||||
]
|
||||
},
|
||||
{
|
||||
"item_type": "item_misc",
|
||||
"code": "pol",
|
||||
|
1
def.go
1
def.go
@ -435,6 +435,7 @@ type MessageParsingRule struct {
|
||||
MsgTypeID64 int64
|
||||
ChatID64 int64 `json:"chat_id"`
|
||||
SenderUserID64 int64 `json:"sender_id"`
|
||||
BotCommand bool `json:"bot_cmd"`
|
||||
re *regexp.Regexp
|
||||
}
|
||||
|
||||
|
31
rules.go
31
rules.go
@ -27,6 +27,7 @@ func resetMsgParsingRules() error {
|
||||
MsgTypeID64: cacheObjSubType[`msg_job_gwithdraw_req`],
|
||||
ChatID64: cfg.Bot.Mainchat,
|
||||
SenderUserID64: int64(bot.Me.ID),
|
||||
BotCommand: true,
|
||||
}
|
||||
rules2 = append(rules2, r)
|
||||
|
||||
@ -37,6 +38,7 @@ func resetMsgParsingRules() error {
|
||||
MsgTypeID64: cacheObjSubType[`msg_bot_shutdown`],
|
||||
ChatID64: cfg.Bot.Admin,
|
||||
SenderUserID64: 0,
|
||||
BotCommand: true,
|
||||
}
|
||||
rules2 = append(rules2, r)
|
||||
|
||||
@ -58,6 +60,7 @@ func resetMsgParsingRules() error {
|
||||
MsgTypeID64: cacheObjSubType[`msg_bot_user_config`],
|
||||
ChatID64: id,
|
||||
SenderUserID64: id,
|
||||
BotCommand: true,
|
||||
}
|
||||
rules2 = append(rules2, r)
|
||||
|
||||
@ -68,6 +71,7 @@ func resetMsgParsingRules() error {
|
||||
MsgTypeID64: cacheObjSubType[`msg_bot_user_config_pillage_on`],
|
||||
ChatID64: id,
|
||||
SenderUserID64: id,
|
||||
BotCommand: true,
|
||||
}
|
||||
rules2 = append(rules2, r)
|
||||
|
||||
@ -78,6 +82,7 @@ func resetMsgParsingRules() error {
|
||||
MsgTypeID64: cacheObjSubType[`msg_bot_user_config_pillage_off`],
|
||||
ChatID64: id,
|
||||
SenderUserID64: id,
|
||||
BotCommand: true,
|
||||
}
|
||||
rules2 = append(rules2, r)
|
||||
|
||||
@ -88,6 +93,7 @@ func resetMsgParsingRules() error {
|
||||
MsgTypeID64: cacheObjSubType[`msg_bot_user_config_def_guild`],
|
||||
ChatID64: id,
|
||||
SenderUserID64: id,
|
||||
BotCommand: true,
|
||||
}
|
||||
rules2 = append(rules2, r)
|
||||
|
||||
@ -98,6 +104,7 @@ func resetMsgParsingRules() error {
|
||||
MsgTypeID64: cacheObjSubType[`msg_bot_user_config_def_castle`],
|
||||
ChatID64: id,
|
||||
SenderUserID64: id,
|
||||
BotCommand: true,
|
||||
}
|
||||
rules2 = append(rules2, r)
|
||||
|
||||
@ -108,6 +115,7 @@ func resetMsgParsingRules() error {
|
||||
MsgTypeID64: cacheObjSubType[`msg_bot_alch_all`],
|
||||
ChatID64: id,
|
||||
SenderUserID64: id,
|
||||
BotCommand: true,
|
||||
}
|
||||
rules2 = append(rules2, r)
|
||||
|
||||
@ -118,6 +126,7 @@ func resetMsgParsingRules() error {
|
||||
MsgTypeID64: cacheObjSubType[`msg_bot_user_config_deposit_on`],
|
||||
ChatID64: id,
|
||||
SenderUserID64: id,
|
||||
BotCommand: true,
|
||||
}
|
||||
rules2 = append(rules2, r)
|
||||
|
||||
@ -128,6 +137,7 @@ func resetMsgParsingRules() error {
|
||||
MsgTypeID64: cacheObjSubType[`msg_bot_user_config_deposit_off`],
|
||||
ChatID64: id,
|
||||
SenderUserID64: id,
|
||||
BotCommand: true,
|
||||
}
|
||||
rules2 = append(rules2, r)
|
||||
}
|
||||
@ -146,6 +156,7 @@ func resetMsgParsingRules() error {
|
||||
MsgTypeID64: cacheObjSubType[`msg_bot_craft_item`],
|
||||
ChatID64: chats[id],
|
||||
SenderUserID64: users[id],
|
||||
BotCommand: true,
|
||||
}
|
||||
rules2 = append(rules2, r)
|
||||
}
|
||||
@ -159,6 +170,7 @@ func resetMsgParsingRules() error {
|
||||
MsgTypeID64: cacheObjSubType[`msg_bot_g_stock`],
|
||||
ChatID64: chats[id],
|
||||
SenderUserID64: users[id],
|
||||
BotCommand: true,
|
||||
}
|
||||
rules2 = append(rules2, r)
|
||||
|
||||
@ -169,6 +181,7 @@ func resetMsgParsingRules() error {
|
||||
MsgTypeID64: cacheObjSubType[`msg_bot_shops`],
|
||||
ChatID64: chats[id],
|
||||
SenderUserID64: users[id],
|
||||
BotCommand: true,
|
||||
}
|
||||
rules2 = append(rules2, r)
|
||||
|
||||
@ -179,6 +192,7 @@ func resetMsgParsingRules() error {
|
||||
MsgTypeID64: cacheObjSubType[`msg_job_gwithdraw_ack`],
|
||||
ChatID64: chats[id],
|
||||
SenderUserID64: users[id],
|
||||
BotCommand: true,
|
||||
}
|
||||
rules2 = append(rules2, r)
|
||||
|
||||
@ -189,6 +203,7 @@ func resetMsgParsingRules() error {
|
||||
MsgTypeID64: cacheObjSubType[`msg_bot_craft_all`],
|
||||
ChatID64: chats[id],
|
||||
SenderUserID64: users[id],
|
||||
BotCommand: true,
|
||||
}
|
||||
rules2 = append(rules2, r)
|
||||
|
||||
@ -199,6 +214,7 @@ func resetMsgParsingRules() error {
|
||||
MsgTypeID64: cacheObjSubType[`msg_bot_get_stash`],
|
||||
ChatID64: chats[id],
|
||||
SenderUserID64: users[id],
|
||||
BotCommand: true,
|
||||
}
|
||||
rules2 = append(rules2, r)
|
||||
|
||||
@ -212,6 +228,7 @@ func resetMsgParsingRules() error {
|
||||
MsgTypeID64: cacheObjSubType[`msg_bot_rage_up`],
|
||||
ChatID64: cfg.Bot.Mainchat,
|
||||
SenderUserID64: 0,
|
||||
BotCommand: true,
|
||||
}
|
||||
rules2 = append(rules2, r)
|
||||
|
||||
@ -222,6 +239,7 @@ func resetMsgParsingRules() error {
|
||||
MsgTypeID64: cacheObjSubType[`msg_bot_peace_up`],
|
||||
ChatID64: cfg.Bot.Mainchat,
|
||||
SenderUserID64: 0,
|
||||
BotCommand: true,
|
||||
}
|
||||
rules2 = append(rules2, r)
|
||||
|
||||
@ -254,6 +272,7 @@ func resetMsgParsingRules() error {
|
||||
MsgType: r.MsgType,
|
||||
ChatID64: r.ChatID64,
|
||||
SenderUserID64: r.SenderUserID64,
|
||||
BotCommand: false,
|
||||
}
|
||||
|
||||
r2.MsgTypeID64, err = codeObjSubTypeId(r2.MsgType)
|
||||
@ -278,8 +297,8 @@ func resetMsgParsingRules() error {
|
||||
return err
|
||||
}
|
||||
|
||||
stmt, err := db.Prepare(`INSERT INTO msg_rules (prio, msg_type_id, chat_id, user_id, descn, rule)
|
||||
VALUES (?, ?, ?, ?, ?, ?);`)
|
||||
stmt, err := db.Prepare(`INSERT INTO msg_rules (prio, msg_type_id, chat_id, user_id, descn, bot_cmd, rule)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?);`)
|
||||
logOnError(err, "resetMsgParsingRules : prepare statement")
|
||||
if err != nil {
|
||||
return err
|
||||
@ -287,7 +306,7 @@ func resetMsgParsingRules() error {
|
||||
defer stmt.Close()
|
||||
count = 0
|
||||
for _, r2 := range rules2 {
|
||||
_, err = stmt.Exec(r2.Priority, r2.MsgTypeID64, r2.ChatID64, r2.SenderUserID64, r2.Description, r2.Rule)
|
||||
_, err = stmt.Exec(r2.Priority, r2.MsgTypeID64, r2.ChatID64, r2.SenderUserID64, r2.Description, r2.BotCommand, r2.Rule)
|
||||
logOnError(err, "resetMsgParsingRules : insert statement "+r2.Description)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -311,6 +330,7 @@ func loadMsgParsingRules() (m map[int]MessageParsingRule, err error) {
|
||||
msgTypeID64 int64
|
||||
chatID64 int64
|
||||
userID64 int64
|
||||
botCommand bool
|
||||
)
|
||||
|
||||
log.Println("Loading message parsing rules...")
|
||||
@ -324,14 +344,14 @@ func loadMsgParsingRules() (m map[int]MessageParsingRule, err error) {
|
||||
}
|
||||
}()
|
||||
|
||||
rules, err := db.Query(`SELECT r.id, r.prio, r.descn, r.rule, r.msg_type_id, r.chat_id, r.user_id FROM msg_rules r ORDER BY r.prio DESC;`)
|
||||
rules, err := db.Query(`SELECT r.id, r.prio, r.descn, r.rule, r.msg_type_id, r.chat_id, r.user_id, r.bot_cmd FROM msg_rules r ORDER BY r.prio DESC;`)
|
||||
if err != nil {
|
||||
return m, err
|
||||
}
|
||||
defer rules.Close()
|
||||
|
||||
for rules.Next() {
|
||||
err = rules.Scan(&id, &priority, &descn, &rule, &msgTypeID64, &chatID64, &userID64)
|
||||
err = rules.Scan(&id, &priority, &descn, &rule, &msgTypeID64, &chatID64, &userID64, &botCommand)
|
||||
if err != nil {
|
||||
return m, err
|
||||
}
|
||||
@ -343,6 +363,7 @@ func loadMsgParsingRules() (m map[int]MessageParsingRule, err error) {
|
||||
i.MsgTypeID64 = msgTypeID64
|
||||
i.ChatID64 = chatID64
|
||||
i.SenderUserID64 = userID64
|
||||
i.BotCommand = botCommand
|
||||
i.re = regexp.MustCompile(rule)
|
||||
m[count] = *i
|
||||
// log.Printf("New rule : %s\n", rule)
|
||||
|
1
sql.go
1
sql.go
@ -402,6 +402,7 @@ func initDB() {
|
||||
,msg_type_id SMALLINT UNSIGNED NOT NULL
|
||||
,chat_id BIGINT NOT NULL
|
||||
,user_id BIGINT NOT NULL
|
||||
,bot_cmd TINYINT NOT NULL
|
||||
,UNIQUE KEY (id)
|
||||
) ENGINE = InnoDB CHARSET=utf8mb4 COLLATE utf8mb4_bin;`)
|
||||
failOnError(err, "initDB : create table msg_rules")
|
||||
|
@ -353,6 +353,9 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
|
||||
} else {
|
||||
err = setObjSubTypeId(objId, rule.MsgTypeID64)
|
||||
logOnError(err, "SQLIdentifyMsgWorker["+strconv.Itoa(id)+"] : setObjSubTypeId")
|
||||
if rule.BotCommand && m.Date.Add(time.Minute).After(time.Now().UTC()) {
|
||||
log.Printf("SQLIdentifyMsgWorker[" + strconv.Itoa(id) + "] : Timed out command\n")
|
||||
} else {
|
||||
switch rule.MsgTypeID64 {
|
||||
case cacheObjSubType[`msg_groles_req`]:
|
||||
case cacheObjSubType[`msg_go`]:
|
||||
@ -595,6 +598,7 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
log.Printf("SQLIdentifyMsgWorker[" + strconv.Itoa(id) + "] : Closing.")
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user