added patched app

This commit is contained in:
kiriharu 2021-01-04 20:13:17 +03:00
parent 6023e35742
commit 761991eae6
7 changed files with 19 additions and 13 deletions

View File

@ -1,11 +1,8 @@
from flask import Flask, request, abort, jsonify
from gevent.pywsgi import WSGIServer
from gevent import monkey
from helpers import access_token_required
import config
monkey.patch_all()
# Monkey patch SSL in requests to prevent RecursionError! DO NOT REMOVE OR MOVE!
from checkers import HttpChecker, ICMPChecker
app = Flask(__name__)

View File

@ -0,0 +1,11 @@
from core.coretypes import Response
from .base import BaseChecker
class TCPPortChecker(BaseChecker):
def __init__(self, target: str):
super().__init__(target)
def check(self) -> Response:
pass

4
apps/api/api/patched.py Normal file
View File

@ -0,0 +1,4 @@
from gevent import monkey
monkey.patch_all()
from api.app import app

View File

@ -14,6 +14,8 @@ class ResponseStatus(str, Enum):
class ErrorCodes(IntEnum):
ConnectError = 1
ICMPHostNotAlive = 2
TCPPortClosed = 3
UDPPortClosed = 4
@dataclass

View File

@ -4,7 +4,6 @@ from .start import start_cmd
from .web import web_cmd
from .whois import whois_cmd
from .icmp import icmp_cmd
from .inline import inline_processor
def setup(dp: Dispatcher):
@ -12,4 +11,3 @@ def setup(dp: Dispatcher):
dp.register_message_handler(web_cmd, commands=['web', 'http'])
dp.register_message_handler(whois_cmd, commands=['whois'])
dp.register_message_handler(icmp_cmd, commands=['icmp'])
dp.register_inline_handler(inline_processor)

View File

@ -12,12 +12,6 @@ icmp_help_message = """
`/icmp <target>`
"""
no_icmp_text = """
Не указана цель для пингования.
Напишите /icmp чтобы посмотреть справку.
"""
async def prepare_icmp_check_result(res: Response):
node = APINodeInfo(**res.json().get("node", None))
@ -52,7 +46,7 @@ async def check_icmp(msg: Message, target: str):
async def icmp_cmd(msg: Message):
args = msg.text.split(" ")
if len(args) == 1:
return await msg.answer(no_icmp_text)
return await msg.answer(icmp_help_message, parse_mode="Markdown")
if len(args) >= 2:
target = args[1]
await check_icmp(msg, target)

View File

@ -2,7 +2,7 @@ from aiogram.types import Message
from typing import Optional
from tgbot.handlers.helpers import check_int
from tgbot.nodes import nodes as all_nodes
from httpx import AsyncClient, Response
from httpx import Response
from core.coretypes import ResponseStatus, HTTP_EMOJI
from datetime import datetime
from ..helpers import send_api_requests