Browse Source

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

master
Romain J 6 months ago
parent
commit
3525b9aa4b
  1. 3
      .mypy.ini
  2. 3
      dev.requirements.txt
  3. 0
      tuxbot/cogs/Admin/functions/__init__.py
  4. 0
      tuxbot/cogs/Crypto/functions/__init__.py
  5. 0
      tuxbot/cogs/Custom/functions/__init__.py
  6. 0
      tuxbot/cogs/Dev/functions/__init__.py
  7. 0
      tuxbot/cogs/Logs/functions/__init__.py
  8. 0
      tuxbot/cogs/Network/functions/__init__.py
  9. 3
      tuxbot/cogs/Network/functions/consts.py
  10. 19
      tuxbot/cogs/Network/functions/utils.py
  11. 7
      tuxbot/cogs/Network/network.py
  12. 0
      tuxbot/cogs/Polls/functions/__init__.py
  13. 0
      tuxbot/cogs/Utils/functions/__init__.py

3
.mypy.ini

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

3
dev.requirements.txt

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

0
tuxbot/cogs/Admin/functions/__init__.py

0
tuxbot/cogs/Crypto/functions/__init__.py

0
tuxbot/cogs/Custom/functions/__init__.py

0
tuxbot/cogs/Dev/functions/__init__.py

0
tuxbot/cogs/Logs/functions/__init__.py

0
tuxbot/cogs/Network/functions/__init__.py

3
tuxbot/cogs/Network/functions/consts.py

@ -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]))"

19
tuxbot/cogs/Network/functions/utils.py

@ -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

7
tuxbot/cogs/Network/network.py

@ -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(

0
tuxbot/cogs/Polls/functions/__init__.py

0
tuxbot/cogs/Utils/functions/__init__.py

Loading…
Cancel
Save