From a91d07323a789ed5584625fa9165652285481995 Mon Sep 17 00:00:00 2001 From: cdle <798731886@qq.com> Date: Tue, 31 Aug 2021 20:57:30 +0800 Subject: [PATCH] update --- conf/{config_demo.yaml => demo_config.yaml} | 5 ----- core/config.go | 22 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) rename conf/{config_demo.yaml => demo_config.yaml} (93%) diff --git a/conf/config_demo.yaml b/conf/demo_config.yaml similarity index 93% rename from conf/config_demo.yaml rename to conf/demo_config.yaml index eb64497..1ecd560 100644 --- a/conf/config_demo.yaml +++ b/conf/demo_config.yaml @@ -1,9 +1,4 @@ # im: -# - type: qq -# masters: -# - 10000 -# groups: -# - 100000000 # - type: tg # token: xxxxx # masters: diff --git a/core/config.go b/core/config.go index 4a438e2..2f2548d 100644 --- a/core/config.go +++ b/core/config.go @@ -1,11 +1,13 @@ package core import ( + "io" "io/ioutil" "os" "path/filepath" "github.com/astaxie/beego/logs" + "github.com/beego/beego/v2/adapter/httplib" "github.com/cdle/sillyGirl/im" "gopkg.in/yaml.v2" ) @@ -20,6 +22,25 @@ var ExecPath, _ = filepath.Abs(filepath.Dir(os.Args[0])) var Config Yaml func init() { + confDir := ExecPath + "/conf" + if _, err := os.Stat(confDir); err != nil { + os.MkdirAll(confDir, os.ModePerm) + } + for _, name := range []string{"app.conf", "config.yaml", "reply.php"} { + f, err := os.OpenFile(ExecPath+"/conf/"+name, os.O_RDWR|os.O_CREATE, 0777) + if err != nil { + logs.Warn(err) + } + s, _ := ioutil.ReadAll(f) + if len(s) == 0 { + logs.Info("下载配置%s", name) + r, err := httplib.Get("https://ghproxy.com/" + "https://raw.githubusercontent.com/cdle/xdd/main/conf/demo_" + name).Response() + if err == nil { + io.Copy(f, r.Body) + } + } + f.Close() + } content, err := ioutil.ReadFile(ExecPath + "/conf/config.yaml") if err != nil { logs.Warn("解析config.yaml读取错误: %v", err) @@ -27,6 +48,7 @@ func init() { if yaml.Unmarshal(content, &Config) != nil { logs.Warn("解析config.yaml出错: %v", err) } + InitReplies() initToHandleMessage() }