fix(commands:iplocalise|Network): remove crashing regex
This commit is contained in:
parent
0ecc97518f
commit
3525b9aa4b
13 changed files with 6 additions and 29 deletions
3
.mypy.ini
Normal file
3
.mypy.ini
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
[mypy]
|
||||||
|
ignore_missing_imports = True
|
||||||
|
exclude = venv
|
|
@ -1,2 +1,3 @@
|
||||||
pylint>=2.6.0
|
pylint>=2.6.0
|
||||||
black>=20.8b1
|
black>=20.8b1
|
||||||
|
mypy>=0.812
|
0
tuxbot/cogs/Admin/functions/__init__.py
Normal file
0
tuxbot/cogs/Admin/functions/__init__.py
Normal file
0
tuxbot/cogs/Crypto/functions/__init__.py
Normal file
0
tuxbot/cogs/Crypto/functions/__init__.py
Normal file
0
tuxbot/cogs/Custom/functions/__init__.py
Normal file
0
tuxbot/cogs/Custom/functions/__init__.py
Normal file
0
tuxbot/cogs/Dev/functions/__init__.py
Normal file
0
tuxbot/cogs/Dev/functions/__init__.py
Normal file
0
tuxbot/cogs/Logs/functions/__init__.py
Normal file
0
tuxbot/cogs/Logs/functions/__init__.py
Normal file
0
tuxbot/cogs/Network/functions/__init__.py
Normal file
0
tuxbot/cogs/Network/functions/__init__.py
Normal 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]))"
|
|
|
@ -1,4 +1,3 @@
|
||||||
import re
|
|
||||||
import socket
|
import socket
|
||||||
from typing import Union, NoReturn
|
from typing import Union, NoReturn
|
||||||
|
|
||||||
|
@ -10,11 +9,6 @@ from ipinfo.exceptions import RequestQuotaExceededError
|
||||||
|
|
||||||
from ipwhois import Net
|
from ipwhois import Net
|
||||||
from ipwhois.asn import IPASN
|
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 (
|
from tuxbot.cogs.Network.functions.exceptions import (
|
||||||
VersionNotFound,
|
VersionNotFound,
|
||||||
|
@ -44,7 +38,7 @@ async def get_ip(ip: str, inet: str = "", tmp: discord.Message = None) -> str:
|
||||||
|
|
||||||
raise VersionNotFound(
|
raise VersionNotFound(
|
||||||
_(
|
_(
|
||||||
"Impossible to collect information on this in the given "
|
"Unable to collect information on this in the given "
|
||||||
"version",
|
"version",
|
||||||
)
|
)
|
||||||
) from e
|
) from e
|
||||||
|
@ -137,17 +131,6 @@ async def get_pydig_result(
|
||||||
return resolver.query(domain, query_type)
|
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]:
|
def check_ip_version_or_raise(version: str) -> Union[bool, NoReturn]:
|
||||||
if version in ["4", "6", ""]:
|
if version in ["4", "6", ""]:
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -41,7 +41,6 @@ from .functions.utils import (
|
||||||
get_ipwhois_result,
|
get_ipwhois_result,
|
||||||
merge_ipinfo_ipwhois,
|
merge_ipinfo_ipwhois,
|
||||||
get_pydig_result,
|
get_pydig_result,
|
||||||
check_ip_or_raise,
|
|
||||||
check_query_type_or_raise,
|
check_query_type_or_raise,
|
||||||
check_ip_version_or_raise,
|
check_ip_version_or_raise,
|
||||||
)
|
)
|
||||||
|
@ -59,9 +58,6 @@ class Network(commands.Cog, name="Network"):
|
||||||
).config
|
).config
|
||||||
|
|
||||||
async def cog_command_error(self, ctx, error):
|
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(
|
if isinstance(
|
||||||
error,
|
error,
|
||||||
(
|
(
|
||||||
|
@ -73,8 +69,6 @@ class Network(commands.Cog, name="Network"):
|
||||||
VersionNotFound,
|
VersionNotFound,
|
||||||
),
|
),
|
||||||
):
|
):
|
||||||
self.bot.console.log("Pass there")
|
|
||||||
|
|
||||||
await ctx.send(_(str(error), ctx, self.bot.config))
|
await ctx.send(_(str(error), ctx, self.bot.config))
|
||||||
|
|
||||||
# =========================================================================
|
# =========================================================================
|
||||||
|
@ -87,7 +81,6 @@ class Network(commands.Cog, name="Network"):
|
||||||
ip: IPConverter,
|
ip: IPConverter,
|
||||||
version: IPVersionConverter = "",
|
version: IPVersionConverter = "",
|
||||||
):
|
):
|
||||||
check_ip_or_raise(str(ip))
|
|
||||||
check_ip_version_or_raise(str(version))
|
check_ip_version_or_raise(str(version))
|
||||||
|
|
||||||
tmp = await ctx.send(
|
tmp = await ctx.send(
|
||||||
|
|
0
tuxbot/cogs/Polls/functions/__init__.py
Normal file
0
tuxbot/cogs/Polls/functions/__init__.py
Normal file
0
tuxbot/cogs/Utils/functions/__init__.py
Normal file
0
tuxbot/cogs/Utils/functions/__init__.py
Normal file
Loading…
Reference in a new issue