fix(commands:iplocalise|Network): remove crashing regex

This commit is contained in:
Romain J 2021-03-26 18:41:21 +01:00
parent 0ecc97518f
commit 3525b9aa4b
13 changed files with 6 additions and 29 deletions

3
.mypy.ini Normal file
View file

@ -0,0 +1,3 @@
[mypy]
ignore_missing_imports = True
exclude = venv

View file

@ -1,2 +1,3 @@
pylint>=2.6.0
black>=20.8b1
black>=20.8b1
mypy>=0.812

View file

View file

View file

View file

View file

View file

@ -1,3 +0,0 @@
DOMAIN_PATTERN = r"^((.*)+\.)+[a-z\-]{2,}\.?$"
IPV4_PATTERN = r"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$"
IPV6_PATTERN = r"^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))"

View file

@ -1,4 +1,3 @@
import re
import socket
from typing import Union, NoReturn
@ -10,11 +9,6 @@ from ipinfo.exceptions import RequestQuotaExceededError
from ipwhois import Net
from ipwhois.asn import IPASN
from tuxbot.cogs.Network.functions.consts import (
DOMAIN_PATTERN,
IPV4_PATTERN,
IPV6_PATTERN,
)
from tuxbot.cogs.Network.functions.exceptions import (
VersionNotFound,
@ -44,7 +38,7 @@ async def get_ip(ip: str, inet: str = "", tmp: discord.Message = None) -> str:
raise VersionNotFound(
_(
"Impossible to collect information on this in the given "
"Unable to collect information on this in the given "
"version",
)
) from e
@ -137,17 +131,6 @@ async def get_pydig_result(
return resolver.query(domain, query_type)
def check_ip_or_raise(ip: str) -> Union[bool, NoReturn]:
check_domain = re.match(DOMAIN_PATTERN, ip)
check_ipv4 = re.match(IPV4_PATTERN, ip)
check_ipv6 = re.match(IPV6_PATTERN, ip)
if check_domain or check_ipv4 or check_ipv6:
return True
raise InvalidIp(_("Invalid ip or domain"))
def check_ip_version_or_raise(version: str) -> Union[bool, NoReturn]:
if version in ["4", "6", ""]:
return True

View file

@ -41,7 +41,6 @@ from .functions.utils import (
get_ipwhois_result,
merge_ipinfo_ipwhois,
get_pydig_result,
check_ip_or_raise,
check_query_type_or_raise,
check_ip_version_or_raise,
)
@ -59,9 +58,6 @@ class Network(commands.Cog, name="Network"):
).config
async def cog_command_error(self, ctx, error):
self.bot.console.log("Pass here")
self.bot.console.log(error)
self.bot.console.log(type(error))
if isinstance(
error,
(
@ -73,8 +69,6 @@ class Network(commands.Cog, name="Network"):
VersionNotFound,
),
):
self.bot.console.log("Pass there")
await ctx.send(_(str(error), ctx, self.bot.config))
# =========================================================================
@ -87,7 +81,6 @@ class Network(commands.Cog, name="Network"):
ip: IPConverter,
version: IPVersionConverter = "",
):
check_ip_or_raise(str(ip))
check_ip_version_or_raise(str(version))
tmp = await ctx.send(

View file

View file