From 30d176f6bbd6a4a5c8dc28c5c2afc73ac60c03c4 Mon Sep 17 00:00:00 2001
From: Noah Petherbridge CoffeeScript Language Support for RiveScript Macros. This language is not
enabled by default; to enable CoffeeScript object macros: Called by the RiveScript object to load CoffeeScript code. JavaScript Language Support for RiveScript Macros. This support is enabled by
default in RiveScript.js; if you don't want it, override the Called by the RiveScript object to load JavaScript code. Read and parse a RiveScript document. Returns a data structure that
represents all of the useful contents of the document, in this format: onError function receives: Create a new RiveScript interpreter. In UTF-8 mode, most characters in a user's message are left intact, except for
certain metacharacters like backslashes and common punctuation characters like
@@ -45,10 +52,9 @@ If you want to override the punctuation regexp, you can provide a new one by
assigning the This option to the constructor will make RiveScript lowercase all the triggers
@@ -93,10 +99,9 @@ Note: the recommended way to handle this case is to provide a trigger of
simply Note: the recommended way to handle this case is to provide at least one
normal reply (with the These custom error messages can be provided during the construction of the
RiveScript object, or set afterwards on the object's Examples: Returns the version number of the RiveScript.js library. By default, JavaScript object macros are enabled. If you want to disable
these (e.g. for security purposes when loading untrusted third-party code),
just set the JavaScript handler to null: Define a JavaScript object macro from your program.CoffeeObjectHandler (RiveScript master)
CoffeeObjectHandler = require "rivescript/lang/coffee"
-bot.setHandler "coffee", new CoffeeObjectHandler
-
CoffeeObjectHandler = require "rivescript/lang/coffee"
+bot.setHandler "coffee", new CoffeeObjectHandler
+
void load (string name, string[] code)
JSObjectHandler (RiveScript master)
javascript
language handler to null, like so:bot.setHandler("javascript", null);
-
bot.setHandler("javascript", null);
+
void load (string name, string[]|function code)
Parser (RiveScript master)
object parse (string filename, string code[, func onError])
{
- "begin": { // "begin" data
- "global": {}, // ! global vars
- "var": {}, // ! bot vars
- "sub": {}, // ! sub substitutions
- "person": {}, // ! person substitutions
- "array": {}, // ! array lists
- },
- "topics": { // main reply data
- "random": { // (topic name)
- "includes": {}, // included topics
- "inherits": {}, // inherited topics
- "triggers": [ // array of triggers
- {
- "trigger": "hello bot",
- "reply": [], // array of replies
- "condition": [], // array of conditions
- "redirect": "", // @ redirect command
- "previous": null, // % previous command
- },
- ...
- ]
- }
- },
- "objects": [ // parsed object macros
- {
- "name": "", // object name
- "language": "", // programming language
- "code": [], // object source code (in lines)
- }
- ]
-}
-
{
+ "begin": { // "begin" data
+ "global": {}, // ! global vars
+ "var": {}, // ! bot vars
+ "sub": {}, // ! sub substitutions
+ "person": {}, // ! person substitutions
+ "array": {}, // ! array lists
+ },
+ "topics": { // main reply data
+ "random": { // (topic name)
+ "includes": {}, // included topics
+ "inherits": {}, // inherited topics
+ "triggers": [ // array of triggers
+ {
+ "trigger": "hello bot",
+ "reply": [], // array of replies
+ "condition": [], // array of conditions
+ "redirect": "", // @ redirect command
+ "previous": null, // % previous command
+ },
+ ...
+ ]
+ }
+ },
+ "objects": [ // parsed object macros
+ {
+ "name": "", // object name
+ "language": "", // programming language
+ "code": [], // object source code (in lines)
+ }
+ ]
+}
+
(err string[, filename str, line_no int])
string stringify (data deparsed)
diff --git a/docs/html/rivescript.html b/docs/html/rivescript.html
index 07e7611..0386c8d 100644
--- a/docs/html/rivescript.html
+++ b/docs/html/rivescript.html
@@ -19,25 +19,32 @@ Notice to Developers
RiveScript (hash options)
options
is an object with the
following keys:* bool debug: Debug mode (default false)
-* int depth: Recursion depth limit (default 50)
-* bool strict: Strict mode (default true)
-* bool utf8: Enable UTF-8 mode (default false, see below)
-* bool forceCase: Force-lowercase triggers (default false, see below)
-* func onDebug: Set a custom handler to catch debug log messages (default null)
-* obj errors: Customize certain error messages (see below)
-* str concat: Globally replace the default concatenation mode when parsing
- RiveScript source files (default `null`. be careful when
- setting this option if using somebody else's RiveScript
- personality; see below)
-* sessionManager: provide a custom session manager to store user variables.
+
+
null
. be careful when
+ setting this option if using somebody else's RiveScript
+ personality; see below)UTF-8 Mode
UTF-8 Mode
unicodePunctuation
attribute of the bot object after
initialization. Example:var bot = new RiveScript({utf8: true});
-bot.unicodePunctuation = new RegExp(/[.,!?;:]/g);
-
var bot = new RiveScript({utf8: true});
+bot.unicodePunctuation = new RegExp(/[.,!?;:]/g);
+
Force Case
Custom Error Messages
*
, which serves as the catch-all trigger and is the default one
that will match if nothing else matches the user's message. Example:+ *
-- I don't know what to say to that!
-
+ *
+- I don't know what to say to that!
+
replyNotFound
: This message is returned when the user did in fact match
@@ -108,11 +113,10 @@ Custom Error Messages
-
command) to every trigger to cover the cases
where none of the conditions are true. Example:+ hello
+
+ hello
* <get name> != undefined => Hello there, <get name>.
- Hi there.
-
objectNotFound
: This message is inserted into the bot's reply in-line when
@@ -128,15 +132,14 @@ Custom Error Messages
errors
property.var bot = new RiveScript({
-errors: {
-replyNotFound: "I don't know how to reply to that."
-}
-});
-
-bot.errors.objectNotFound = "Something went terribly wrong.";
-
var bot = new RiveScript({
+errors: {
+replyNotFound: "I don't know how to reply to that."
+}
+});
+bot.errors.objectNotFound = "Something went terribly wrong.";
+
string version ()
void setHandler(string lang, object)
var bot = new RiveScript();
-bot.setHandler("javascript", null);
-
var bot = new RiveScript();
+bot.setHandler("javascript", null);
+
void setSubroutine(string name, function)
async freezeUservars (string user)
thawUservars()
Thaw a user's frozen variables. The action can be one of the following: - discard: Don't restore the variables, just delete the frozen copy. - keep: Keep the frozen copy after restoring +* discard: Don't restore the variables, just delete the frozen copy. +* keep: Keep the frozen copy after restoring * thaw: Restore the variables and delete the frozen copy (default)
Retrieve the trigger that the user matched most recently.
@@ -314,42 +316,39 @@eg/scope
directory in
the source distribution of RiveScript-JS.
Example:
-// Normal usage as a promise -bot.reply(username, message, this).then(function(reply) { - console.log("Bot>", reply); -}); - -// Async-Await usage in an async function. -async function getReply(username, message) { - var reply = await bot.reply(username, message); - console.log("Bot>", reply); -} -
// Normal usage as a promise
+bot.reply(username, message, this).then(function(reply) {
+ console.log("Bot>", reply);
+});
+// Async-Await usage in an async function.
+async function getReply(username, message) {
+ var reply = await bot.reply(username, message);
+ console.log("Bot>", reply);
+}
+
Obsolete as of v2.0.0 -- use reply()
instead in new code.
Asyncronous version of reply. Use replyAsync if at least one of the subroutines
used with the <call>
tag returns a promise.
Example: using promises
-rs.replyAsync(user, message).then(function(reply) { - console.log("Bot>", reply); -}).catch(function(error) { - console.error("Error: ", error); -}); -
rs.replyAsync(user, message).then(function(reply) {
+ console.log("Bot>", reply);
+}).catch(function(error) {
+ console.error("Error: ", error);
+});
+
Example: using the callback
-rs.replyAsync(username, msg, this, function(error, reply) { - if (!error) { - console.log("Bot>", reply); - } else { - console.error("Error: ", error); - } -}); -
rs.replyAsync(username, msg, this, function(error, reply) {
+ if (!error) {
+ console.log("Bot>", reply);
+ } else {
+ console.error("Error: ", error);
+ }
+});
+
DEPRECATED
@@ -359,20 +358,19 @@This enables you to create a JavaScript object macro that returns a promise for asynchronous tasks (e.g. polling a web API or database). Example:
-rs.setSubroutine("asyncHelper", function (rs, args) { - return new rs.Promise(function (resolve, reject) { - resolve(42); - }); -}); -
rs.setSubroutine("asyncHelper", function (rs, args) {
+ return new rs.Promise(function (resolve, reject) {
+ resolve(42);
+ });
+});
+
If you're using promises in your object macros, you need to get a reply from
the bot using the replyAsync()
method instead of reply()
, for example:
rs.replyAsync(username, message, this).then(function(reply) { - console.log("Bot> ", reply); -}); -
rs.replyAsync(username, message, this).then(function(reply) {
+ console.log("Bot> ", reply);
+});
+