rewrited commands

This commit is contained in:
kiriharu 2021-01-13 22:24:09 +03:00
parent 352d27f8b2
commit 8afcb2e087
4 changed files with 9 additions and 20 deletions

View File

@ -28,6 +28,7 @@ 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")
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:

View File

@ -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)

View File

@ -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

View File

@ -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)