Make WPM customization available per-message basis

This commit is contained in:
R. Richard 2019-08-26 14:18:23 +02:00
parent af3781adb3
commit 0ea6188a05

View File

@ -8,23 +8,15 @@ class MessageQueueHandler:
def __init__(self, wpm): def __init__(self, wpm):
self.connector = None self.connector = 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
def wpm(self):
return self._wpm
@wpm.setter
def wpm(self, wpm):
self._wpm = wpm
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) wpm = message['wpm'] if 'wpm' in message else self.wpm
cps = 5 * wpm / 60
sleep(len(message['message']) / cps)
self.connector.send_message(message) self.connector.send_message(message)
def handle_event(self, message, _): def handle_event(self, message, _):