feat: add Commands enum, delete useless commands, revamp the Settings class and the MarkovChain.message_handler method
This commit is contained in:
parent
29e1242591
commit
3a33411dd9
18 changed files with 1111 additions and 1190 deletions
32
src/markovbot_gui/libs/timer.py
Normal file
32
src/markovbot_gui/libs/timer.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import logging
|
||||
import threading
|
||||
from collections.abc import Callable
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class LoopingTimer(threading.Thread):
|
||||
"""
|
||||
Thread that will continuously run `target(*args, **kwargs)`
|
||||
every `interval` seconds, until program termination.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
interval: int,
|
||||
target: Callable[[], None],
|
||||
*args,
|
||||
**kwargs,
|
||||
) -> None:
|
||||
threading.Thread.__init__(self)
|
||||
self.interval = interval
|
||||
self.target = target
|
||||
self.args = args
|
||||
self.kwargs = kwargs
|
||||
|
||||
self.stopped = threading.Event()
|
||||
self.daemon = True
|
||||
|
||||
def run(self):
|
||||
while not self.stopped.wait(self.interval):
|
||||
self.target(*self.args, **self.kwargs)
|
||||
Loading…
Add table
Add a link
Reference in a new issue