From 5b313d8ad9a24a2728c1c359252abdc8e224f093 Mon Sep 17 00:00:00 2001 From: cdle Date: Mon, 12 Jun 2023 12:07:12 +0800 Subject: [PATCH] x --- adapters/web/main.go | 51 +++++++++++++++++++++++++------------------- core/carry.go | 5 +---- core/init.go | 4 ++++ core/web.go | 15 +++++++------ 4 files changed, 42 insertions(+), 33 deletions(-) diff --git a/adapters/web/main.go b/adapters/web/main.go index f013c2c..06e29fc 100644 --- a/adapters/web/main.go +++ b/adapters/web/main.go @@ -74,31 +74,38 @@ var GetUserNumber = func() int { return i } +func initWebBot() { + if adapter == nil { + adapter = &core.Factory{} + adapter.Init("web", "default") + adapter.SetIsAdmin(func(s string) bool { + isAdmin, ok := webAdmins.Load(s) + if ok { + return isAdmin.(bool) + } + return false + }) + adapter.SetReplyHandler(func(msg map[string]string) string { + message := WebMessage{ + UserID: msg[core.USER_ID], + Images: []string{}, + Type: "chat", + Content: msg[core.CONETNT], + } + sendWebMessage(&message) + return "" + }) + } +} + func init() { core.RegistFuncs["Broadcast2WebUser"] = Broadcast2WebUser - adapter = &core.Factory{} - adapter.Init("web", "default") - adapter.SetIsAdmin(func(s string) bool { - isAdmin, ok := webAdmins.Load(s) - if ok { - return isAdmin.(bool) - } - return false - }) - adapter.SetReplyHandler(func(msg map[string]string) string { - message := WebMessage{ - UserID: msg[core.USER_ID], - Images: []string{}, - Type: "chat", - Content: msg[core.CONETNT], - } - sendWebMessage(&message) - return "" - }) + go func() { + time.Sleep(time.Second) + initWebBot() + }() core.GinApi(core.GET, "/api/web_chat", func(ctx *gin.Context) { - // if adapter == nil { - - // } + initWebBot() rid := ctx.Query("rid") ctt := ctx.Query("ctt") token, _ := ctx.Cookie("token") diff --git a/core/carry.go b/core/carry.go index 5f25d87..915e351 100644 --- a/core/carry.go +++ b/core/carry.go @@ -31,7 +31,7 @@ var CarryGroups = MakeBucket("CarryGroups") var carryCounter int64 // LOGIC -func init() { +func initCarry() { AddCommand([]*common.Function{ { Rules: []string{`raw [\s\S]+`}, @@ -198,10 +198,7 @@ func init() { }, }, }) -} -// VAR Watch -func init() { setCgs() storage.Watch(CarryGroups, nil, func(old, new, key string) *storage.Final { console.Log("已更新搬运数据") diff --git a/core/init.go b/core/init.go index 5909484..f5da3ab 100644 --- a/core/init.go +++ b/core/init.go @@ -18,6 +18,7 @@ import ( var DataHome = utils.GetDataHome() func Init() { + sillyGirl = MakeBucket("sillyGirl") _, err := os.Stat(DataHome) if err != nil { @@ -27,6 +28,8 @@ func Init() { initToHandleMessage() sillyGirl.Set("compiled_at", compiled_at) console.Log("编译版本:%s", compiled_at) + initWeb() + initCarry() sillyGirl.Set("started_at", time.Now().Format("2006-01-02 15:04:05")) storage.Watch(sillyGirl, "compiled_at", func(old, new, key string) *storage.Final { if old != new { @@ -148,4 +151,5 @@ func Init() { initWebPluginList() go initPluginList() initPluginPublish() + } diff --git a/core/web.go b/core/web.go index 8fcea14..894ed13 100644 --- a/core/web.go +++ b/core/web.go @@ -43,7 +43,7 @@ func Cors() gin.HandlerFunc { var Server *gin.Engine -func init() { +func initWeb() { for _, arg := range os.Args { //处理升级 if arg == "-r" { //准备程序->原程序 rfix := ".ready.exe" @@ -351,13 +351,14 @@ func init() { Now: new, } }) + + // logs.Info("Http服务(%s)开始运行", port) + logs.Info("管理员面板:") + logs.Info(" > 本机: http://localhost:%s", port) + local_ip := getLocalIP() + logs.Info(" > 局域网: http://%s:%s", local_ip, port) + sillyGirl.Set("local_ip", local_ip) go func() { - // logs.Info("Http服务(%s)开始运行", port) - logs.Info("管理员面板:") - logs.Info(" > 本机: http://localhost:%s", port) - local_ip := getLocalIP() - sillyGirl.Set("local_ip", local_ip) - logs.Info(" > 局域网: http://%s:%s", local_ip, port) if err := srvs[0].ListenAndServe(); err != nil && err != http.ErrServerClosed { logs.Error("Http服务运行失败:%s", err.Error()) }