refactor: 重构消息发送模型

This commit is contained in:
lixiangwuxian
2024-10-28 02:58:08 +08:00
parent fe863a9ac8
commit 7e28953a56
10 changed files with 196 additions and 16 deletions

View File

@@ -20,6 +20,7 @@ func init() {
handler.RegisterHandler("/构建bot", build, constants.LEVEL_ADMIN)
handler.RegisterHandler("/构建重启", buildAndRestart, constants.LEVEL_ADMIN)
handler.RegisterHandler("/gitpull", pullCode, constants.LEVEL_ADMIN)
handler.RegisterHandler("/shutdown", shutdown, constants.LEVEL_ADMIN)
}
func restart(msg model.Message) model.Reply {
@@ -38,6 +39,15 @@ func restart(msg model.Message) model.Reply {
}
}
func shutdown(msg model.Message) model.Reply {
go shutdownProgram()
return model.Reply{
ReplyMsg: "关闭中...",
ReferOriginMsg: true,
FromMsg: msg,
}
}
func build(msg model.Message) model.Reply {
err := buildBot()
if err != nil {
@@ -117,6 +127,14 @@ func restartProgram() error {
return nil
}
func shutdownProgram() error {
log.Println("关闭程序...")
docker.DockerContainer.RemoveContainer()
time.Sleep(500 * time.Millisecond)
os.Exit(0)
return nil
}
func buildBot() error {
hasVaildBuild = false
workDir, err := os.Getwd()