This commit is contained in:
cdle
2023-06-07 19:15:27 +08:00
parent c74c9b130e
commit 1f02e78ea0
4 changed files with 64 additions and 16 deletions
+7 -7
View File
@@ -233,13 +233,13 @@ func initToHandleMessage() {
}
s.Reply("ok")
case "reply":
if data := noReplyGroups.GetBytes(cid); len(data) != 0 {
info := &GroupInfo{}
if info.Enable {
info.Enable = !info.Enable
noReplyGroups.Set(cid, utils.JsonMarshal(info))
}
}
// if data := noReplyGroups.GetBytes(cid); len(data) != 0 {
info := &GroupInfo{}
// if info.Enable {
// info.Enable = !info.Enable
noReplyGroups.Set(cid, utils.JsonMarshal(info))
// }
// }
s.Reply("ok")
case "noreply", "unreply":
if data := noReplyGroups.GetBytes(cid); len(data) == 0 {
+12 -8
View File
@@ -5,7 +5,7 @@ import (
"os"
"regexp"
"runtime"
"syscall"
"strings"
"time"
"github.com/beego/beego/v2/adapter/httplib"
@@ -65,8 +65,8 @@ func Init() {
}
console.Debug("正在创建编译文件...")
filename := utils.ExecPath + "/" + utils.ProcessName
ready := filename + ".ready"
if f, err := os.OpenFile(ready, syscall.O_CREAT, 0777); err != nil {
ready := strings.Replace(filename, ".exe", ".ready.exe", -1)
if f, err := os.OpenFile(ready, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0777); err != nil {
console.Error("创建编译文件错误:%v", err)
return &storage.Final{
Error: fmt.Errorf("创建编译文件错误:%v", err),
@@ -84,11 +84,15 @@ func Init() {
}
}
}
console.Debug("正在删除旧程序错误...")
if err = os.RemoveAll(filename); err != nil {
console.Error("删除旧程序错误:%v", err)
return &storage.Final{
Error: fmt.Errorf("删除旧程序错误:%v", err),
if runtime.GOOS == "window" {
utils.Daemon("ready")
} else {
console.Debug("正在删除旧程序错误...")
if err = os.RemoveAll(filename); err != nil {
console.Error("删除旧程序错误:%v", err)
return &storage.Final{
Error: fmt.Errorf("删除旧程序错误:%v", err),
}
}
}
console.Debug("正在移动新程序错误...")
+8
View File
@@ -3,6 +3,7 @@ package main
import (
"bufio"
"os"
"strings"
"time"
_ "github.com/cdle/sillyplus/adapters/qq"
@@ -26,6 +27,13 @@ func main() {
if arg == "-d" {
d = true
}
if arg == "-r" && strings.Contains(os.Args[0], ".ready.exe") { //准备程序还原程序
err := utils.CopyFile(utils.ProcessName, strings.Replace(utils.ProcessName, "ready.exe", ".exe", -1))
if err == nil {
utils.Daemon("reset")
}
continue
}
}
if !d {
t := false
+37 -1
View File
@@ -6,6 +6,7 @@ import (
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"os"
"os/exec"
@@ -169,8 +170,43 @@ func GetPidFromFile(pidFile string) (int, error) {
return pid, nil
}
func Daemon() {
func CopyFile(src string, dst string) error {
// 打开源文件
srcFile, err := os.Open(src)
if err != nil {
return err
}
defer srcFile.Close()
// 创建目标文件,如果目标文件已存在则覆盖
dstFile, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return err
}
defer dstFile.Close()
// 将源文件内容复制到目标文件
_, err = io.Copy(dstFile, srcFile)
if err != nil {
return err
}
return nil
}
func Daemon(str ...string) {
first := ""
if len(str) > 0 {
first = str[0]
}
args := os.Args[1:]
if first == "ready" {
os.Args[0] = strings.Replace(os.Args[0], ".exe", ".ready.exe", -1)
args = append(args, "-r")
}
if first == "reset" {
os.Args[0] = strings.Replace(os.Args[0], ".ready.exe", ".exe", -1)
}
execArgs := make([]string, 0)
l := len(args)
for i := 0; i < l; i++ {