diff --git a/.gitignore b/.gitignore index f3e8653..2182745 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ dwz replies qinglongs sets.conf -_* \ No newline at end of file +_* +*.exe \ No newline at end of file diff --git a/core/function.go b/core/function.go index 5c57a0a..44b5cb0 100644 --- a/core/function.go +++ b/core/function.go @@ -5,6 +5,7 @@ import ( "net/url" "os" "regexp" + "runtime" "strings" "github.com/beego/beego/v2/core/logs" @@ -14,6 +15,9 @@ import ( var c *cron.Cron func init() { + if runtime.GOOS != "windows" { + pname = regexp.MustCompile(`/([^/\s]+)$`).FindStringSubmatch(os.Args[0])[1] + } c = cron.New() c.Start() } @@ -26,7 +30,7 @@ type Function struct { Cron string } -var pname = regexp.MustCompile(`/([^/\s]+)$`).FindStringSubmatch(os.Args[0])[1] +var pname = "" var name = func() string { return sillyGirl.Get("name", "傻妞") diff --git a/core/init.go b/core/init.go index 6588ba0..46543d0 100644 --- a/core/init.go +++ b/core/init.go @@ -22,7 +22,7 @@ func init() { } } initStore() - ReadYaml(ExecPath+"/conf/", &Config, "https://raw.githubusercontent.com/cdle/sillyGirl/main/conf/demo_config.yaml") + ReadYaml("conf/", &Config, "https://raw.githubusercontent.com/cdle/sillyGirl/main/conf/demo_config.yaml") InitReplies() initToHandleMessage() file, err := os.Open("/etc/sillyGirl/sets.conf") diff --git a/core/otto.go b/core/otto.go index 8899ddb..5e6a86a 100644 --- a/core/otto.go +++ b/core/otto.go @@ -27,9 +27,10 @@ func init() { var OttoFuncs = map[string]func(string) string{} func init123() { - files, err := ioutil.ReadDir(ExecPath + "/develop/replies") + files, err := ioutil.ReadDir("develop/replies") if err != nil { - logs.Warn("打开文件夹%s错误,%v", ExecPath+"/develop/replies", err) + os.MkdirAll("develop/replies", os.ModePerm) + // logs.Warn("打开文件夹%s错误,%v", "develop/replies", err) return } @@ -114,7 +115,7 @@ func init123() { if v.IsDir() { continue } - jr := string(ExecPath + "/develop/replies/" + v.Name()) + jr := string("develop/replies/" + v.Name()) data := "" if strings.Contains(jr, "http") { data, err = httplib.Get(jr).String() diff --git a/core/store.go b/core/store.go index 1310057..19354f5 100644 --- a/core/store.go +++ b/core/store.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "reflect" + "runtime" "strconv" "github.com/boltdb/bolt" @@ -23,11 +24,12 @@ func NewBucket(name string) Bucket { } func initStore() { - // if _, err := os.Stat(ExecPath + "/sillyGirl.cache"); err == nil { - // os.Rename(ExecPath+"/sillyGirl.cache", "/etc/sillyGirl/sillyGirl.cache") - // } var err error - db, err = bolt.Open("/etc/sillyGirl/sillyGirl.cache", 0600, nil) + if runtime.GOOS != "windows" { + db, err = bolt.Open("/etc/sillyGirl/sillyGirl.cache", 0600, nil) + } else { + db, err = bolt.Open(`C:\ProgramData\sillyGirl.cache`, 0600, nil) + } if err != nil { panic(err) } diff --git a/core/test.go b/core/test.go index 7ea44f8..3f2f7a5 100644 --- a/core/test.go +++ b/core/test.go @@ -7,6 +7,7 @@ import ( "os" "os/exec" "regexp" + "runtime" "strings" "time" @@ -58,6 +59,9 @@ func initSys() { Cron: "*/1 * * * *", Admin: true, Handle: func(s Sender) interface{} { + if runtime.GOOS == "windows" { + return "windows系统不支持此命令" + } if s.GetImType() == "fake" && !sillyGirl.GetBool("auto_update", true) { return nil } diff --git a/im/qq/main.go b/im/qq/main.go index 0cabad3..58f835f 100644 --- a/im/qq/main.go +++ b/im/qq/main.go @@ -283,7 +283,7 @@ func start() { core.GroupPushs["qq"] = func(i, _ interface{}, s string) { paths := []string{} for _, v := range regexp.MustCompile(`\[TG:image,file=([^\[\]]+)\]`).FindAllStringSubmatch(s, -1) { - paths = append(paths, core.ExecPath+"/data/images/"+v[1]) + paths = append(paths, "data/images/"+v[1]) s = strings.Replace(s, fmt.Sprintf(`[TG:image,file=%s]`, v[1]), "", -1) } imgs := []message.IMessageElement{} diff --git a/im/tg/tg.go b/im/tg/tg.go index 2959525..b65e8df 100644 --- a/im/tg/tg.go +++ b/im/tg/tg.go @@ -64,8 +64,7 @@ func init() { Token: token, Poller: &tb.LongPoller{Timeout: 10 * time.Second}, // ParseMode: tb.ModeMarkdownV2, - URL: tg.Get("url"), - + URL: tg.Get("url"), } if url := tg.Get("http_proxy"); url != "" { client, clientErr := buildClientWithProxy(url) @@ -89,7 +88,7 @@ func init() { paths := []string{} ct := &tb.Chat{ID: core.Int64(i)} for _, v := range regexp.MustCompile(`\[CQ:image,file=([^\[\]]+)\]`).FindAllStringSubmatch(s, -1) { - paths = append(paths, core.ExecPath+"/data/images/"+v[1]) + paths = append(paths, "data/images/"+v[1]) s = strings.Replace(s, fmt.Sprintf(`[CQ:image,file=%s]`, v[1]), "", -1) } s = regexp.MustCompile(`\[CQ:([^\[\]]+)\]`).ReplaceAllString(s, "") @@ -133,7 +132,7 @@ func init() { } b.Handle(tb.OnPhoto, func(m *tb.Message) { filename := fmt.Sprint(time.Now().UnixNano()) + ".image" - filepath := core.ExecPath + "/data/images/" + filename + filepath := "data/images/" + filename if b.Download(&m.Photo.File, filepath) == nil { m.Text = fmt.Sprintf(`[TG:image,file=%s]`, filename) + m.Caption Handler(m) @@ -154,7 +153,7 @@ func init() { // return // } // filename := fmt.Sprint(time.Now().UnixNano()) + ".image" - // filepath := core.ExecPath + "/data/images/" + filename + // filepath := "data/images/" + filename // f, err := os.Create(filepath) // if err != nil { // return @@ -179,7 +178,11 @@ func (sender *Sender) GetUserID() interface{} { } func (sender *Sender) GetChatID() interface{} { - return int(sender.Message.Chat.ID) + if sender.Message.Private() { + return 0 + } else { + return int(sender.Message.Chat.ID) + } } func (sender *Sender) GetImType() string { @@ -284,7 +287,7 @@ func (sender *Sender) Reply(msgs ...interface{}) (int, error) { sender.Reply(err) return 0, nil } else { - rts,err := b.SendAlbum(r, tb.Album{&tb.Photo{File: tb.FromReader(f)}}, options...) + rts, err := b.SendAlbum(r, tb.Album{&tb.Photo{File: tb.FromReader(f)}}, options...) if err == nil { rt = &rts[0] } diff --git a/im/wx/init.go b/im/wx/init.go index ec0d75b..c8495a0 100644 --- a/im/wx/init.go +++ b/im/wx/init.go @@ -112,7 +112,7 @@ func init() { } for _, v := range regexp.MustCompile(`\[CQ:image,file=([^\[\]]+)\]`).FindAllStringSubmatch(s, -1) { s = strings.Replace(s, fmt.Sprintf(`[CQ:image,file=%s]`, v[1]), "", -1) - data, err := os.ReadFile(core.ExecPath + "/data/images/" + v[1]) + data, err := os.ReadFile("data/images/" + v[1]) if err == nil { add := regexp.MustCompile("(https.*)").FindString(string(data)) if add != "" { diff --git a/im/wxmp/init.go b/im/wxmp/init.go index 8c55b61..96e47f7 100644 --- a/im/wxmp/init.go +++ b/im/wxmp/init.go @@ -21,7 +21,7 @@ var u2i = core.NewBucket("wxmpu2i") var material = core.NewBucket("wxmpMaterial") func init() { - file_dir := core.ExecPath + "/logs/wxmp/" + file_dir := "logs/wxmp/" os.MkdirAll(file_dir, os.ModePerm) core.Server.Any("/wx/", func(c *gin.Context) { wc := wechat.NewWechat()