mirror of
https://github.com/catspace-dev/unicheckbot.git
synced 2024-11-21 21:46:32 +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):
|
||||
pass
|
||||
|
||||
async def process_args(self, text: str) -> list:
|
||||
def process_args(self, text: str) -> list:
|
||||
raise NotImplemented
|
||||
|
||||
async def validate_target(self, target: str):
|
||||
def validate_target(self, target: str):
|
||||
for validator in self.validators:
|
||||
validator.validate(target)
|
||||
|
||||
|
@ -81,7 +81,7 @@ class CheckerTargetPortHandler(CheckerBaseHandler):
|
|||
async def handler(self, message: Message):
|
||||
"""This hanler can be used if you need target port args"""
|
||||
try:
|
||||
args = await self.process_args(message.text)
|
||||
args = self.process_args(message.text)
|
||||
except NotEnoughArgs:
|
||||
logger.info(f"User {message.from_user.id} got NotEnoughArgs error")
|
||||
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")
|
||||
return await message.answer(self.invalid_port_message, parse_mode="Markdown")
|
||||
try:
|
||||
await self.validate_target(args[0])
|
||||
self.validate_target(args[0])
|
||||
except ValueError: # For ip check
|
||||
pass
|
||||
except LocalhostForbidden:
|
||||
|
|
|
@ -23,7 +23,7 @@ class ICMPCheckerHandler(CheckerBaseHandler):
|
|||
@rate_limit
|
||||
async def handler(self, message: Message):
|
||||
try:
|
||||
args = await self.process_args(message.text)
|
||||
args = self.process_args(message.text)
|
||||
except NotEnoughArgs:
|
||||
return await message.answer(icmp_help_message, parse_mode="Markdown")
|
||||
except LocalhostForbidden:
|
||||
|
@ -31,13 +31,13 @@ class ICMPCheckerHandler(CheckerBaseHandler):
|
|||
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:
|
||||
def process_args(self, text: str) -> list:
|
||||
args = text.split()
|
||||
if len(args) == 1:
|
||||
raise NotEnoughArgs()
|
||||
if len(args) >= 2:
|
||||
target = args[1]
|
||||
await self.validate_target(target)
|
||||
self.validate_target(target)
|
||||
return [target]
|
||||
|
||||
async def prepare_message(self, res: Response):
|
||||
|
|
|
@ -24,7 +24,7 @@ class IPCalcCommandHandler(SimpleCommandHandler):
|
|||
@rate_limit
|
||||
async def handler(self, message: Message):
|
||||
try:
|
||||
args = await self.process_args(message.text)
|
||||
args = self.process_args(message.text)
|
||||
network = ipaddress.ip_network(args[1], False)
|
||||
except NotEnoughArgs:
|
||||
await message.answer(self.help_message, parse_mode='Markdown')
|
||||
|
@ -34,7 +34,7 @@ class IPCalcCommandHandler(SimpleCommandHandler):
|
|||
msg = await self.prepare_message(network)
|
||||
await message.answer(msg)
|
||||
|
||||
async def process_args(self, text: str) -> list:
|
||||
def process_args(self, text: str) -> list:
|
||||
args = text.split()
|
||||
if len(args) == 1:
|
||||
raise NotEnoughArgs
|
||||
|
|
|
@ -24,7 +24,7 @@ class MinecraftCheckerHandler(CheckerTargetPortHandler):
|
|||
def __init__(self):
|
||||
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)
|
||||
|
||||
async def prepare_message(self, res: Response):
|
||||
|
|
|
@ -29,7 +29,7 @@ class TCPCheckerHandler(CheckerTargetPortHandler):
|
|||
async def handler(self, message: 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)
|
||||
if len(args) != 2:
|
||||
raise NotEnoughArgs()
|
||||
|
|
|
@ -22,7 +22,7 @@ class WebCheckerHandler(CheckerTargetPortHandler):
|
|||
def __init__(self):
|
||||
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)
|
||||
|
||||
async def prepare_message(self, res: Response):
|
||||
|
|
|
@ -116,7 +116,7 @@ class WhoisCommandHandler(SimpleCommandHandler):
|
|||
@rate_limit
|
||||
async def handler(self, message: Message):
|
||||
try:
|
||||
args = await self.process_args(message.text)
|
||||
args = self.process_args(message.text)
|
||||
except NotEnoughArgs:
|
||||
await message.answer(no_domain_text, parse_mode='Markdown')
|
||||
except LocalhostForbidden:
|
||||
|
@ -124,13 +124,13 @@ class WhoisCommandHandler(SimpleCommandHandler):
|
|||
else:
|
||||
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()
|
||||
if len(args) == 1:
|
||||
raise NotEnoughArgs
|
||||
if len(args) >= 2:
|
||||
host = args[1]
|
||||
await self.validate_target(host)
|
||||
self.validate_target(host)
|
||||
return [host] # only domain name
|
||||
|
||||
async def prepare_message(self) -> str:
|
||||
|
|
Loading…
Reference in New Issue
Block a user