x
This commit is contained in:
+5
-5
@@ -233,13 +233,13 @@ func initToHandleMessage() {
|
|||||||
}
|
}
|
||||||
s.Reply("ok")
|
s.Reply("ok")
|
||||||
case "reply":
|
case "reply":
|
||||||
if data := noReplyGroups.GetBytes(cid); len(data) != 0 {
|
// if data := noReplyGroups.GetBytes(cid); len(data) != 0 {
|
||||||
info := &GroupInfo{}
|
info := &GroupInfo{}
|
||||||
if info.Enable {
|
// if info.Enable {
|
||||||
info.Enable = !info.Enable
|
// info.Enable = !info.Enable
|
||||||
noReplyGroups.Set(cid, utils.JsonMarshal(info))
|
noReplyGroups.Set(cid, utils.JsonMarshal(info))
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
s.Reply("ok")
|
s.Reply("ok")
|
||||||
case "noreply", "unreply":
|
case "noreply", "unreply":
|
||||||
if data := noReplyGroups.GetBytes(cid); len(data) == 0 {
|
if data := noReplyGroups.GetBytes(cid); len(data) == 0 {
|
||||||
|
|||||||
+7
-3
@@ -5,7 +5,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"runtime"
|
"runtime"
|
||||||
"syscall"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/adapter/httplib"
|
"github.com/beego/beego/v2/adapter/httplib"
|
||||||
@@ -65,8 +65,8 @@ func Init() {
|
|||||||
}
|
}
|
||||||
console.Debug("正在创建编译文件...")
|
console.Debug("正在创建编译文件...")
|
||||||
filename := utils.ExecPath + "/" + utils.ProcessName
|
filename := utils.ExecPath + "/" + utils.ProcessName
|
||||||
ready := filename + ".ready"
|
ready := strings.Replace(filename, ".exe", ".ready.exe", -1)
|
||||||
if f, err := os.OpenFile(ready, syscall.O_CREAT, 0777); err != nil {
|
if f, err := os.OpenFile(ready, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0777); err != nil {
|
||||||
console.Error("创建编译文件错误:%v", err)
|
console.Error("创建编译文件错误:%v", err)
|
||||||
return &storage.Final{
|
return &storage.Final{
|
||||||
Error: fmt.Errorf("创建编译文件错误:%v", err),
|
Error: fmt.Errorf("创建编译文件错误:%v", err),
|
||||||
@@ -84,6 +84,9 @@ func Init() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if runtime.GOOS == "window" {
|
||||||
|
utils.Daemon("ready")
|
||||||
|
} else {
|
||||||
console.Debug("正在删除旧程序错误...")
|
console.Debug("正在删除旧程序错误...")
|
||||||
if err = os.RemoveAll(filename); err != nil {
|
if err = os.RemoveAll(filename); err != nil {
|
||||||
console.Error("删除旧程序错误:%v", err)
|
console.Error("删除旧程序错误:%v", err)
|
||||||
@@ -91,6 +94,7 @@ func Init() {
|
|||||||
Error: fmt.Errorf("删除旧程序错误:%v", err),
|
Error: fmt.Errorf("删除旧程序错误:%v", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
console.Debug("正在移动新程序错误...")
|
console.Debug("正在移动新程序错误...")
|
||||||
if err = os.Rename(ready, filename); err != nil {
|
if err = os.Rename(ready, filename); err != nil {
|
||||||
console.Error("移动新程序错误:%v", err)
|
console.Error("移动新程序错误:%v", err)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
_ "github.com/cdle/sillyplus/adapters/qq"
|
_ "github.com/cdle/sillyplus/adapters/qq"
|
||||||
@@ -26,6 +27,13 @@ func main() {
|
|||||||
if arg == "-d" {
|
if arg == "-d" {
|
||||||
d = true
|
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 {
|
if !d {
|
||||||
t := false
|
t := false
|
||||||
|
|||||||
+37
-1
@@ -6,6 +6,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@@ -169,8 +170,43 @@ func GetPidFromFile(pidFile string) (int, error) {
|
|||||||
return pid, nil
|
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:]
|
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)
|
execArgs := make([]string, 0)
|
||||||
l := len(args)
|
l := len(args)
|
||||||
for i := 0; i < l; i++ {
|
for i := 0; i < l; i++ {
|
||||||
|
|||||||
Reference in New Issue
Block a user