Refactor MessageSender

This commit is contained in:
R. Richard 2020-06-24 13:44:07 +02:00
parent e5d0e91e93
commit dc5e26843a

View File

@ -1,17 +1,22 @@
DEFAULT_ORIGINATOR = 'avataobot'
class MessageSender:
def __init__(self, uplink):
self.uplink = uplink
def send(self, message, originator=None):
def send(self, message, originator=DEFAULT_ORIGINATOR, buttons=None):
message = {
'key': 'message.send',
'message': message
}
if originator:
message['originator'] = originator
if buttons:
message['buttons'] = buttons
self.uplink.send_message(message)
def queue_messages(self, messages, originator=None):
def queue_messages(self, messages, originator=DEFAULT_ORIGINATOR, buttons=None):
message_queue = {
'key': 'message.queue',
'messages': []
@ -21,10 +26,6 @@ class MessageSender:
if originator:
next_message['originator'] = originator
message_queue['messages'].append(next_message)
if buttons and message_queue['messages']:
message_queue['messages'][-1]['buttons'] = buttons
self.uplink.send_message(message_queue)
def set_originator(self, originator):
self.uplink.send_message({
'key': 'message.config',
'originator': originator
})