x
This commit is contained in:
@@ -8,6 +8,6 @@
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script src="/admin/umi.99c0f090.js"></script>
|
||||
<script src="/admin/umi.7c524e1b.js"></script>
|
||||
|
||||
</body></html>
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+7
-3
@@ -269,9 +269,13 @@ func setCgs() {
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
if cg.In {
|
||||
AddListenOnGroup(cg.ID, fmt.Sprintf("已为采集群(%s)开启监听模式", cg.ID))
|
||||
AddNoReplyGroups(cg.ID, fmt.Sprintf("已为采集群(%s)开启禁言模式", cg.ID))
|
||||
if cg.In && cg.Enable {
|
||||
name := cg.ChatName
|
||||
if name == "" {
|
||||
name = cg.ID
|
||||
}
|
||||
AddListenOnGroup(cg.ID, fmt.Sprintf("已为采集群(%s)开启监听模式", name))
|
||||
AddNoReplyGroups(cg.ID, fmt.Sprintf("已为采集群(%s)开启禁言模式", name))
|
||||
}
|
||||
cgs = append(cgs, cg)
|
||||
return nil
|
||||
|
||||
@@ -11,11 +11,11 @@ type Function struct {
|
||||
FindAll bool `json:"-"`
|
||||
Admin bool `json:"-"`
|
||||
Handle func(Sender, func(vm *goja.Runtime)) interface{} `json:"-"`
|
||||
Cron string `json:"cron"`
|
||||
Cron map[string]string `json:"cron"`
|
||||
Priority int `json:"-"`
|
||||
Disable bool `json:"-"`
|
||||
Hidden bool `json:"-"`
|
||||
CronId int `json:"-"`
|
||||
CronIds []int `json:"-"`
|
||||
Origin string `json:"-"`
|
||||
UUID string `json:"id"`
|
||||
Title string `json:"title"`
|
||||
|
||||
+22
-16
@@ -376,24 +376,30 @@ func AddCommand(cmds []*common.Function) {
|
||||
}
|
||||
fmtRule(cmds[j])
|
||||
{
|
||||
if cmds[j].Cron != "" && !cmds[j].Disable && !cmds[j].Module && !cmds[j].OnStart {
|
||||
cron := strings.TrimSpace(cmds[j].Cron)
|
||||
if len(regexp.MustCompile(`\S+`).FindAllString(cron, -1)) == 5 {
|
||||
cmds[j].Cron = "0 " + cron
|
||||
}
|
||||
cronId, err := C.AddFunc(cmds[j].Cron, func() {
|
||||
cmds[j].Handle(&Faker{
|
||||
Admin: true,
|
||||
Type: "cron",
|
||||
}, nil)
|
||||
})
|
||||
if err == nil {
|
||||
cmds[j].CronId = int(cronId)
|
||||
// console["log"]("脚本%s添加定时器", cmds[j].Title)
|
||||
} else {
|
||||
console.Error("脚本%s定时器错误,%v", cmds[j].Title, err)
|
||||
if !cmds[j].Disable && !cmds[j].Module && !cmds[j].OnStart {
|
||||
for plt, Cron := range cmds[j].Cron {
|
||||
plt := plt
|
||||
cron := strings.TrimSpace(Cron)
|
||||
if len(regexp.MustCompile(`\S+`).FindAllString(cron, -1)) == 5 {
|
||||
Cron = "0 " + Cron
|
||||
}
|
||||
cronId, err := C.AddFunc(Cron, func() {
|
||||
cmds[j].Handle(&Faker{
|
||||
Admin: true,
|
||||
Type: plt,
|
||||
}, nil)
|
||||
})
|
||||
if err == nil {
|
||||
cmds[j].CronIds = append(cmds[j].CronIds, int(cronId))
|
||||
// console["log"]("脚本%s添加定时器", cmds[j].Title)
|
||||
} else {
|
||||
console.Error("脚本%s定时器错误,%v", cmds[j].Title, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
// if cmds[j].Cron != "" && !cmds[j].Disable && !cmds[j].Module && !cmds[j].OnStart {
|
||||
|
||||
// }
|
||||
}
|
||||
{
|
||||
lf := len(Functions)
|
||||
|
||||
+10
-4
@@ -90,9 +90,7 @@ func (sender *Strings) Dir(path string) string {
|
||||
func (sender *Strings) Contains(s string, substr interface{}) bool {
|
||||
switch substr := substr.(type) {
|
||||
case string:
|
||||
if strings.Contains(s, substr) {
|
||||
return true
|
||||
}
|
||||
return strings.Contains(s, substr)
|
||||
case []string:
|
||||
for _, sub := range substr {
|
||||
if strings.Contains(s, sub) {
|
||||
@@ -166,6 +164,10 @@ func (sender *Strings) Split(s string, sep string, n int) []string {
|
||||
return strings.SplitN(s, sep, n)
|
||||
}
|
||||
|
||||
func (sender *Strings) BuildQuery(params map[string]interface{}) string {
|
||||
return sender.EncodeQueryString(params)
|
||||
}
|
||||
|
||||
func (sender *Strings) EncodeQueryString(params map[string]interface{}) string {
|
||||
var buf bytes.Buffer
|
||||
for key, value := range params {
|
||||
@@ -192,6 +194,10 @@ func (sender *Strings) EncodeQueryString(params map[string]interface{}) string {
|
||||
return buf.String()
|
||||
}
|
||||
|
||||
func (sender *Strings) ParseQuery(querystring string) map[string]interface{} {
|
||||
return sender.DecodeQueryString(querystring)
|
||||
}
|
||||
|
||||
func (sender *Strings) DecodeQueryString(querystring string) map[string]interface{} {
|
||||
u, err := url.Parse(querystring)
|
||||
|
||||
@@ -245,7 +251,7 @@ func (sender *Strings) BuildCQCode(cqType string, params map[string]interface{})
|
||||
var sb strings.Builder
|
||||
sb.WriteString("[CQ:" + cqType)
|
||||
for k, v := range params {
|
||||
sb.WriteString(",")
|
||||
sb.WriteString(", ")
|
||||
sb.WriteString(k)
|
||||
sb.WriteString("=")
|
||||
sb.WriteString(fmt.Sprintf("%v", v))
|
||||
|
||||
+14
-10
@@ -199,9 +199,10 @@ func initPlugins() {
|
||||
if Functions[i].UUID == key {
|
||||
DestroyAdapterByUUID(key)
|
||||
Functions[i].Running = false
|
||||
if Functions[i].CronId != 0 {
|
||||
C.Remove(cron.EntryID(Functions[i].CronId))
|
||||
|
||||
if len(Functions[i].CronIds) != 0 {
|
||||
for _, id := range Functions[i].CronIds {
|
||||
C.Remove(cron.EntryID(id))
|
||||
}
|
||||
}
|
||||
Functions = append(Functions[:i], Functions[i+1:]...)
|
||||
CancelPluginCrons(key)
|
||||
@@ -244,7 +245,7 @@ func initPlugin(data string, uuid string) (*common.Function, error) {
|
||||
var imType *common.Filter
|
||||
var userId *common.Filter
|
||||
var groupId *common.Filter
|
||||
var cron string
|
||||
var cron = map[string]string{}
|
||||
var admin bool
|
||||
var disable bool
|
||||
var priority int
|
||||
@@ -365,9 +366,6 @@ func initPlugin(data string, uuid string) (*common.Function, error) {
|
||||
BlackMode: true,
|
||||
Items: item,
|
||||
}
|
||||
case "cron", "crontab":
|
||||
cron = strings.TrimSpace(res[2])
|
||||
cron = strings.ReplaceAll(cron, `\/`, "/")
|
||||
case "admin":
|
||||
admin = strings.TrimSpace(res[2]) == "true"
|
||||
case "disable":
|
||||
@@ -438,6 +436,12 @@ func initPlugin(data string, uuid string) (*common.Function, error) {
|
||||
time.Sleep(time.Second * 2)
|
||||
getPaterner(uuid, strings.TrimSpace(paterner))
|
||||
}()
|
||||
default:
|
||||
cron_ := strings.TrimSpace(res[2])
|
||||
cron_ = strings.ReplaceAll(cron_, `\/`, "/")
|
||||
if strings.HasPrefix(res[1], "cron") {
|
||||
cron[res[1]] = cron_
|
||||
}
|
||||
}
|
||||
}
|
||||
script := ""
|
||||
@@ -453,9 +457,9 @@ func initPlugin(data string, uuid string) (*common.Function, error) {
|
||||
if err == nil && err2 != nil {
|
||||
err = err2
|
||||
}
|
||||
if err == nil && len(rules) == 0 && cron != "" {
|
||||
err = fmt.Errorf("无效的脚本%s", title)
|
||||
}
|
||||
// if err == nil && len(rules) == 0 && cron != "" {
|
||||
// err = fmt.Errorf("无效的脚本%s", title)
|
||||
// }
|
||||
if web {
|
||||
onStart = true
|
||||
}
|
||||
|
||||
+23
-14
@@ -260,20 +260,29 @@ func (sender *SenderJsIplm) IsAdmin() bool {
|
||||
return sender.Message.IsAdmin()
|
||||
}
|
||||
|
||||
func (sender *SenderJsIplm) Reply(text string) *goja.Promise {
|
||||
promise, resolve, reject := sender.Vm.NewPromise()
|
||||
go func() {
|
||||
if text == "" {
|
||||
resolve("")
|
||||
return
|
||||
}
|
||||
i, err := sender.Message.Reply(text)
|
||||
if err != nil {
|
||||
reject(err.Error())
|
||||
}
|
||||
resolve(i)
|
||||
}()
|
||||
return promise
|
||||
func (sender *SenderJsIplm) Reply(text string) interface{} {
|
||||
// promise, resolve, reject := sender.Vm.NewPromise()
|
||||
// go func() {
|
||||
// defer func() {
|
||||
// recover()
|
||||
// }()
|
||||
// if text == "" {
|
||||
// resolve("")
|
||||
// return
|
||||
// }
|
||||
// i, err := sender.Message.Reply(text)
|
||||
// if err != nil {
|
||||
// reject(err.Error())
|
||||
// return
|
||||
// }
|
||||
// resolve(i)
|
||||
// }()
|
||||
// return promise
|
||||
i, err := sender.Message.Reply(text)
|
||||
if err != nil {
|
||||
panic(Error(sender.Vm, err))
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
func (sender *SenderJsIplm) HoldOn(str ...string) string {
|
||||
|
||||
Reference in New Issue
Block a user