This commit is contained in:
cdle
2023-06-06 13:50:35 +08:00
parent 7bbf2e6ba1
commit 10f300626a
5 changed files with 62 additions and 22 deletions
+4 -1
View File
@@ -3,7 +3,6 @@
一个不太有用的机器人,不生产消息,只搬运消息。
## 特性
- 简单易用的消息搬运功能。
- 简单强大的自定义回复功能。
- 完整支持 ECMAScript 5.1 的插件系统,基于 [otto](https://github.com/robertkrimen/otto)。
@@ -520,3 +519,7 @@ md5(string): string; //加密
running(): boolean; //服务是否运行
uuid(): string; //生成uuid
```
### 项目赞助
打开微信扫一扫,深入了解作者~
![](https://raw.githubusercontent.com/cdle/sillyGirl/main/appreciate.jpg)
+31 -21
View File
@@ -497,30 +497,40 @@ func (sender *CustomSender) Reply(msgs ...interface{}) (string, error) {
// "uuid": utils.GenUUID(),
}
if sender.f.reply == nil {
matched := false
var any *common.Function
var one *common.Function
for _, function := range Functions {
if function.Reply != nil && function.Reply.Platform == platform && (len(function.Reply.BotsID) == 0 || Contains(function.Reply.BotsID, platform)) {
message_id := ""
function.Handle(&Faker{
Type: "*",
}, func(vm *goja.Runtime) {
obj := vm.NewObject()
for k, v := range msg {
obj.Set(k, v)
}
proxy := vm.NewProxy(obj, &goja.ProxyTrapConfig{
Set: func(target *goja.Object, property string, value, receiver goja.Value) (success bool) {
message_id = fmt.Sprint(value.Export())
return true
},
})
vm.Set("msg", proxy)
vm.Set("message", proxy)
})
return message_id, nil
if function.Reply != nil && function.Reply.Platform == platform {
if len(function.Reply.BotsID) == 0 {
any = function
} else if Contains(function.Reply.BotsID, sender.f.botid) {
one = function
}
}
}
if !matched {
if one == nil && any != nil {
one = any
}
if one != nil {
message_id := ""
one.Handle(&Faker{
Type: "*",
}, func(vm *goja.Runtime) {
obj := vm.NewObject()
for k, v := range msg {
obj.Set(k, v)
}
proxy := vm.NewProxy(obj, &goja.ProxyTrapConfig{
Set: func(target *goja.Object, property string, value, receiver goja.Value) (success bool) {
message_id = fmt.Sprint(value.Export())
return true
},
})
vm.Set("msg", proxy)
vm.Set("message", proxy)
})
return message_id, nil
} else {
c := MsgChan{
Msg: msg,
Chan: make(chan string),
+18
View File
@@ -0,0 +1,18 @@
package core
func Script(uuid string) map[string]interface{} {
su := &ScriptUtils{
script: plugins.GetString(uuid),
}
var o = map[string]interface{}{
"get": su.GetValue,
"save": func() {
plugins.Set(uuid, su.script)
},
}
o["set"] = func(key, value string) map[string]interface{} {
su.SetValue(key, value)
return o
}
return o
}
+3
View File
@@ -81,6 +81,9 @@ func publicScript(str string) string {
if su.GetValue("title") == "" {
su.SetValue("title", "无名脚本")
}
if su.GetValue("message") == "" {
su.DeleteValue("message")
}
create_at := su.GetValue("create_at")
if _, err := time.Parse("2006-01-02 15:04:05", create_at); create_at == "" || err != nil {
su.SetValue("create_at", time.Now().Format("2006-01-02 15:04:05"))
+6
View File
@@ -404,6 +404,12 @@ func SetPluginMethod(vm *goja.Runtime, uuid string, on_start bool) {
vm.Set("getReplyMessage", func(plt string, bots_id []string) *goja.Promise {
return GetReplyMessage(vm, plt, bots_id)
})
vm.Set("Script", func(str string) interface{} {
if str == "" {
str = uuid
}
return Script(str)
})
}
func EncryptPlugin(script string) string {