This commit is contained in:
shoopea 2019-05-18 16:12:29 +08:00
parent e628d7303b
commit 0e7ba94f8b
2 changed files with 21 additions and 1 deletions

5
bot.go
View File

@ -177,8 +177,11 @@ func botMsgDump(m *tb.Message) {
r := regexp.MustCompile("^[0-9]+$") r := regexp.MustCompile("^[0-9]+$")
if r.MatchString(m.Payload) { if r.MatchString(m.Payload) {
objId, _ := strconv.ParseInt(m.Payload, 10, 64) objId, _ := strconv.ParseInt(m.Payload, 10, 64)
objSubTypeId, err := getObjSubTypeId(objId) objTypeId, err := getObjTypeId(objId)
logOnError(err, "botMsgDump : getObjSubTypeId")
if err != nil { if err != nil {
res = `Error retrieving the message`
} else if objTypeId != objTypeMessage {
res = `This is not a message reference` res = `This is not a message reference`
} else { } else {
cwm, err := getMsg(objId) cwm, err := getMsg(objId)

17
sql.go
View File

@ -1391,6 +1391,23 @@ func getMsg(objId int64) (*ChatWarsMessage, error) {
return m, nil return m, nil
} }
func getObjTypeId(objId int64) (int64, error) {
var objTypeId int64
stmt, err := db.Prepare(`SELECT o.obj_type_id FROM obj o WHERE o.id = ?`)
if err != nil {
return 0, err
}
defer stmt.Close()
err = stmt.QueryRow(objId).Scan(&objTypeId)
if err != nil {
return 0, err
}
return objTypeId, nil
}
func getObjSubTypeId(objId int64) (int64, error) { func getObjSubTypeId(objId int64) (int64, error) {
var objSubTypeId int64 var objSubTypeId int64