mirror of
https://github.com/catspace-dev/unicheckbot.git
synced 2025-07-09 15:52:25 +03:00
implement simple command handlera
This commit is contained in:
parent
19a400328e
commit
b6918d8724
|
@ -28,7 +28,19 @@ class LocalhostForbidden(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class CheckerBaseHandler:
|
class SimpleCommandHandler:
|
||||||
|
|
||||||
|
async def handler(self, message: Message):
|
||||||
|
pass
|
||||||
|
|
||||||
|
async def process_args(self, text: str) -> list:
|
||||||
|
raise NotImplemented
|
||||||
|
|
||||||
|
async def prepare_message(self, res: Response) -> str:
|
||||||
|
raise NotImplemented
|
||||||
|
|
||||||
|
|
||||||
|
class CheckerBaseHandler(SimpleCommandHandler):
|
||||||
help_message = "Set help message in class!"
|
help_message = "Set help message in class!"
|
||||||
header_message = header
|
header_message = header
|
||||||
localhost_forbidden_message = "❗ Локальные адреса запрещены"
|
localhost_forbidden_message = "❗ Локальные адреса запрещены"
|
||||||
|
@ -39,9 +51,6 @@ class CheckerBaseHandler:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def handler(self, message: Message):
|
|
||||||
"""Always should call check at end"""
|
|
||||||
|
|
||||||
async def target_port_handler(self, message: Message):
|
async def target_port_handler(self, message: Message):
|
||||||
"""This hanler can be used if you need target port args"""
|
"""This hanler can be used if you need target port args"""
|
||||||
try:
|
try:
|
||||||
|
@ -88,18 +97,12 @@ class CheckerBaseHandler:
|
||||||
if validate_local(target):
|
if validate_local(target):
|
||||||
raise LocalhostForbidden()
|
raise LocalhostForbidden()
|
||||||
|
|
||||||
async def process_args(self, text: str) -> list:
|
|
||||||
raise NotImplemented
|
|
||||||
|
|
||||||
async def message_std_vals(self, res: Response) -> Tuple[str, Any]:
|
async def message_std_vals(self, res: Response) -> Tuple[str, Any]:
|
||||||
node = APINodeInfo(**res.json().get("node", None))
|
node = APINodeInfo(**res.json().get("node", None))
|
||||||
message = f"{node.location}:\n"
|
message = f"{node.location}:\n"
|
||||||
status = res.json().get("status", None)
|
status = res.json().get("status", None)
|
||||||
return message, status
|
return message, status
|
||||||
|
|
||||||
async def prepare_message(self, res: Response) -> str:
|
|
||||||
raise NotImplemented
|
|
||||||
|
|
||||||
|
|
||||||
def process_args_for_host_port(text: str, default_port: int) -> list:
|
def process_args_for_host_port(text: str, default_port: int) -> list:
|
||||||
port = None
|
port = None
|
||||||
|
|
Loading…
Reference in New Issue
Block a user