This commit is contained in:
cdle
2021-10-11 20:06:50 +08:00
parent cdce7002ab
commit 0594da99b4
4 changed files with 46 additions and 28 deletions
+30
View File
@@ -165,6 +165,36 @@ func init123() {
v, _ := otto.ToValue(s.GetUsername())
return v
})
vm.Set("Await", func(call otto.Value) interface{} {
patternV, _ := call.Object().Get("pattern")
timeoutV, _ := call.Object().Get("timeout")
timeout, _ := timeoutV.ToInteger()
pattern, _ := patternV.ToString()
s.Await(s, func(s1 string, s2 Sender, e error) interface{} {
if e != nil {
return nil
}
v, err := call.Object().Call("callback", s1)
if err != nil {
return nil
}
deleteV, _ := v.Object().Get("delete")
delete, _ := deleteV.ToBoolean()
if delete {
s2.Delete()
}
disappearV, _ := call.Object().Get("disappear")
disappear, _ := disappearV.ToInteger()
s2.Disappear(time.Millisecond * time.Duration(disappear))
replyV, _ := v.Object().Get("reply")
reply, _ := replyV.ToString()
if reply != "" {
return reply
}
return nil
}, pattern, time.Millisecond*time.Duration(timeout))
return otto.Value{}
})
vm.Set("GetUserID", func() otto.Value {
v, _ := otto.ToValue(s.GetUserID())
return v