This commit is contained in:
@@ -2,10 +2,12 @@ package model
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/dop251/goja"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -157,6 +159,26 @@ func bindBossScriptFunctions(vm *goja.Runtime, hookAction any) {
|
||||
ctx.SwitchPetFn(uint32(catchTime))
|
||||
return goja.Undefined()
|
||||
})
|
||||
|
||||
_ = vm.Set("debug", func(call goja.FunctionCall) goja.Value {
|
||||
if len(call.Arguments) == 0 {
|
||||
g.Log().Debugf(ctx, "[boss-script] debug() called with no arguments")
|
||||
return goja.Undefined()
|
||||
}
|
||||
|
||||
parts := make([]string, 0, len(call.Arguments))
|
||||
for _, arg := range call.Arguments {
|
||||
exported := arg.Export()
|
||||
if bytes, err := json.Marshal(exported); err == nil {
|
||||
parts = append(parts, string(bytes))
|
||||
continue
|
||||
}
|
||||
parts = append(parts, arg.String())
|
||||
}
|
||||
|
||||
g.Log().Debugf(ctx, "[boss-script] %s", strings.Join(parts, " "))
|
||||
return goja.Undefined()
|
||||
})
|
||||
}
|
||||
|
||||
func defaultHookActionResult(hookAction any) bool {
|
||||
|
||||
Reference in New Issue
Block a user