Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to update trigger an reply dynamic? #399

Open
cage1618 opened this issue Nov 25, 2022 · 4 comments
Open

How to update trigger an reply dynamic? #399

cage1618 opened this issue Nov 25, 2022 · 4 comments

Comments

@cage1618
Copy link

rivescript is greate!

ATT, I found the stream method, but it seems only append new trigger. I want to update a trigger an reply when the bot is running but not stop it. Thanks

@kirsle
Copy link
Member

kirsle commented Nov 26, 2022

This is currently not supported easily but I'd be open for a pull request that would fix this.

A long time ago it used to be possible - RiveScript loaded triggers in as a hashmap keyed by the trigger text, so seeing a 'duplicate' trigger would update/merge the data and reloading a bot's replies was possible without needing to fully re-initialize a RiveScript instance from scratch. But this caused some issues with the way %Previous was handled; having two 'identical' triggers that had a different %Previous on each, they'd end up overwriting each other by the trigger text and causing problems; so the module was refactored to load triggers into an array rather than a hash map.

The plus side was, 'identical' triggers having different %Previous commands worked since they wouldn't overwrite each other; but attempting to 'reload' triggers just appended the duplicates further down the array where they were overshadowed by the first version that was loaded the first time.

A fix for this may look like (probably added to the sortReplies() function): to de-duplicate or merge triggers having the same +Trigger and %Previous value.

@cage1618
Copy link
Author

Thanks for your reply, so currently the best practices is stop the bot and then reload it, am i right?

@kirsle
Copy link
Member

kirsle commented Nov 27, 2022

Yeah - specifically, null out your old RiveScript object and replace it w/ a new RiveScript(); where you set up your bot anew.

This may reset user variables in memory though (if you're using the default settings); to make sure recent user variables cross over you can use getUservars()/setUservars().

// get the variables out of your current bot
let vars = await old_bot.getUservars();

let new_bot = new RiveScript();
await new_bot.loadDirectory("replies").then(new_bot.sortReplies);

// set them in the new bot
await new_bot.setUservars(vars);

// use the new bot (replace w/e you store RiveScript in
// with the new variable; the old bot will be garbage collected
// and future replies in your app call the new one now
old_bot = new_bot;

@cage1618
Copy link
Author

Ok, In this case, I have 2 questions:

  1. How about the input and reply tag reference? I thinks it will be lost in the new bot, am I right?
  2. How to release resources of the old bot?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants