x
This commit is contained in:
@@ -3,7 +3,6 @@
|
|||||||
一个不太有用的机器人,不生产消息,只搬运消息。
|
一个不太有用的机器人,不生产消息,只搬运消息。
|
||||||
|
|
||||||
## 特性
|
## 特性
|
||||||
|
|
||||||
- 简单易用的消息搬运功能。
|
- 简单易用的消息搬运功能。
|
||||||
- 简单强大的自定义回复功能。
|
- 简单强大的自定义回复功能。
|
||||||
- 完整支持 ECMAScript 5.1 的插件系统,基于 [otto](https://github.com/robertkrimen/otto)。
|
- 完整支持 ECMAScript 5.1 的插件系统,基于 [otto](https://github.com/robertkrimen/otto)。
|
||||||
@@ -520,3 +519,7 @@ md5(string): string; //加密
|
|||||||
running(): boolean; //服务是否运行
|
running(): boolean; //服务是否运行
|
||||||
uuid(): string; //生成uuid
|
uuid(): string; //生成uuid
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 项目赞助
|
||||||
|
打开微信扫一扫,深入了解作者~
|
||||||
|

|
||||||
|
|||||||
+31
-21
@@ -497,30 +497,40 @@ func (sender *CustomSender) Reply(msgs ...interface{}) (string, error) {
|
|||||||
// "uuid": utils.GenUUID(),
|
// "uuid": utils.GenUUID(),
|
||||||
}
|
}
|
||||||
if sender.f.reply == nil {
|
if sender.f.reply == nil {
|
||||||
matched := false
|
var any *common.Function
|
||||||
|
var one *common.Function
|
||||||
for _, function := range Functions {
|
for _, function := range Functions {
|
||||||
if function.Reply != nil && function.Reply.Platform == platform && (len(function.Reply.BotsID) == 0 || Contains(function.Reply.BotsID, platform)) {
|
if function.Reply != nil && function.Reply.Platform == platform {
|
||||||
message_id := ""
|
if len(function.Reply.BotsID) == 0 {
|
||||||
function.Handle(&Faker{
|
any = function
|
||||||
Type: "*",
|
} else if Contains(function.Reply.BotsID, sender.f.botid) {
|
||||||
}, func(vm *goja.Runtime) {
|
one = function
|
||||||
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 !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{
|
c := MsgChan{
|
||||||
Msg: msg,
|
Msg: msg,
|
||||||
Chan: make(chan string),
|
Chan: make(chan string),
|
||||||
|
|||||||
@@ -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
|
||||||
|
}
|
||||||
@@ -81,6 +81,9 @@ func publicScript(str string) string {
|
|||||||
if su.GetValue("title") == "" {
|
if su.GetValue("title") == "" {
|
||||||
su.SetValue("title", "无名脚本")
|
su.SetValue("title", "无名脚本")
|
||||||
}
|
}
|
||||||
|
if su.GetValue("message") == "" {
|
||||||
|
su.DeleteValue("message")
|
||||||
|
}
|
||||||
create_at := su.GetValue("create_at")
|
create_at := su.GetValue("create_at")
|
||||||
if _, err := time.Parse("2006-01-02 15:04:05", create_at); create_at == "" || err != nil {
|
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"))
|
su.SetValue("create_at", time.Now().Format("2006-01-02 15:04:05"))
|
||||||
|
|||||||
@@ -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 {
|
vm.Set("getReplyMessage", func(plt string, bots_id []string) *goja.Promise {
|
||||||
return GetReplyMessage(vm, plt, bots_id)
|
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 {
|
func EncryptPlugin(script string) string {
|
||||||
|
|||||||
Reference in New Issue
Block a user