forked from aichaos/rivescript-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrivescript.RiveScript.html
More file actions
123 lines (101 loc) · 10.6 KB
/
Copy pathrivescript.RiveScript.html
File metadata and controls
123 lines (101 loc) · 10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Python: class RiveScript</title>
</head><body bgcolor="#f0f0f8">
<p>
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
<tr bgcolor="#ffc8d8">
<td colspan=3 valign=bottom> <br>
<font color="#000000" face="helvetica, arial"><strong>rivescript.RiveScript</strong> = <a name="rivescript.RiveScript">class RiveScript</a></font></td></tr>
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
<td colspan=2><tt>A RiveScript interpreter for Python 2.<br> </tt></td></tr>
<tr><td> </td>
<td width="100%">Methods defined here:<br>
<dl><dt><a name="RiveScript-__init__"><strong>__init__</strong></a>(self, debug<font color="#909090">=False</font>, strict<font color="#909090">=True</font>, depth<font color="#909090">=50</font>, log<font color="#909090">=''</font>)</dt><dd><tt>Initialize a new RiveScript interpreter.<br>
<br>
bool debug: Specify a debug mode.<br>
bool strict: Strict mode (RS syntax errors are fatal)<br>
str log: Specify a log file for debug output to go to (instead of STDOUT).<br>
int depth: Specify the recursion depth limit.</tt></dd></dl>
<dl><dt><a name="RiveScript-check_syntax"><strong>check_syntax</strong></a>(self, cmd, line)</dt><dd><tt>Syntax check a RiveScript command and line.<br>
<br>
Returns a syntax error string on error; None otherwise.</tt></dd></dl>
<dl><dt><a name="RiveScript-clear_uservars"><strong>clear_uservars</strong></a>(self, user<font color="#909090">=None</font>)</dt><dd><tt>Delete all variables about a user (or all users).<br>
<br>
If no username is passed, deletes all variables about all users. Otherwise, only<br>
deletes all variables for the given user.</tt></dd></dl>
<dl><dt><a name="RiveScript-freeze_uservars"><strong>freeze_uservars</strong></a>(self, user)</dt><dd><tt>Freeze the variable state for a user.<br>
<br>
This will clone and preserve a user's entire variable state, so that it can be<br>
restored later with `thaw_uservars`.</tt></dd></dl>
<dl><dt><a name="RiveScript-get_uservar"><strong>get_uservar</strong></a>(self, user, name)</dt><dd><tt>Get a variable about a user.<br>
<br>
If the user has no data at all, returns None. If the user doesn't have a value<br>
set for the variable you want, returns the string 'undefined'.</tt></dd></dl>
<dl><dt><a name="RiveScript-get_uservars"><strong>get_uservars</strong></a>(self, user<font color="#909090">=None</font>)</dt><dd><tt>Get all variables about a user (or all users).<br>
<br>
If no username is passed, returns the entire user database structure. Otherwise,<br>
only returns the variables for the given user, or None if none exist.</tt></dd></dl>
<dl><dt><a name="RiveScript-last_match"><strong>last_match</strong></a>(self, user)</dt><dd><tt>Get the last trigger matched for the user.<br>
<br>
This will return the raw trigger text that the user's last message matched. If<br>
there was no match, this will return None.</tt></dd></dl>
<dl><dt><a name="RiveScript-load_directory"><strong>load_directory</strong></a>(self, directory, ext<font color="#909090">='.rs'</font>)</dt><dd><tt>Load RiveScript documents from a directory.</tt></dd></dl>
<dl><dt><a name="RiveScript-load_file"><strong>load_file</strong></a>(self, filename)</dt><dd><tt>Load and parse a RiveScript document.</tt></dd></dl>
<dl><dt><a name="RiveScript-reply"><strong>reply</strong></a>(self, user, msg)</dt><dd><tt>Fetch a reply from the RiveScript brain.</tt></dd></dl>
<dl><dt><a name="RiveScript-set_global"><strong>set_global</strong></a>(self, name, value)</dt><dd><tt>Set a global variable.<br>
<br>
Equivalent to `! global` in RiveScript code. Set to None to delete.</tt></dd></dl>
<dl><dt><a name="RiveScript-set_handler"><strong>set_handler</strong></a>(self, language, obj)</dt><dd><tt>Define a custom language handler for RiveScript objects.<br>
<br>
language: The lowercased name of the programming language,<br>
e.g. python, javascript, perl<br>
obj: An instance of a class object that provides the following interface:<br>
<br>
class MyObjectHandler:<br>
def <a href="#rivescript.RiveScript-__init__">__init__</a>(self):<br>
pass<br>
def load(self, name, code):<br>
# name = the name of the object from the RiveScript code<br>
# code = the source code of the object<br>
def call(self, rs, name, fields):<br>
# rs = the current RiveScript interpreter object<br>
# name = the name of the object being called<br>
# fields = array of arguments passed to the object<br>
return reply<br>
<br>
Pass in a None value for the object to delete an existing handler (for example,<br>
to prevent Python code from being able to be run by default).<br>
<br>
Look in the `eg` folder of the rivescript-python distribution for an example<br>
script that sets up a JavaScript language handler.</tt></dd></dl>
<dl><dt><a name="RiveScript-set_person"><strong>set_person</strong></a>(self, what, rep)</dt><dd><tt>Set a person substitution.<br>
<br>
Equivalent to `! person` in RiveScript code. Set to None to delete.</tt></dd></dl>
<dl><dt><a name="RiveScript-set_subroutine"><strong>set_subroutine</strong></a>(self, name, code)</dt><dd><tt>Define a Python object from your program.<br>
<br>
This is equivalent to having an object defined in the RiveScript code, except<br>
your Python code is defining it instead. `name` is the name of the object, and<br>
`code` is a Python function (a `def`) that accepts rs,args as its parameters.<br>
<br>
This method is only available if there is a Python handler set up (which there<br>
is by default, unless you've called <a href="#rivescript.RiveScript-set_handler">set_handler</a>("python", None)).</tt></dd></dl>
<dl><dt><a name="RiveScript-set_substitution"><strong>set_substitution</strong></a>(self, what, rep)</dt><dd><tt>Set a substitution.<br>
<br>
Equivalent to `! sub` in RiveScript code. Set to None to delete.</tt></dd></dl>
<dl><dt><a name="RiveScript-set_uservar"><strong>set_uservar</strong></a>(self, user, name, value)</dt><dd><tt>Set a variable for a user.</tt></dd></dl>
<dl><dt><a name="RiveScript-set_variable"><strong>set_variable</strong></a>(self, name, value)</dt><dd><tt>Set a bot variable.<br>
<br>
Equivalent to `! var` in RiveScript code. Set to None to delete.</tt></dd></dl>
<dl><dt><a name="RiveScript-sort_replies"><strong>sort_replies</strong></a>(self, thats<font color="#909090">=False</font>)</dt><dd><tt>Sort the loaded triggers.</tt></dd></dl>
<dl><dt><a name="RiveScript-stream"><strong>stream</strong></a>(self, code)</dt><dd><tt>Stream in RiveScript source code dynamically.<br>
<br>
`code` should be an array of lines of RiveScript code.</tt></dd></dl>
<dl><dt><a name="RiveScript-thaw_uservars"><strong>thaw_uservars</strong></a>(self, user, action<font color="#909090">='thaw'</font>)</dt><dd><tt>Thaw a user's frozen variables.<br>
<br>
The `action` can be one of the following options:<br>
<br>
discard: Don't restore the user's variables, just delete the frozen copy.<br>
keep: Keep the frozen copy after restoring the variables.<br>
thaw: Restore the variables, then delete the frozen copy (default).</tt></dd></dl>
</td></tr></table>
</body></html>