rivescript-python
rivescript-python copied to clipboard
Adding and getting dynamic triggers
Is it possible to getand add triggers dynamically ?
For example from a redis store.
To be able to add triggers without restarting the bot.
routes = {
"topic=domath": {
"math": {
"triggers": getTriggersFromRedis,
"args": "<star1> <star2>",
"handler": doMath
},
"wildcard": {
"triggers": ["*"],
"args": "<star>",
"handler": wildcardHandler
}
}
}
This way i can also let the bot add new triggers by itself, based on the wildcard message for a topic.
It will search for certain keywords like action verbs, question verbs etc... in the wildcard message, then determine where to create the new trigger.
You can use stream() to add new triggers whenever you want (make sure to call sortReplies() afterward so they're actually matchable).
The router example code exists entirely outside the rivescript library so you can make it do whatever you need for it to get stuff from Redis or whatever.
Oh, i did'nt know stream() could be used to "livestream" triggers without restarting the bot.
Not sure if sortReplies() would require a restart though. That will not be ideal in this situation.
I want the bot and rivescript code to be as dynamic as possible.
Meaning less hardcoded triggers.responses in the files.
Thanks though.
sortReplies() can be called multiple times without a restart. It deletes the sort buffers and remakes them from scratch each time.