mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 16:21:31 +00:00
Make WPM customization available per-message basis
This commit is contained in:
parent
af3781adb3
commit
0ea6188a05
@ -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, _):
|
||||||
|
Loading…
Reference in New Issue
Block a user