-
Notifications
You must be signed in to change notification settings - Fork 0
/
event_messages.py
36 lines (28 loc) · 998 Bytes
/
event_messages.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
from enum import Enum
class EventType(Enum):
USER_MESSAGE = 1
API_CALL = 2
API_RESULT = 3
SYSTEM_MESSAGE = 4
VOICE_EVENT_LISTENING = 5
VOICE_EVENT_FINISHED = 6
class EventMessages:
def __init__(self) -> None:
self.event_list = []
self.event_callbacks = []
def add_callback(self, callback_function):
self.event_callbacks.append(callback_function)
def message(self, event_type:EventType, event_message:str):
self.event_list.append((event_type, event_message))
for fn in self.event_callbacks:
fn((event_type, event_message))
def pop_all_events(self):
# n is current list size
n = len(self.event_list)
# get first n elements
pop = self.event_list[:n]
# remove first n elements and leave the rest (in case new elements where added)
self.event_list = self.event_list[n:]
# return removed elements
return pop
event_log = EventMessages()