This commit is contained in:
cdle
2023-06-30 13:58:31 +08:00
parent 9c09a5588b
commit 6f1f9f0dc9
5 changed files with 68 additions and 7 deletions
+7 -6
View File
@@ -32,12 +32,13 @@ type Function struct {
Encrypt bool `json:"encrypt"`
OnStart bool `json:"on_start"`
PluginPublisher
Running bool `json:"running"`
Https []*Http `json:"-"`
Reply *Reply `json:"-"`
Downloads int `json:"downloads"`
HasForm bool `json:"has_form"`
Carry bool `json:"carry"`
Running bool `json:"running"`
Https []*Http `json:"-"`
Reply *Reply `json:"-"`
Downloads int `json:"downloads"`
HasForm bool `json:"has_form"`
Carry bool `json:"carry"`
Messages interface{} `json:"messages"`
}
type Filter struct {
BlackMode bool
+3
View File
@@ -41,6 +41,7 @@ type SenderJsIplm struct {
}
type Console struct {
UUID string
}
var console = &Console{}
@@ -77,6 +78,7 @@ func (c *Console) Warn(v ...interface{}) {
}
log := utils.FormatLog(v[0], v[1:]...)
logs.Warn(log)
WritePluginMessage(c.UUID, "warn", log)
Broadcast2WebUser(log, "warn")
}
@@ -86,6 +88,7 @@ func (c *Console) Error(v ...interface{}) {
}
log := utils.FormatLog(v[0], v[1:]...)
logs.Error(log)
WritePluginMessage(c.UUID, "error", log)
Broadcast2WebUser(log, "error")
}
+56
View File
@@ -0,0 +1,56 @@
package core
import (
"encoding/json"
"time"
"github.com/cdle/sillyplus/utils"
)
type PMsg struct {
Class string `json:"class"`
Unix int `json:"unix"`
Content string `json:"content"`
}
var plugin_messages = MakeBucket("plugin_messages")
func WritePluginMessage(uuid string, class string, content string) {
if uuid == "" {
return
}
var data = plugin_messages.GetBytes(uuid)
pmsgs := []PMsg{}
json.Unmarshal(data, &pmsgs)
s := &Strings{}
ok := false
new := PMsg{
Class: class,
Unix: int(time.Now().Unix()),
Content: content,
}
for i := range pmsgs {
if pmsgs[i].Class != class {
continue
}
if content == "" {
continue
}
if s.Similarity(pmsgs[i].Content, content) > 0.9 {
pmsgs[i] = new
ok = true
break
}
}
if !ok {
pmsgs = append(pmsgs, new)
}
plugin_messages.Set(uuid, utils.JsonMarshal(pmsgs))
}
func GetPluginMessage(uuid string) []PMsg {
var data = plugin_messages.GetBytes(uuid)
pmsgs := []PMsg{}
json.Unmarshal(data, &pmsgs)
return pmsgs
}
+1
View File
@@ -210,6 +210,7 @@ func initWebPluginList() {
rr.Data[i].Running = false
for j := range fc {
if rr.Data[i].UUID == fc[j].UUID {
rr.Data[i].Messages = GetPluginMessage(rr.Data[i].UUID)
if rr.Data[i].Version != fc[j].Version {
rr.Data[i].Status = 1
} else {
+1 -1
View File
@@ -322,7 +322,7 @@ func SetPluginMethod(vm *goja.Runtime, uuid string, on_start bool, running func(
vm.Set("md5", utils.Md5)
vm.Set("image", utils.ToImageQrcode)
vm.Set("video", utils.ToVideoQrcode)
vm.Set("console", console)
vm.Set("console", &Console{UUID: uuid})
vm.Set("sillyplus", sillyplusJsIplm)
vm.Set("call", func(str string) interface{} {
return RegistFuncs[str]