mirror of
https://github.com/catspace-dev/unicheckbot.git
synced 2024-11-25 07:13:44 +03:00
small refactor
This commit is contained in:
parent
3ca281627f
commit
00ea38b251
|
@ -49,10 +49,13 @@ class CheckerBaseHandler(SimpleCommandHandler):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def check(self, chat_id: int, bot: Bot, data: dict):
|
async def check(self, msg: Message, data: dict):
|
||||||
# TODO: start check and end check metrics with ident, chat_id and api_endpoint
|
# TODO: start check and end check metrics with ident, chat_id and api_endpoint
|
||||||
ts = time()
|
ts = time()
|
||||||
ident = uuid4().hex
|
ident = uuid4().hex
|
||||||
|
# refactoring goes brr
|
||||||
|
chat_id = msg.chat.id
|
||||||
|
bot = msg.bot
|
||||||
logger.info(f"User {chat_id} started check {ident}")
|
logger.info(f"User {chat_id} started check {ident}")
|
||||||
# format header
|
# format header
|
||||||
rsp_msg = await bot.send_message(
|
rsp_msg = await bot.send_message(
|
||||||
|
@ -71,8 +74,9 @@ class CheckerBaseHandler(SimpleCommandHandler):
|
||||||
iter_keys = iter_keys + 1
|
iter_keys = iter_keys + 1
|
||||||
|
|
||||||
if NOTIFY_CHECKS:
|
if NOTIFY_CHECKS:
|
||||||
notify_text = f"**User {chat_id} issued check: {self.api_endpoint} for {data['target_fq']}**\n\n" \
|
notify_text = f"**User {msg.from_user.full_name} (@{msg.from_user.username}) ({chat_id}) issued check: " \
|
||||||
f"```{rsp_msg.text}```"
|
f"{self.api_endpoint} for {data['target_fq']}**\n\n" \
|
||||||
|
f"```\n{rsp_msg.text}\n```"
|
||||||
await send_message_to_admins(notify_text)
|
await send_message_to_admins(notify_text)
|
||||||
|
|
||||||
logger.info(f"User {chat_id} ended check {ident}")
|
logger.info(f"User {chat_id} ended check {ident}")
|
||||||
|
@ -108,8 +112,7 @@ class CheckerTargetPortHandler(CheckerBaseHandler):
|
||||||
logger.info(f"User {message.from_user.id} got LocalhostForbidden error")
|
logger.info(f"User {message.from_user.id} got LocalhostForbidden error")
|
||||||
return await message.answer(self.localhost_forbidden_message, parse_mode="Markdown")
|
return await message.answer(self.localhost_forbidden_message, parse_mode="Markdown")
|
||||||
await self.check(
|
await self.check(
|
||||||
message.chat.id,
|
message,
|
||||||
message.bot,
|
|
||||||
dict(target=args[0], port=args[1], target_fq=f"{args[0]}:{args[1]}")
|
dict(target=args[0], port=args[1], target_fq=f"{args[0]}:{args[1]}")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ class ICMPCheckerHandler(CheckerBaseHandler):
|
||||||
except LocalhostForbidden:
|
except LocalhostForbidden:
|
||||||
return await message.answer(self.localhost_forbidden_message, parse_mode="Markdown")
|
return await message.answer(self.localhost_forbidden_message, parse_mode="Markdown")
|
||||||
else:
|
else:
|
||||||
await self.check(message.chat.id, message.bot, dict(target=args[0], target_fq=args[0]))
|
await self.check(message, dict(target=args[0], target_fq=args[0]))
|
||||||
|
|
||||||
def process_args(self, text: str) -> list:
|
def process_args(self, text: str) -> list:
|
||||||
args = text.split()
|
args = text.split()
|
||||||
|
|
|
@ -27,7 +27,7 @@ start_message = """
|
||||||
🚩 [Этот бот с открытым с исходным кодом](https://github.com/catspace-dev/unicheckbot)
|
🚩 [Этот бот с открытым с исходным кодом](https://github.com/catspace-dev/unicheckbot)
|
||||||
🚩 [Помогите улучшить бота](https://github.com/catspace-dev/unicheckbot/issues) или [расскажите об ошибке](https://github.com/catspace-dev/unicheckbot/issues)
|
🚩 [Помогите улучшить бота](https://github.com/catspace-dev/unicheckbot/issues) или [расскажите об ошибке](https://github.com/catspace-dev/unicheckbot/issues)
|
||||||
|
|
||||||
Разработчик: [kiriharu](http://t.me/kiriharu)
|
Разработчик: [kiriharu](https://t.me/kiriharu)
|
||||||
При поддержке: [SpaceCore.pro](https://spacecore.pro/)
|
При поддержке: [SpaceCore.pro](https://spacecore.pro/)
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user