-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.py
45 lines (38 loc) · 1.39 KB
/
response.py
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
import re
"""
Response object
:param set_name: Name of the set to which the response belongs
:param match_str: String representation of regex for matching input
:param resp: String response displayed if matched
:param is_on: List of boolean states that must be true to match response
:param is_off: List of boolean states that must be false to match response
:param set_on: List of boolean states that will become true if matched
:param set_off: List of boolean states that will become false if matched
:param next: Optional response string to auto-trigger if this is matched
"""
class Response():
SET_CHANGE = re.compile(r'\ballegra_set_change_')
SET_EXIT = re.compile(r'exit')
@staticmethod
def get_set_change(msg):
return re.sub(Response.SET_CHANGE, '', msg)
def __init__(self, match_str, resp, is_on='', is_off='', set_on='', set_off='', next=''):
self.regex = re.compile(r'\b%s\b' % match_str, re.I)
self.resp = resp
if is_on:
self.is_on = is_on.split(',')
else:
self.is_on = []
if is_off:
self.is_off = is_off.split(',')
else:
self.is_off = []
if set_on:
self.set_on = set_on.split(',')
else:
self.set_on = []
if set_off:
self.set_off = set_off.split(',')
else:
self.set_off = []
self.next = next