aichaos / rivescript-js

A RiveScript interpreter for JavaScript. RiveScript is a scripting language for chatterbots.
https://www.rivescript.com/
MIT License
377 stars 144 forks source link

How to receive <star> in object macros similar in perl? #265

Closed ghabxph closed 6 years ago

ghabxph commented 6 years ago

How would I achieve this similar scenario below in javascript version of this rivescript?

> object hash javascript test
    return require('crypto').createHash('sha1').update(args).digest('hex');
< object

+ what is the md5 hash of *
- The hash of "<star>" is: <call>hash <star></call>

Args is the argument entered. This code is broken of course. Is this kind of scenario possible? If it is, how is it done?

kirsle commented 6 years ago

args is the right name, but it's an array type, so you'd want args[0] in your example.

The args array follows "shell quoting" style -- generally, all of the space-separated words from the <call> tag go into individual array elements, but quoted strings are treated like single words.

So if you want the entire <star> to come in as one argument even if the user typed spaces, put quotes around it. Longer example:

+ what is the md5 hash of *
- The hash of "<star>" is: <call>hash md5 "<star>"</call>

If the user said "what is the md5 hash of hello world"

ghabxph commented 6 years ago

Ah I see. It is working now. Thanks for your help :)

We can now close this issue.