|
Methods defined here:
- __init__(self, debug=False, strict=True, depth=50, log='')
- Initialize a new RiveScript interpreter.
bool debug: Specify a debug mode.
bool strict: Strict mode (RS syntax errors are fatal)
str log: Specify a log file for debug output to go to (instead of STDOUT).
int depth: Specify the recursion depth limit.
- check_syntax(self, cmd, line)
- Syntax check a RiveScript command and line.
Returns a syntax error string on error; None otherwise.
- clear_uservars(self, user=None)
- Delete all variables about a user (or all users).
If no username is passed, deletes all variables about all users. Otherwise, only
deletes all variables for the given user.
- freeze_uservars(self, user)
- Freeze the variable state for a user.
This will clone and preserve a user's entire variable state, so that it can be
restored later with `thaw_uservars`.
- get_uservar(self, user, name)
- Get a variable about a user.
If the user has no data at all, returns None. If the user doesn't have a value
set for the variable you want, returns the string 'undefined'.
- get_uservars(self, user=None)
- Get all variables about a user (or all users).
If no username is passed, returns the entire user database structure. Otherwise,
only returns the variables for the given user, or None if none exist.
- last_match(self, user)
- Get the last trigger matched for the user.
This will return the raw trigger text that the user's last message matched. If
there was no match, this will return None.
- load_directory(self, directory, ext='.rs')
- Load RiveScript documents from a directory.
- load_file(self, filename)
- Load and parse a RiveScript document.
- reply(self, user, msg)
- Fetch a reply from the RiveScript brain.
- set_global(self, name, value)
- Set a global variable.
Equivalent to `! global` in RiveScript code. Set to None to delete.
- set_handler(self, language, obj)
- Define a custom language handler for RiveScript objects.
language: The lowercased name of the programming language,
e.g. python, javascript, perl
obj: An instance of a class object that provides the following interface:
class MyObjectHandler:
def __init__(self):
pass
def load(self, name, code):
# name = the name of the object from the RiveScript code
# code = the source code of the object
def call(self, rs, name, fields):
# rs = the current RiveScript interpreter object
# name = the name of the object being called
# fields = array of arguments passed to the object
return reply
Pass in a None value for the object to delete an existing handler (for example,
to prevent Python code from being able to be run by default).
Look in the `eg` folder of the rivescript-python distribution for an example
script that sets up a JavaScript language handler.
- set_person(self, what, rep)
- Set a person substitution.
Equivalent to `! person` in RiveScript code. Set to None to delete.
- set_subroutine(self, name, code)
- Define a Python object from your program.
This is equivalent to having an object defined in the RiveScript code, except
your Python code is defining it instead. `name` is the name of the object, and
`code` is a Python function (a `def`) that accepts rs,args as its parameters.
This method is only available if there is a Python handler set up (which there
is by default, unless you've called set_handler("python", None)).
- set_substitution(self, what, rep)
- Set a substitution.
Equivalent to `! sub` in RiveScript code. Set to None to delete.
- set_uservar(self, user, name, value)
- Set a variable for a user.
- set_variable(self, name, value)
- Set a bot variable.
Equivalent to `! var` in RiveScript code. Set to None to delete.
- sort_replies(self, thats=False)
- Sort the loaded triggers.
- stream(self, code)
- Stream in RiveScript source code dynamically.
`code` should be an array of lines of RiveScript code.
- thaw_uservars(self, user, action='thaw')
- Thaw a user's frozen variables.
The `action` can be one of the following options:
discard: Don't restore the user's variables, just delete the frozen copy.
keep: Keep the frozen copy after restoring the variables.
thaw: Restore the variables, then delete the frozen copy (default).
|