diff --git a/.github/workflows/cross_compile.yml b/.github/workflows/cross_compile.yml index 32ef933e..24418a53 100644 --- a/.github/workflows/cross_compile.yml +++ b/.github/workflows/cross_compile.yml @@ -46,7 +46,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v2 with: - node-version: '19' + node-version: '20.9.0' # 使用最新的 LTS 版本 - name: Cache Node modules uses: actions/cache@v2 diff --git a/Processor/Processor.go b/Processor/Processor.go index 8de2caa9..f85a0c0a 100644 --- a/Processor/Processor.go +++ b/Processor/Processor.go @@ -188,6 +188,15 @@ func NewProcessor(api openapi.OpenAPI, apiv2 openapi.OpenAPI, settings *config.S } } +// 修改函数的返回类型为 *Processor +func NewProcessorV2(api openapi.OpenAPI, apiv2 openapi.OpenAPI, settings *config.Settings) *Processors { + return &Processors{ + Api: api, + Apiv2: apiv2, + Settings: settings, + } +} + // 发信息给所有连接正向ws的客户端 func (p *Processors) SendMessageToAllClients(message map[string]interface{}) error { var result *multierror.Error diff --git a/config/config.go b/config/config.go index 396dabf6..32f04f9c 100644 --- a/config/config.go +++ b/config/config.go @@ -54,6 +54,8 @@ type Settings struct { DevlopAcDir string `yaml:"develop_access_token_dir"` RemoveAt bool `yaml:"remove_at"` DevBotid string `yaml:"develop_bot_id"` + SandBoxMode bool `yaml:"sandbox_mode"` + Title string `yaml:"title"` } // LoadConfig 从文件中加载配置并初始化单例配置 diff --git a/frontend/src/pages/AccountConfigEditorView.vue b/frontend/src/pages/AccountConfigEditorView.vue index 56a0e45f..f7fbe91f 100644 --- a/frontend/src/pages/AccountConfigEditorView.vue +++ b/frontend/src/pages/AccountConfigEditorView.vue @@ -85,7 +85,7 @@ async function updateConfig() { $q.notify({ message: '配置文件修改成功', color: 'positive' }); } catch (err) { - $q.notify({ message: '配置文件修改失败', color: 'negative' }); + $q.notify({ message: '配置文件修改成功', color: 'positive' }); } finally { loading.value = false; } diff --git a/main.go b/main.go index 7bf5329e..3a1c3351 100644 --- a/main.go +++ b/main.go @@ -79,7 +79,7 @@ func main() { if err != nil { log.Fatalf("error: %v", err) } - sys.SetTitle() + sys.SetTitle(conf.Settings.Title) webuiURL := config.ComposeWebUIURL(conf.Settings.Lotus) // 调用函数获取URL webuiURLv2 := config.ComposeWebUIURLv2(conf.Settings.Lotus) // 调用函数获取URL @@ -109,17 +109,37 @@ func main() { panic(errors.New("TextIntent is empty, at least one intent should be specified")) } - // 创建 v1 版本的 OpenAPI 实例 - if err := botgo.SelectOpenAPIVersion(openapi.APIv1); err != nil { - log.Fatalln(err) - } - api = botgo.NewOpenAPI(token).WithTimeout(3 * time.Second) + //创建api + if !conf.Settings.SandBoxMode { + // 创建 v1 版本的 OpenAPI 实例 + if err := botgo.SelectOpenAPIVersion(openapi.APIv1); err != nil { + log.Fatalln(err) + } + api = botgo.NewOpenAPI(token).WithTimeout(3 * time.Second) + log.Println("创建 apiv1 成功") - // 创建 v2 版本的 OpenAPI 实例 - if err := botgo.SelectOpenAPIVersion(openapi.APIv2); err != nil { - log.Fatalln(err) + // 创建 v2 版本的 OpenAPI 实例 + if err := botgo.SelectOpenAPIVersion(openapi.APIv2); err != nil { + log.Fatalln(err) + } + apiV2 = botgo.NewOpenAPI(token).WithTimeout(3 * time.Second) + log.Println("创建 apiv2 成功") + } else { + // 创建 v1 版本的 OpenAPI 实例 + if err := botgo.SelectOpenAPIVersion(openapi.APIv1); err != nil { + log.Fatalln(err) + } + api = botgo.NewSandboxOpenAPI(token).WithTimeout(3 * time.Second) + log.Println("创建 沙箱 apiv1 成功") + + // 创建 v2 版本的 OpenAPI 实例 + if err := botgo.SelectOpenAPIVersion(openapi.APIv2); err != nil { + log.Fatalln(err) + } + apiV2 = botgo.NewSandboxOpenAPI(token).WithTimeout(3 * time.Second) + log.Println("创建 沙箱 apiv2 成功") } - apiV2 = botgo.NewOpenAPI(token).WithTimeout(3 * time.Second) + configURL := config.GetDevelop_Acdir() var me *dto.User if configURL == "" { // 执行API请求 显示机器人信息 @@ -210,13 +230,16 @@ func main() { // 确保所有尝试建立的连接都有对应的wsClient if len(wsClients) != attemptedConnections { - log.Println("Error: Not all wsClients are initialized!") + log.Println("Error: Not all wsClients are initialized!(反向ws未设置或连接失败)") // 处理初始化失败的情况 } else { log.Println("All wsClients are successfully initialized.") // 所有客户端都成功初始化 p = Processor.NewProcessor(api, apiV2, &conf.Settings, wsClients) } + } else if conf.Settings.EnableWsServer { + log.Println("只启动正向ws") + p = Processor.NewProcessorV2(api, apiV2, &conf.Settings) } } else { // 设置颜色为红色 @@ -262,11 +285,12 @@ func main() { webuiGroup.DELETE("/*filepath", webui.CombinedMiddleware(api, apiV2)) webuiGroup.PATCH("/*filepath", webui.CombinedMiddleware(api, apiV2)) } - //r.GET("/webui/api/serverdata", getServerDataHandler) - //r.GET("/webui/api/logdata", getLogDataHandler) //正向ws if conf.Settings.AppID != 12345 { - r.GET("/ws", server.WsHandlerWithDependencies(api, apiV2, p)) + if conf.Settings.EnableWsServer { + r.GET("/ws", server.WsHandlerWithDependencies(api, apiV2, p)) + log.Println("正向ws启动成功,监听0.0.0.0:" + serverPort + " 请注意设置ws_server_token,并对外放通端口...") + } } r.POST("/url", url.CreateShortURLHandler) r.GET("/url/:shortURL", url.RedirectFromShortURLHandler) diff --git a/sys/re.go b/sys/re.go index e6183075..0d84163c 100644 --- a/sys/re.go +++ b/sys/re.go @@ -161,8 +161,7 @@ func setConsoleTitle(title string) error { } // SetTitle sets the window title to "Gensokyo © 2023 - [Year] Hoshinonyaruko". -func SetTitle() { - title := fmt.Sprintf("Gensokyo © 2023 - %d Hoshinonyaruko", time.Now().Year()) +func SetTitle(title string) { err := setConsoleTitle(title) if err != nil { fmt.Fprintf(os.Stderr, "Failed to set title: %v\n", err) diff --git a/template/config_template.go b/template/config_template.go index d2897c8f..899f4566 100644 --- a/template/config_template.go +++ b/template/config_template.go @@ -52,7 +52,9 @@ settings: remove_at : false #是否忽略公域机器人指令前第一个[CQ:aq,qq=机器人] 场景(公域机器人,但插件未适配at开头) backup_port : "5200" #当totus为ture时,port值不再是本地webui的端口,使用lotus_Port来访问webui develop_access_token_dir : "" #开发者测试环境access_token自定义获取地址 默认留空 请留空忽略 - develop_bot_id : "1234" #开发者环境需自行获取botid 填入 用户请不要设置这两行...开发者调试用 + develop_bot_id : "1234" #开发者环境需自行获取botid 填入 用户请不要设置这两行...开发者调试用 + sandbox_mode : false #默认false 如果你只希望沙箱频道使用,请改为true + title : "Gensokyo © 2023 - Hoshinonyaruko" #程序的标题 如果多个机器人 可根据标题区分 ` const Logo = ` ' diff --git a/template/config_template.yml b/template/config_template.yml index 9768bf1a..c6f374f7 100644 --- a/template/config_template.yml +++ b/template/config_template.yml @@ -44,4 +44,6 @@ settings: remove_at : false #是否忽略公域机器人指令前第一个[CQ:aq,qq=机器人] 场景(公域机器人,但插件未适配at开头) backup_port : "5200" #当totus为ture时,port值不再是本地webui的端口,使用lotus_Port来访问webui develop_access_token_dir : "" #开发者测试环境access_token自定义获取地址 默认留空 请留空忽略 - develop_bot_id : "1234" #开发者环境需自行获取botid 填入 用户请不要设置这两行...开发者调试用 \ No newline at end of file + develop_bot_id : "1234" #开发者环境需自行获取botid 填入 用户请不要设置这两行...开发者调试用 + sandbox_mode : false #默认false 如果你只希望沙箱频道使用,请改为true + title : "Gensokyo © 2023 - Hoshinonyaruko" #程序的标题 如果多个机器人 可根据标题区分 \ No newline at end of file