update
This commit is contained in:
+1
-1
@@ -26,7 +26,7 @@ func init() {
|
|||||||
if _, err := os.Stat(confDir); err != nil {
|
if _, err := os.Stat(confDir); err != nil {
|
||||||
os.MkdirAll(confDir, os.ModePerm)
|
os.MkdirAll(confDir, os.ModePerm)
|
||||||
}
|
}
|
||||||
for _, name := range []string{"app.conf", "config.yaml", "reply.php"} {
|
for _, name := range []string{"config.yaml"} {
|
||||||
f, err := os.OpenFile(ExecPath+"/conf/"+name, os.O_RDWR|os.O_CREATE, 0777)
|
f, err := os.OpenFile(ExecPath+"/conf/"+name, os.O_RDWR|os.O_CREATE, 0777)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logs.Warn(err)
|
logs.Warn(err)
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/astaxie/beego/logs"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Daemon() {
|
||||||
|
args := os.Args[1:]
|
||||||
|
execArgs := make([]string, 0)
|
||||||
|
l := len(args)
|
||||||
|
for i := 0; i < l; i++ {
|
||||||
|
if strings.Index(args[i], "-d") == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
execArgs = append(execArgs, args[i])
|
||||||
|
}
|
||||||
|
proc := exec.Command(os.Args[0], execArgs...)
|
||||||
|
err := proc.Start()
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
logs.Info("傻妞以静默形式运行")
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
@@ -2,8 +2,12 @@ package core
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"os/exec"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/beego/beego/v2/core/logs"
|
||||||
"github.com/cdle/sillyGirl/im"
|
"github.com/cdle/sillyGirl/im"
|
||||||
"github.com/cdle/sillyGirl/im/tg"
|
"github.com/cdle/sillyGirl/im/tg"
|
||||||
tb "gopkg.in/tucnak/telebot.v2"
|
tb "gopkg.in/tucnak/telebot.v2"
|
||||||
@@ -16,6 +20,8 @@ type Function struct {
|
|||||||
Handle func(s im.Sender) bool
|
Handle func(s im.Sender) bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var pname = regexp.MustCompile(`/([^/\s]+)`).FindStringSubmatch(os.Args[0])[1]
|
||||||
|
|
||||||
var functions = []Function{
|
var functions = []Function{
|
||||||
{
|
{
|
||||||
Rules: []string{"^傻妞 (.*)$", "^傻妞$"},
|
Rules: []string{"^傻妞 (.*)$", "^傻妞$"},
|
||||||
@@ -29,11 +35,56 @@ var functions = []Function{
|
|||||||
return true
|
return true
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Rules: []string{"^升级$"},
|
||||||
|
Handle: func(s im.Sender) bool {
|
||||||
|
s.Reply("傻妞开始拉取代码。")
|
||||||
|
rtn, err := exec.Command("sh", "-c", "cd "+ExecPath+" && git stash && git pull").Output()
|
||||||
|
if err != nil {
|
||||||
|
s.Reply("傻妞拉取代失败:" + err.Error() + "。")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
t := string(rtn)
|
||||||
|
if !strings.Contains(t, "changed") {
|
||||||
|
if strings.Contains(t, "Already") || strings.Contains(t, "已经是最新") {
|
||||||
|
s.Reply("傻妞已是最新版啦。")
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
s.Reply("傻妞拉取代失败:" + t + "。")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
s.Reply("傻妞拉取代码成功。")
|
||||||
|
}
|
||||||
|
s.Reply("傻妞正在编译程序。")
|
||||||
|
rtn, err = exec.Command("sh", "-c", "cd "+ExecPath+" && go build -o "+pname).Output()
|
||||||
|
if err != nil {
|
||||||
|
s.Reply("傻妞编译失败:" + err.Error())
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
s.Reply("傻妞编译成功。")
|
||||||
|
}
|
||||||
|
s.Reply("傻妞重启程序。")
|
||||||
|
Daemon()
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Rules: []string{"^重启$"},
|
||||||
|
Handle: func(s im.Sender) bool {
|
||||||
|
s.Reply("傻妞重启程序。")
|
||||||
|
Daemon()
|
||||||
|
return true
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var Senders chan im.Sender
|
var Senders chan im.Sender
|
||||||
|
|
||||||
func initToHandleMessage() {
|
func initToHandleMessage() {
|
||||||
|
if len(Config.Im) == 0 {
|
||||||
|
logs.Warn("未配置置通讯工具")
|
||||||
|
}
|
||||||
for _, im := range Config.Im {
|
for _, im := range Config.Im {
|
||||||
switch im.Type {
|
switch im.Type {
|
||||||
case "tg":
|
case "tg":
|
||||||
|
|||||||
Reference in New Issue
Block a user