From 5ab4d79b6e6d136629c52c3570ef7594154bc3ed Mon Sep 17 00:00:00 2001 From: kiriharu Date: Mon, 11 Jan 2021 12:01:46 +0300 Subject: [PATCH] rate limit for ipcalc handler --- apps/tgbot/tgbot/handlers/base.py | 1 + apps/tgbot/tgbot/handlers/default/ipcalc.py | 2 ++ 2 files changed, 3 insertions(+) diff --git a/apps/tgbot/tgbot/handlers/base.py b/apps/tgbot/tgbot/handlers/base.py index 551b26b..d62037d 100644 --- a/apps/tgbot/tgbot/handlers/base.py +++ b/apps/tgbot/tgbot/handlers/base.py @@ -96,6 +96,7 @@ class CheckerBaseHandler(SimpleCommandHandler): te = time() logger.info(f"func {__name__} took {te - ts} sec") + # TODO: Validation classes async def validate_target(self, target: str): if validate_local(target): raise LocalhostForbidden() diff --git a/apps/tgbot/tgbot/handlers/default/ipcalc.py b/apps/tgbot/tgbot/handlers/default/ipcalc.py index e6cee69..8b02503 100644 --- a/apps/tgbot/tgbot/handlers/default/ipcalc.py +++ b/apps/tgbot/tgbot/handlers/default/ipcalc.py @@ -3,6 +3,7 @@ from typing import Union import ipaddress from tgbot.handlers.base import SimpleCommandHandler, NotEnoughArgs +from tgbot.middlewares.throttling import rate_limit ipcalc_help_message = """ ❓ Калькулятор IP подсетей. @@ -20,6 +21,7 @@ class IPCalcCommandHandler(SimpleCommandHandler): def __init__(self): super().__init__() + @rate_limit async def handler(self, message: Message): try: args = await self.process_args(message.text)