aichaos / rivescript-perl

A RiveScript interpreter for Perl. RiveScript is a scripting language for chatterbots.
https://www.rivescript.com
MIT License
8 stars 4 forks source link

Nesting random tag inside random tag #10

Open ghost opened 7 years ago

ghost commented 7 years ago

Hi. If I try to insert random tag inside random tag: + <bot name> * <get it> == undefined => {random} ^ {random}Yes?|Yea?{/random}| ^ Yea?{/random} - What's up? I'm getting this output: Yea?|Yea?{/random} I'm using default response in begin block: * <bot mood> == happy => {ok} If I use that code in begin block: * <bot mood> == happy => {random} ^ {ok}|{ok}|{ok}|{ok}|{ok}|{ok}|{ok}|{ok}|{ok}|{ok}|{ok}|{ok}|{ok}|{ok}| ^ {ok} :)|{ok} :)| ^ {ok} ;)|{ok} ;)| ^ {ok} :P| ^ {ok} ;P{/random} The response is even more strange: Yea?|Yea?|Yea?{/random}|Yea?|Yea?{/random}|Yea?|Yea?{/random}|Yea?|Yea?{/random}|Yea?|Yea?{/random}|Yea?|Yea?{/random}|Yea?|Yea?{/random}|Yea?|Yea?{/random}|Yea?|Yea?{/random}|Yea?|Yea?{/random}|Yea?|Yea?{/random}|Yea?|Yea?{/random}|Yea?|Yea?{/random}|Yea?|Yea?{/random} :)|Yea?|Yea?{/random} :)|Yea?|Yea?{/random} ;)|Yea?|Yea?{/random} ;)|Yea?|Yea?{/random} :P|Yea?|Yea?{/random} ;P{/random}

kirsle commented 7 years ago

Yeah this isn't supported.

The random tags are found by a regexp like {random}(.+?){/random}, so if you had embedded random tags, the closing tag of the inner random would match with the opening tag of the outer random.

{random}{random}Yes?|Yea?{/random}|Yea?{/random}

The first iteration of the regexp would match {random}{random}Yes?|Yea?{/random} with the inner text being {random}Yes?|Yea? which it would then pick a random result from (one of which contains another random tag which might go on to confuse the bot even further).