Fix issues in PR #67

This commit is contained in:
R. Richard 2019-08-26 13:51:28 +02:00 committed by therealkrispet
parent 7a14928432
commit af3781adb3

View File

@ -11,7 +11,7 @@ class MessageQueueHandler:
self._wpm, self._cps = None, None self._wpm, self._cps = None, None
self.wpm = wpm self.wpm = wpm
self._queue = Queue() self._queue = Queue()
self._thread = Thread(target=self.dispatch_messages) self._thread = Thread(target=self._dispatch_messages)
@property @property
def wpm(self): def wpm(self):
@ -20,19 +20,19 @@ class MessageQueueHandler:
@wpm.setter @wpm.setter
def wpm(self, wpm): def wpm(self, wpm):
self._wpm = wpm self._wpm = wpm
self._cps = 5*wpm/60 self._cps = 5 * wpm / 60
def dispatch_messages(self): def _dispatch_messages(self):
for message in iter(self._queue.get, None): for message in iter(self._queue.get, None):
sleep(len(message['message'])/self._cps) sleep(len(message['message'])/self._cps)
self.connector.send_message(message) self.connector.send_message(message)
def handle_event(self, message, _): def handle_event(self, message, _):
for unpacked in self.generate_messages_from_queue(message): for unpacked in self._generate_messages_from_queue(message):
self._queue.put(unpacked) self._queue.put(unpacked)
@staticmethod @staticmethod
def generate_messages_from_queue(queue_message): def _generate_messages_from_queue(queue_message):
last = queue_message['value'][-1] last = queue_message['value'][-1]
for message in queue_message['value']: for message in queue_message['value']:
yield { yield {