-
Notifications
You must be signed in to change notification settings - Fork 209
Plugins and Functions
The ^respond(topic_name)
function is used in the reply it takes the current input and check it against the selected topic more matches. Once it gets to the end of the topic it will unwind its way back and continue checking in the normal path.
> topic random
+ * i *
- ^respond(i_topic)
+ * you *
- ^respond(you_topic)
< topic
> topic i_topic
+ i am not *
- No, you aren’t!
+ i am *1
- Yes, you are!
< topic
> topic you_topic
+ you are not *
- No, I am not!
+ you are *1
- Yes, I am!
< topic
When the user says I am not a robot! the system will match it with the * i *
rule and look first for a reply in gambits in the i_topic topic
###^topicRedirect(topic_name,trigger)
^topicRedirect(topic,trigger)
is used in the reply and is very similar to reply redirects except they redirect you to a reply in a specific topic.
> topic random
+ say something random
- ^topicRedirect(something_random,__say__)
< topic
> topic something_random
+ __say__
- Wind on the face is not good for you.
- I watched Mr. Dressup as a kid.
< topic
For this you just need to pass it into the bot options, when creating the new superscript bot object. Here is an example:
var superscript = require("superscript");
var options = {};
options['factSystem'] = factSystem;
options['mongoose'] = mongoose;
options['scope'] = {
'customFunction': function(a, b) { return a + b }
}
new superscript(options, function(err, bot) {
// bot stuff, request, reply
});
The keyname to use is 'scope' key, this will mixin to the plugins. Then from your custom plugin you have the function available. i.e..: this.customFunction()
This is useful, if you want some resource to be available in all the plugins and want to get it initialized at the start of the bot server. Another way to make some resource available in all the plugins is to declare and initialize it in one of the plugins and export it as a module, which can be require()
'ed by other plugins by referencing to that plugin file. But that will introduce dependencies among plugins, which will be hard to document and they loose their modularity. Here is the line that calls the plugin: https://github.com/silentrob/superscript/blob/master/lib/processtags.js#L51-L52