test shutdown

This commit is contained in:
shoopea 2020-02-14 11:08:19 +08:00
parent 7fcbf15d51
commit 5cbca6d44c
4 changed files with 22 additions and 0 deletions

5
bot.go
View File

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"log" "log"
"os"
"regexp" "regexp"
"strconv" "strconv"
"time" "time"
@ -1350,3 +1351,7 @@ func botGetItemId(m *tb.Message) {
return return
} }
func botShutdown() {
os.Exit(0)
}

View File

@ -24,6 +24,11 @@
"name": "Guild deposit chat", "name": "Guild deposit chat",
"obj_type": "msg" "obj_type": "msg"
}, },
{
"intl_id": "msg_bot_shutdown",
"name": "Request shutdown",
"obj_type": "msg"
},
{ {
"intl_id": "msg_shop_main_req", "intl_id": "msg_shop_main_req",
"name": "Shop main request", "name": "Shop main request",

View File

@ -30,6 +30,16 @@ func resetMsgParsingRules() error {
} }
rules2 = append(rules2, r) rules2 = append(rules2, r)
r = MessageParsingRule{
Priority: 9999,
Description: "Shutdown",
Rule: "^/shutdown$",
MsgTypeID64: cacheObjSubType[`msg_bot_shutdown`],
ChatID64: cfg.Bot.Admin,
SenderUserID64: 0,
}
rules2 = append(rules2, r)
chats := make([]int64, 0) chats := make([]int64, 0)
users := make([]int64, 0) users := make([]int64, 0)
chats = append(chats, cfg.Bot.Mainchat) chats = append(chats, cfg.Bot.Mainchat)

View File

@ -548,6 +548,8 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) {
botUserConfigPillage(m, true) botUserConfigPillage(m, true)
case cacheObjSubType[`msg_bot_user_config_pillage_off`]: case cacheObjSubType[`msg_bot_user_config_pillage_off`]:
botUserConfigPillage(m, false) botUserConfigPillage(m, false)
case cacheObjSubType[`msg_bot_shutdown`]:
botShutdown()
default: 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) //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)
} }