MCPcopy Create free account
hub / github.com/TimMcCool/scratchattach / enforce_ratelimit

Function enforce_ratelimit

scratchattach/site/session.py:53–67  ·  view source on GitHub ↗
(__type: str, name: str, amount: int = 5, duration: int = 60)

Source from the content-addressed store, hash-verified

51
52
53def enforce_ratelimit(__type: str, name: str, amount: int = 5, duration: int = 60) -> None:
54 cache = ratelimit_cache
55 cache.setdefault(__type, [])
56 uses = cache[__type]
57 while uses and uses[-1] < time.time() - duration:
58 uses.pop()
59 if len(uses) < amount:
60 uses.insert(0, time.time())
61 return
62 raise exceptions.RateLimitedError(
63 f"Rate limit for {name} exceeded.\n"
64 "This rate limit is enforced by scratchattach, not by the Scratch API.\n"
65 "For security reasons, it cannot be turned off.\n\n"
66 "Don't spam-create studios or similar, it WILL get you banned."
67 )
68
69
70C = TypeVar("C", bound=BaseSiteComponent)

Callers 3

create_projectMethod · 0.85
create_studioMethod · 0.85
create_classMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected