From 8afcb2e087d168e12499ba1254cd197008759b7a Mon Sep 17 00:00:00 2001 From: kiriharu Date: Wed, 13 Jan 2021 22:24:09 +0300 Subject: [PATCH] rewrited commands --- apps/tgbot/tgbot/handlers/default/icmp.py | 3 ++- apps/tgbot/tgbot/handlers/default/minecraft.py | 10 ++-------- apps/tgbot/tgbot/handlers/default/tcp.py | 6 +++--- apps/tgbot/tgbot/handlers/default/web.py | 10 ++-------- 4 files changed, 9 insertions(+), 20 deletions(-) diff --git a/apps/tgbot/tgbot/handlers/default/icmp.py b/apps/tgbot/tgbot/handlers/default/icmp.py index 592ffd5..4de783f 100644 --- a/apps/tgbot/tgbot/handlers/default/icmp.py +++ b/apps/tgbot/tgbot/handlers/default/icmp.py @@ -28,7 +28,8 @@ class ICMPCheckerHandler(CheckerBaseHandler): return await message.answer(icmp_help_message, parse_mode="Markdown") except LocalhostForbidden: return await message.answer(self.localhost_forbidden_message, parse_mode="Markdown") - await self.check(message.chat.id, message.bot, dict(target=args[0], target_fq=args[0])) + else: + await self.check(message.chat.id, message.bot, dict(target=args[0], target_fq=args[0])) async def process_args(self, text: str) -> list: args = text.split() diff --git a/apps/tgbot/tgbot/handlers/default/minecraft.py b/apps/tgbot/tgbot/handlers/default/minecraft.py index 405b6f4..790acaa 100644 --- a/apps/tgbot/tgbot/handlers/default/minecraft.py +++ b/apps/tgbot/tgbot/handlers/default/minecraft.py @@ -1,10 +1,8 @@ -from aiogram.types import Message from core.coretypes import ResponseStatus, ErrorPayload, MinecraftResponse from httpx import Response -from tgbot.handlers.base import CheckerBaseHandler, process_args_for_host_port +from tgbot.handlers.base import CheckerTargetPortHandler, process_args_for_host_port from tgbot.handlers.metrics import push_status_metric -from tgbot.middlewares.throttling import rate_limit minecraft_help_message = """ ❓ Получает статистику о Minecraft сервере @@ -18,17 +16,13 @@ minecraft_help_message = """ invalid_port = """❗Неправильный порт. Напишите /minecraft чтобы увидеть справку к данному способу проверки.""" -class MinecraftCheckerHandler(CheckerBaseHandler): +class MinecraftCheckerHandler(CheckerTargetPortHandler): help_message = minecraft_help_message api_endpoint = "minecraft" def __init__(self): super().__init__() - @rate_limit - async def handler(self, message: Message): - await self.target_port_handler(message) - async def process_args(self, text: str) -> list: return process_args_for_host_port(text, 25565) diff --git a/apps/tgbot/tgbot/handlers/default/tcp.py b/apps/tgbot/tgbot/handlers/default/tcp.py index e1b728e..a2aa1fc 100644 --- a/apps/tgbot/tgbot/handlers/default/tcp.py +++ b/apps/tgbot/tgbot/handlers/default/tcp.py @@ -2,7 +2,7 @@ from aiogram.types import Message from core.coretypes import ResponseStatus, ErrorPayload, PortResponse from httpx import Response -from tgbot.handlers.base import CheckerBaseHandler, NotEnoughArgs, InvalidPort +from tgbot.handlers.base import CheckerTargetPortHandler, NotEnoughArgs, InvalidPort from tgbot.handlers.helpers import check_int from tgbot.handlers.metrics import push_status_metric from tgbot.middlewares.throttling import rate_limit @@ -17,7 +17,7 @@ tcp_help_message = """ invalid_port = """❗Неправильный порт. Напишите /tcp чтобы увидеть справку к данному способу проверки.""" -class TCPCheckerHandler(CheckerBaseHandler): +class TCPCheckerHandler(CheckerTargetPortHandler): help_message = tcp_help_message api_endpoint = "tcp_port" @@ -26,7 +26,7 @@ class TCPCheckerHandler(CheckerBaseHandler): @rate_limit async def handler(self, message: Message): - await self.target_port_handler(message) + await super(TCPCheckerHandler, self).handler(message) async def process_args(self, text: str) -> list: port = None diff --git a/apps/tgbot/tgbot/handlers/default/web.py b/apps/tgbot/tgbot/handlers/default/web.py index 95a6dc2..dafc369 100644 --- a/apps/tgbot/tgbot/handlers/default/web.py +++ b/apps/tgbot/tgbot/handlers/default/web.py @@ -1,9 +1,7 @@ -from aiogram.types import Message from httpx import Response from core.coretypes import ResponseStatus, HTTP_EMOJI, HttpCheckerResponse, ErrorPayload -from ..base import CheckerBaseHandler, process_args_for_host_port +from ..base import CheckerTargetPortHandler, process_args_for_host_port from ..metrics import push_status_metric -from tgbot.middlewares.throttling import rate_limit web_help_message = """ ❓ Производит проверку хоста по протоколу HTTP. @@ -16,17 +14,13 @@ web_help_message = """ invalid_port = """❗Неправильный порт. Напишите /web чтобы увидеть справку к данному способу проверки.""" -class WebCheckerHandler(CheckerBaseHandler): +class WebCheckerHandler(CheckerTargetPortHandler): help_message = web_help_message api_endpoint = "http" def __init__(self): super().__init__() - @rate_limit - async def handler(self, message: Message): - await self.target_port_handler(message) - async def process_args(self, text: str) -> list: return process_args_for_host_port(text, 80)