(__type: str, name: str, amount: int = 5, duration: int = 60)
| 51 | |
| 52 | |
| 53 | def 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 | |
| 70 | C = TypeVar("C", bound=BaseSiteComponent) |
no outgoing calls
no test coverage detected