feat: add Commands enum, delete useless commands, revamp the Settings class and the MarkovChain.message_handler method

This commit is contained in:
cătălin 2024-11-01 04:40:17 +01:00
commit 3a33411dd9
No known key found for this signature in database
18 changed files with 1111 additions and 1190 deletions

View 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)