This commit is contained in:
cdle
2021-09-14 20:44:05 +08:00
parent 802ed85ea5
commit 2545606147
7 changed files with 102 additions and 4 deletions
+2 -1
View File
@@ -4,4 +4,5 @@ sillyGirl
.vscode
dev.go
.DS_Store
develop/jd_cookie
develop/jd_cookie
*.cache
+14
View File
@@ -11,15 +11,24 @@ import (
"github.com/beego/beego/v2/core/logs"
"github.com/cdle/sillyGirl/im"
"github.com/cdle/sillyGirl/im/tg"
cron "github.com/robfig/cron/v3"
tb "gopkg.in/tucnak/telebot.v2"
)
var c *cron.Cron
func init() {
c = cron.New()
c.Start()
}
type Function struct {
Rules []string
FindAll bool
Admin bool
Handle func(s im.Sender) interface{}
Regex bool
Cron string
}
var pname = regexp.MustCompile(`/([^/\s]+)`).FindStringSubmatch(os.Args[0])[1]
@@ -124,6 +133,11 @@ func AddCommand(prefix string, cmds []Function) {
}
}
functions = append(functions, cmd)
if cmd.Cron != "" {
c.AddFunc(cmd.Cron, func() {
cmd.Handle(nil)
})
}
}
}
+39
View File
@@ -0,0 +1,39 @@
package core
import (
"github.com/boltdb/bolt"
)
var name = "sillyGirl"
var db *bolt.DB
func init() {
var err error
db, err = bolt.Open(ExecPath+"/"+name+".cache", 0600, nil)
if err != nil {
panic(err)
}
err = db.Update(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte(name))
if b == nil {
tx.CreateBucket([]byte(name))
}
return nil
})
}
func Set(key string, value string) {
db.Update(func(tx *bolt.Tx) error {
tx.Bucket([]byte(name)).Put([]byte(key), []byte(value))
return nil
})
}
func Get(key string) string {
value := ""
db.View(func(tx *bolt.Tx) error {
value = string(tx.Bucket([]byte(name)).Get([]byte(key)))
return nil
})
return value
}
+36
View File
@@ -0,0 +1,36 @@
package core
import (
"errors"
"github.com/cdle/sillyGirl/im"
)
func init() {
AddCommand("", []Function{
{
Rules: []string{"set ? ?"},
Handle: func(s im.Sender) interface{} {
Set(s.Get(0), s.Get(1))
return "设置成功"
},
},
{
Rules: []string{"delete ?"},
Handle: func(s im.Sender) interface{} {
Set(s.Get(), "")
return "删除成功"
},
},
{
Rules: []string{"get ?"},
Handle: func(s im.Sender) interface{} {
v := Get(s.Get())
if v == "" {
return errors.New("空值")
}
return v
},
},
})
}
+4 -3
View File
@@ -198,7 +198,8 @@ func init() {
{
Rules: []string{`cron hide duplicate`},
Admin: true,
Handle: func(s im.Sender) interface{} {
Cron: "*/10 * * * *",
Handle: func(_ im.Sender) interface{} {
w := func(s string) int {
if strings.Contains(s, "shufflewzc") {
return 1
@@ -232,9 +233,9 @@ func init() {
tasks[crons[i].Name] = crons[i]
}
if err := Req(CRONS, PUT, "/disable", []byte(fmt.Sprintf(`["%s"]`, dup.ID))); err != nil {
s.Reply(fmt.Sprintf("隐藏 %v %v %v", dup.Name, dup.Command, err))
// s.Reply(fmt.Sprintf("隐藏 %v %v %v", dup.Name, dup.Command, err))
} else {
s.Reply(fmt.Sprintf("已隐藏重复任务 %v %v", dup.Name, dup.Command))
// s.Reply(fmt.Sprintf("已隐藏重复任务 %v %v", dup.Name, dup.Command))
}
} else {
tasks[crons[i].Name] = crons[i]
+2
View File
@@ -5,7 +5,9 @@ go 1.16
require (
github.com/astaxie/beego v1.12.3
github.com/beego/beego/v2 v2.0.1
github.com/boltdb/bolt v1.3.1
github.com/buger/jsonparser v1.1.1
github.com/robfig/cron/v3 v3.0.1
gopkg.in/tucnak/telebot.v2 v2.4.0
gopkg.in/yaml.v2 v2.4.0
)
+5
View File
@@ -16,6 +16,8 @@ github.com/beego/x2j v0.0.0-20131220205130-a0352aadc542/go.mod h1:kSeGC/p1AbBiEp
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/bradfitz/gomemcache v0.0.0-20180710155616-bc664df96737/go.mod h1:PmM6Mmwb0LSuEubjR8N7PtNe1KxZLtOUHtbeikc5h60=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
@@ -128,6 +130,8 @@ github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB8
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644 h1:X+yvsM2yrEktyI+b2qND5gpH8YhURn0k8OCaeRnkINo=
github.com/shiena/ansicolor v0.0.0-20151119151921-a422bbe96644/go.mod h1:nkxAfR/5quYxwPZhyDxgasBMnRtBZd0FCEpawpjMUFg=
@@ -198,6 +202,7 @@ golang.org/x/sys v0.0.0-20191010194322-b09406accb47/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200106162015-b016eb3dc98e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=