-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevents.py
More file actions
86 lines (73 loc) · 2.7 KB
/
events.py
File metadata and controls
86 lines (73 loc) · 2.7 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
from enum import Enum, auto
import logging
class EventTypes(Enum):
"""Event types."""
MACHINE_STARTUP = auto()
MACHINE_SLEEP = auto()
MACHINE_SHUTDOWN = auto()
MACHINE_ERROR = auto()
MACHINE_IDLE = auto()
DIRECT_SPEECH = auto()
SAY_TIME = auto()
SAY_RANDOM = auto()
SAY_PRAISE_VAULT_TEC = auto()
MACHINE_BORED = auto()
MACHINE_ATTENTION_SEEKING = auto()
INPUT_PIR_DETECTED = auto()
SAY_HOME_LAB_SMALLTALK = auto()
def __str__(self):
"""Return a string representation of the event type, usefull for prompting."""
if self == EventTypes.MACHINE_STARTUP:
return "The machine starts up."
elif self == EventTypes.MACHINE_SLEEP:
return "The machine sleeps."
elif self == EventTypes.MACHINE_IDLE:
return "The machine is idle."
elif self == EventTypes.MACHINE_BORED:
return "The machine is bored."
elif self == EventTypes.MACHINE_ATTENTION_SEEKING:
return "The machine is seeking attention."
elif self == EventTypes.INPUT_PIR_DETECTED:
return "The machine detects motion."
elif self == EventTypes.DIRECT_SPEECH:
return "The machine speaks."
elif self == EventTypes.SAY_TIME:
return "The machine says the current time."
elif self == EventTypes.SAY_RANDOM:
return "The machine says a random memory."
elif self == EventTypes.SAY_PRAISE_VAULT_TEC:
return "The machine praises Vault-Tec."
elif self == EventTypes.SAY_HOME_LAB_SMALLTALK:
return "The machine says a short commentary on the home lab and Tomáš."
else:
return "Unknown."
class Event:
def __init__(self, event_type, data=None):
self.type = event_type
self.data = data
class EventQueue:
def __init__(self):
self.events = []
def add_event(self, event):
logging.debug(f"EQ - Adding: {event.type} - Data: {event.data}.")
self.events.append(event)
def get_events(self):
return self.events
def get_event_to_handle(self):
if len(self.events) > 0:
logging.debug(
f"EQ - Handling: {self.events[0].type.name} - Data: {self.events[0].data}.")
return self.events.pop(0)
return None
def empty(self):
return len(self.events) == 0
def has_event_of_type(self, event_type):
for event in self.events:
if event.type == event_type:
return True
return False
def get_event_of_type(self, event_type):
for event in self.events:
if event.type == event_type:
return event
return None