From c6b9fa6112e336aa64c9c4e2261cd2aa753e7800 Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Tue, 26 Apr 2022 22:47:48 +0100 Subject: [PATCH] Update vbancmd.py add ratelimit kwarg. applies only to multiset operations (apply, profile_apply). --- vbancmd/vbancmd.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/vbancmd/vbancmd.py b/vbancmd/vbancmd.py index cab6301..ef7e695 100644 --- a/vbancmd/vbancmd.py +++ b/vbancmd/vbancmd.py @@ -29,6 +29,7 @@ class VbanCmd(abc.ABC): self._channel = kwargs["channel"] self._delay = kwargs["delay"] self._sync = kwargs["sync"] + self._ratelimit = kwargs["ratelimit"] # fmt: off self._bps_opts = [ 0, 110, 150, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 31250, @@ -66,6 +67,7 @@ class VbanCmd(abc.ABC): self.running = True self._pdirty = False self.cache = {} + self.in_apply = False def __enter__(self): self.login() @@ -203,6 +205,8 @@ class VbanCmd(abc.ABC): self.cache[f"{id_}.{param}"] = val if self._sync: sleep(self._delay) + if self.in_apply: + sleep(self._ratelimit) def sendtext(self, cmd): """Sends a multiple parameter string over a network.""" @@ -237,6 +241,7 @@ class VbanCmd(abc.ABC): def apply(self, mapping: dict): """Sets all parameters of a di""" + self.in_apply = True for key, submapping in mapping.items(): obj, index = key.split("-") @@ -247,8 +252,8 @@ class VbanCmd(abc.ABC): else: raise ValueError(obj) target.apply(submapping) - if not self._sync: - sleep(self._delay * 30) + sleep(self._ratelimit) + self.in_apply = False def apply_profile(self, name: str): try: @@ -258,7 +263,7 @@ class VbanCmd(abc.ABC): del profile["extends"] for key in profile.keys(): if key in base: - base[key] |= profile[key] + base[key] = base[key] | profile[key] else: base[key] = profile[key] profile = base @@ -314,6 +319,7 @@ def _make_remote(kind: NamedTuple) -> VbanCmd: "channel": 0, "delay": 0.001, "sync": False, + "ratelimit": 0.025, } kwargs = defaultkwargs | kwargs VbanCmd.__init__(self, **kwargs)