mirror of
https://github.com/catspace-dev/unicheckbot.git
synced 2024-11-22 05:46:33 +03:00
Remove redundant async/await when there is no IO
This commit is contained in:
parent
51fc561ef4
commit
f81f1953d1
|
@ -28,10 +28,10 @@ class SimpleCommandHandler:
|
||||||
async def handler(self, message: Message):
|
async def handler(self, message: Message):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
async def process_args(self, text: str) -> list:
|
def process_args(self, text: str) -> list:
|
||||||
raise NotImplemented
|
raise NotImplemented
|
||||||
|
|
||||||
async def validate_target(self, target: str):
|
def validate_target(self, target: str):
|
||||||
for validator in self.validators:
|
for validator in self.validators:
|
||||||
validator.validate(target)
|
validator.validate(target)
|
||||||
|
|
||||||
|
@ -81,7 +81,7 @@ class CheckerTargetPortHandler(CheckerBaseHandler):
|
||||||
async def handler(self, message: Message):
|
async def 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:
|
||||||
args = await self.process_args(message.text)
|
args = self.process_args(message.text)
|
||||||
except NotEnoughArgs:
|
except NotEnoughArgs:
|
||||||
logger.info(f"User {message.from_user.id} got NotEnoughArgs error")
|
logger.info(f"User {message.from_user.id} got NotEnoughArgs error")
|
||||||
return await message.answer(self.help_message, parse_mode="Markdown")
|
return await message.answer(self.help_message, parse_mode="Markdown")
|
||||||
|
@ -89,7 +89,7 @@ class CheckerTargetPortHandler(CheckerBaseHandler):
|
||||||
logger.info(f"User {message.from_user.id} got InvalidPort error")
|
logger.info(f"User {message.from_user.id} got InvalidPort error")
|
||||||
return await message.answer(self.invalid_port_message, parse_mode="Markdown")
|
return await message.answer(self.invalid_port_message, parse_mode="Markdown")
|
||||||
try:
|
try:
|
||||||
await self.validate_target(args[0])
|
self.validate_target(args[0])
|
||||||
except ValueError: # For ip check
|
except ValueError: # For ip check
|
||||||
pass
|
pass
|
||||||
except LocalhostForbidden:
|
except LocalhostForbidden:
|
||||||
|
|
|
@ -23,7 +23,7 @@ class ICMPCheckerHandler(CheckerBaseHandler):
|
||||||
@rate_limit
|
@rate_limit
|
||||||
async def handler(self, message: Message):
|
async def handler(self, message: Message):
|
||||||
try:
|
try:
|
||||||
args = await self.process_args(message.text)
|
args = self.process_args(message.text)
|
||||||
except NotEnoughArgs:
|
except NotEnoughArgs:
|
||||||
return await message.answer(icmp_help_message, parse_mode="Markdown")
|
return await message.answer(icmp_help_message, parse_mode="Markdown")
|
||||||
except LocalhostForbidden:
|
except LocalhostForbidden:
|
||||||
|
@ -31,13 +31,13 @@ class ICMPCheckerHandler(CheckerBaseHandler):
|
||||||
else:
|
else:
|
||||||
await self.check(message.chat.id, message.bot, dict(target=args[0], target_fq=args[0]))
|
await self.check(message.chat.id, message.bot, dict(target=args[0], target_fq=args[0]))
|
||||||
|
|
||||||
async def process_args(self, text: str) -> list:
|
def process_args(self, text: str) -> list:
|
||||||
args = text.split()
|
args = text.split()
|
||||||
if len(args) == 1:
|
if len(args) == 1:
|
||||||
raise NotEnoughArgs()
|
raise NotEnoughArgs()
|
||||||
if len(args) >= 2:
|
if len(args) >= 2:
|
||||||
target = args[1]
|
target = args[1]
|
||||||
await self.validate_target(target)
|
self.validate_target(target)
|
||||||
return [target]
|
return [target]
|
||||||
|
|
||||||
async def prepare_message(self, res: Response):
|
async def prepare_message(self, res: Response):
|
||||||
|
|
|
@ -24,7 +24,7 @@ class IPCalcCommandHandler(SimpleCommandHandler):
|
||||||
@rate_limit
|
@rate_limit
|
||||||
async def handler(self, message: Message):
|
async def handler(self, message: Message):
|
||||||
try:
|
try:
|
||||||
args = await self.process_args(message.text)
|
args = self.process_args(message.text)
|
||||||
network = ipaddress.ip_network(args[1], False)
|
network = ipaddress.ip_network(args[1], False)
|
||||||
except NotEnoughArgs:
|
except NotEnoughArgs:
|
||||||
await message.answer(self.help_message, parse_mode='Markdown')
|
await message.answer(self.help_message, parse_mode='Markdown')
|
||||||
|
@ -34,7 +34,7 @@ class IPCalcCommandHandler(SimpleCommandHandler):
|
||||||
msg = await self.prepare_message(network)
|
msg = await self.prepare_message(network)
|
||||||
await message.answer(msg)
|
await message.answer(msg)
|
||||||
|
|
||||||
async def process_args(self, text: str) -> list:
|
def process_args(self, text: str) -> list:
|
||||||
args = text.split()
|
args = text.split()
|
||||||
if len(args) == 1:
|
if len(args) == 1:
|
||||||
raise NotEnoughArgs
|
raise NotEnoughArgs
|
||||||
|
|
|
@ -24,7 +24,7 @@ class MinecraftCheckerHandler(CheckerTargetPortHandler):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
async def process_args(self, text: str) -> list:
|
def process_args(self, text: str) -> list:
|
||||||
return process_args_for_host_port(text, 25565)
|
return process_args_for_host_port(text, 25565)
|
||||||
|
|
||||||
async def prepare_message(self, res: Response):
|
async def prepare_message(self, res: Response):
|
||||||
|
|
|
@ -29,7 +29,7 @@ class TCPCheckerHandler(CheckerTargetPortHandler):
|
||||||
async def handler(self, message: Message):
|
async def handler(self, message: Message):
|
||||||
await super(TCPCheckerHandler, self).handler(message)
|
await super(TCPCheckerHandler, self).handler(message)
|
||||||
|
|
||||||
async def process_args(self, text: str) -> list:
|
def process_args(self, text: str) -> list:
|
||||||
args = text.split(' ', 1)
|
args = text.split(' ', 1)
|
||||||
if len(args) != 2:
|
if len(args) != 2:
|
||||||
raise NotEnoughArgs()
|
raise NotEnoughArgs()
|
||||||
|
|
|
@ -22,7 +22,7 @@ class WebCheckerHandler(CheckerTargetPortHandler):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
async def process_args(self, text: str) -> list:
|
def process_args(self, text: str) -> list:
|
||||||
return process_args_for_host_port(text, 80)
|
return process_args_for_host_port(text, 80)
|
||||||
|
|
||||||
async def prepare_message(self, res: Response):
|
async def prepare_message(self, res: Response):
|
||||||
|
|
|
@ -116,7 +116,7 @@ class WhoisCommandHandler(SimpleCommandHandler):
|
||||||
@rate_limit
|
@rate_limit
|
||||||
async def handler(self, message: Message):
|
async def handler(self, message: Message):
|
||||||
try:
|
try:
|
||||||
args = await self.process_args(message.text)
|
args = self.process_args(message.text)
|
||||||
except NotEnoughArgs:
|
except NotEnoughArgs:
|
||||||
await message.answer(no_domain_text, parse_mode='Markdown')
|
await message.answer(no_domain_text, parse_mode='Markdown')
|
||||||
except LocalhostForbidden:
|
except LocalhostForbidden:
|
||||||
|
@ -124,13 +124,13 @@ class WhoisCommandHandler(SimpleCommandHandler):
|
||||||
else:
|
else:
|
||||||
await message.answer(create_whois_message(args[0]), parse_mode='html')
|
await message.answer(create_whois_message(args[0]), parse_mode='html')
|
||||||
|
|
||||||
async def process_args(self, text: str) -> list:
|
def process_args(self, text: str) -> list:
|
||||||
args = text.split()
|
args = text.split()
|
||||||
if len(args) == 1:
|
if len(args) == 1:
|
||||||
raise NotEnoughArgs
|
raise NotEnoughArgs
|
||||||
if len(args) >= 2:
|
if len(args) >= 2:
|
||||||
host = args[1]
|
host = args[1]
|
||||||
await self.validate_target(host)
|
self.validate_target(host)
|
||||||
return [host] # only domain name
|
return [host] # only domain name
|
||||||
|
|
||||||
async def prepare_message(self) -> str:
|
async def prepare_message(self) -> str:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user