diff --git a/bot.go b/bot.go index 2531553..f35c779 100644 --- a/bot.go +++ b/bot.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "log" + "os" "regexp" "strconv" "time" @@ -1350,3 +1351,7 @@ func botGetItemId(m *tb.Message) { return } + +func botShutdown() { + os.Exit(0) +} diff --git a/data/code_obj_sub_type.json b/data/code_obj_sub_type.json index 0b1a3b8..64a131c 100644 --- a/data/code_obj_sub_type.json +++ b/data/code_obj_sub_type.json @@ -24,6 +24,11 @@ "name": "Guild deposit chat", "obj_type": "msg" }, + { + "intl_id": "msg_bot_shutdown", + "name": "Request shutdown", + "obj_type": "msg" + }, { "intl_id": "msg_shop_main_req", "name": "Shop main request", diff --git a/rules.go b/rules.go index 40c50ac..f87947e 100644 --- a/rules.go +++ b/rules.go @@ -30,6 +30,16 @@ func resetMsgParsingRules() error { } 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) users := make([]int64, 0) chats = append(chats, cfg.Bot.Mainchat) diff --git a/workers.go b/workers.go index 8eb1355..9add398 100644 --- a/workers.go +++ b/workers.go @@ -548,6 +548,8 @@ func SQLIdentifyMsgWorker(id int, objIds <-chan int64) { botUserConfigPillage(m, true) case cacheObjSubType[`msg_bot_user_config_pillage_off`]: botUserConfigPillage(m, false) + case cacheObjSubType[`msg_bot_shutdown`]: + botShutdown() 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) }