Compare commits

..

No commits in common. "master" and "chausie-20200526" 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):
for message in iter(self._queue.get, None):
is_queue_empty = self._queue.empty()
message['typing'] = not is_queue_empty
message['typing'] = not self._queue.empty()
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
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):
poll_freq = self.drain_poll_freq

View File

@ -1,22 +1,17 @@
DEFAULT_ORIGINATOR = 'avataobot'
class MessageSender:
def __init__(self, uplink):
self.uplink = uplink
def send(self, message, originator=DEFAULT_ORIGINATOR, buttons=None):
def send(self, message, originator=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=DEFAULT_ORIGINATOR, buttons=None):
def queue_messages(self, messages, originator=None):
message_queue = {
'key': 'message.queue',
'messages': []
@ -26,6 +21,10 @@ 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
})

View File

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