Compare commits

..

No commits in common. "master" and "chausie-20200521" have entirely different histories.

3 changed files with 12 additions and 15 deletions

View File

@ -27,15 +27,14 @@ class MessageQueueHandler:
def _dispatch_messages(self): def _dispatch_messages(self):
for message in iter(self._queue.get, None): for message in iter(self._queue.get, None):
is_queue_empty = self._queue.empty() message['typing'] = not self._queue.empty()
message['typing'] = not is_queue_empty
self.connector.send_message(message) self.connector.send_message(message)
self._sleep(self._get_sleep_time(message, is_queue_empty)) self._sleep(self._get_sleep_time(message))
def _get_sleep_time(self, message, is_queue_empty): def _get_sleep_time(self, message):
words_per_min = message['wpm'] if 'wpm' in message else self.wpm words_per_min = message['wpm'] if 'wpm' in message else self.wpm
chars_per_min = self.avg_word_len * words_per_min / 60 chars_per_min = self.avg_word_len * words_per_min / 60
return 0 if is_queue_empty else len(message['message']) / chars_per_min return len(message['message']) / chars_per_min
def _sleep(self, seconds): def _sleep(self, seconds):
poll_freq = self.drain_poll_freq poll_freq = self.drain_poll_freq

View File

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

View File

@ -79,7 +79,6 @@ class IdeHandler:
def read(self, message): def read(self, message):
if 'patterns' in message: if 'patterns' in message:
self.filemanager.patterns = message['patterns'] self.filemanager.patterns = message['patterns']
self.monitor.paths = self.filemanager.parents
try: try:
message['filename'] = self.filemanager.find_file( message['filename'] = self.filemanager.find_file(
message.get('filename') or self.initial_file message.get('filename') or self.initial_file