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
+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)
})
}
}
}