mirror of
https://github.com/onyx-and-iris/vban-cmd-python.git
synced 2026-04-18 04:53:31 +00:00
add a ratelimit decorator to {VbanCmd}.sendtext()
ip kwarg renamed to host.
This commit is contained in:
@@ -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"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user