add a ratelimit decorator to {VbanCmd}.sendtext()

ip kwarg renamed to host.
This commit is contained in:
2026-03-02 23:20:45 +00:00
parent cf66ae252c
commit 86d0aa91c3
4 changed files with 42 additions and 29 deletions

View File

@@ -1,6 +1,23 @@
import time
from typing import Iterator
def ratelimit(func):
"""ratelimit decorator for {VbanCmd}.sendtext, to prevent flooding the network with script requests."""
def wrapper(*args, **kwargs):
self, *rem = args
if self.script_ratelimit > 0:
now = time.time()
elapsed = now - self._last_script_request_time
if elapsed < self.script_ratelimit:
time.sleep(self.script_ratelimit - elapsed)
self._last_script_request_time = time.time()
return func(*args, **kwargs)
return wrapper
def cache_bool(func, param):
"""Check cache for a bool prop"""