Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have the following code within the .rive file for RiveScript Interpreter, the code basically will say hello world when the user type the command "give me result":

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

Now when running that with the interpreter with the command python3 rivescript eg/brain, I get the right expected results. But when I try to run it with the following code:

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

As it mentions here that Python support by default is on.

Edit: I forgott to mention the error I'm getting which is the following:

[ERR: Object Not Found]

Why I am getting this error?

like image 442
0x01Brain Avatar asked Mar 20 '26 02:03

0x01Brain


1 Answers

Simple: Just reply to the bot with the trigger to that object macro.

For example: To call the object macro described include the following trigger and reply in your .rive file:

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

+ hello world
- <call>hello_world</call>
like image 187
TheRobotCarlson Avatar answered Mar 21 '26 16:03

TheRobotCarlson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!