Trees | Indices | Help |
|
---|
|
A RiveScript interpreter for Python 2 and 3.
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|
|||
|
|
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. bool utf8: Enable UTF-8 support. |
Return the version number of the RiveScript library. This may be called as either a class method of a method of a RiveScript object. |
Load RiveScript documents from a directory. Provide `ext` as a list of extensions to search for. The default list is `.rive`, `.rs` |
Stream in RiveScript source code dynamically. `code` should be an array of lines of RiveScript code. |
Syntax check a RiveScript command and line. Returns a syntax error string on error; None otherwise. |
Return the in-memory RiveScript document as a Python data structure. This would be useful for developing a user interface for editing RiveScript replies without having to edit the RiveScript code manually. |
Write the currently parsed RiveScript data into a file. Pass either a file name (string) or a file handle object. This uses `deparse()` to dump a representation of the loaded data and writes it to the destination file. If you provide your own data as the `deparsed` argument, it will use that data instead of calling `deparse()` itself. This way you can use `deparse()`, edit the data, and use that to write the RiveScript document (for example, to be used by a user interface for editing RiveScript without writing the code directly). |
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. |
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 a global variable. Equivalent to `! global` in RiveScript code. Set to None to delete. |
Set a bot variable. Equivalent to `! var` in RiveScript code. Set to None to delete. |
Set a substitution. Equivalent to `! sub` in RiveScript code. Set to None to delete. |
Set a person substitution. Equivalent to `! person` in RiveScript code. Set to None to delete. |
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 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. |
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 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`. |
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). |
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. |
Get information about a trigger. Pass in a raw trigger to find out what file name and line number it appeared at. This is useful for e.g. tracking down the location of the trigger last matched by the user via last_match(). Returns a list of matching triggers, containing their topics, filenames and line numbers. Returns None if there weren't any matches found. The keys in the trigger info is as follows: * category: Either 'topic' (for normal) or 'thats' (for %Previous triggers) * topic: The topic name * trigger: The raw trigger text * filename: The filename the trigger was found in. * lineno: The line number the trigger was found on. Pass in a true value for `dump`, and the entire syntax tracking tree is returned. |
Retrieve the user ID of the current user talking to your bot. This is mostly useful inside of a Python object macro to get the user ID of the person who caused the object macro to be invoked (i.e. to set a variable for that user from within the object). This will return None if used outside of the context of getting a reply (i.e. the value is unset at the end of the `reply()` method). |
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Tue Nov 25 18:56:01 2014 | http://epydoc.sourceforge.net |