This commit is contained in:
cdle
2021-08-31 20:57:30 +08:00
parent 4ed9cdb8e8
commit a91d07323a
2 changed files with 22 additions and 5 deletions
@@ -1,9 +1,4 @@
# im:
# - type: qq
# masters:
# - 10000
# groups:
# - 100000000
# - type: tg
# token: xxxxx
# masters:
+22
View File
@@ -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()
}