如何在 Rivescript“.rive”脚本中执行 Python3 对象宏?

How to execute a Python3 object macro within Rivescript ".rive" script?

我在 RiveScript Interpreter 的 .rive 文件中有以下代码,当用户键入命令时,代码基本上会说 hello world "give me result":

> object base64 python
    import base64 as b64
    return b64.b64encode(" ".join(args))
< object
+ encode * in base64
- OK: <call>base64 <star></call>

现在,当 运行使用命令 python3 rivescript eg/brain 与解释器连接时,我得到了正确的预期结果。但是当我尝试使用以下代码 运行 它时:

from rivescript import RiveScript

bot = RiveScript()
bot.load_directory("./eg/brain")
bot.sort_replies()

while True:
    msg = raw_input('You> ')
    if msg == '/quit':
        quit()

    reply = bot.reply("localuser", msg)
    print 'Bot>', reply

因为它提到 here 默认情况下 Python 支持是开启的。

编辑:我忘记提及我遇到的错误如下:

[ERR: Object Not Found]

为什么会出现此错误?

简单:只需使用该对象宏的触发器回复机器人。

例如:要调用描述的对象宏,请在您的 .rive 文件中包含以下触发器和回复:

> object hello_world python
   print("give me result")
< object 

+ hello world
- <call>hello_world</call>