From 3525b9aa4bc2f0b11d9f5b2ef69228b092abbbac Mon Sep 17 00:00:00 2001 From: Romain J Date: Fri, 26 Mar 2021 18:41:21 +0100 Subject: [PATCH] fix(commands:iplocalise|Network): remove crashing regex --- .mypy.ini | 3 +++ dev.requirements.txt | 3 ++- 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 | 0 tuxbot/cogs/Network/functions/consts.py | 3 --- tuxbot/cogs/Network/functions/utils.py | 19 +------------------ tuxbot/cogs/Network/network.py | 7 ------- tuxbot/cogs/Polls/functions/__init__.py | 0 tuxbot/cogs/Utils/functions/__init__.py | 0 13 files changed, 6 insertions(+), 29 deletions(-) create mode 100644 .mypy.ini create mode 100644 tuxbot/cogs/Admin/functions/__init__.py create mode 100644 tuxbot/cogs/Crypto/functions/__init__.py create mode 100644 tuxbot/cogs/Custom/functions/__init__.py create mode 100644 tuxbot/cogs/Dev/functions/__init__.py create mode 100644 tuxbot/cogs/Logs/functions/__init__.py create mode 100644 tuxbot/cogs/Network/functions/__init__.py delete mode 100644 tuxbot/cogs/Network/functions/consts.py create mode 100644 tuxbot/cogs/Polls/functions/__init__.py create mode 100644 tuxbot/cogs/Utils/functions/__init__.py diff --git a/.mypy.ini b/.mypy.ini new file mode 100644 index 0000000..c005c7d --- /dev/null +++ b/.mypy.ini @@ -0,0 +1,3 @@ +[mypy] +ignore_missing_imports = True +exclude = venv diff --git a/dev.requirements.txt b/dev.requirements.txt index d75ecc1..da9cb13 100644 --- a/dev.requirements.txt +++ b/dev.requirements.txt @@ -1,2 +1,3 @@ pylint>=2.6.0 -black>=20.8b1 \ No newline at end of file +black>=20.8b1 +mypy>=0.812 \ No newline at end of file diff --git a/tuxbot/cogs/Admin/functions/__init__.py b/tuxbot/cogs/Admin/functions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tuxbot/cogs/Crypto/functions/__init__.py b/tuxbot/cogs/Crypto/functions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tuxbot/cogs/Custom/functions/__init__.py b/tuxbot/cogs/Custom/functions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tuxbot/cogs/Dev/functions/__init__.py b/tuxbot/cogs/Dev/functions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tuxbot/cogs/Logs/functions/__init__.py b/tuxbot/cogs/Logs/functions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tuxbot/cogs/Network/functions/__init__.py b/tuxbot/cogs/Network/functions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tuxbot/cogs/Network/functions/consts.py b/tuxbot/cogs/Network/functions/consts.py deleted file mode 100644 index 0b89acf..0000000 --- a/tuxbot/cogs/Network/functions/consts.py +++ /dev/null @@ -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]))" diff --git a/tuxbot/cogs/Network/functions/utils.py b/tuxbot/cogs/Network/functions/utils.py index 79d0cb6..118f478 100644 --- a/tuxbot/cogs/Network/functions/utils.py +++ b/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 diff --git a/tuxbot/cogs/Network/network.py b/tuxbot/cogs/Network/network.py index 0ea02cb..e449625 100644 --- a/tuxbot/cogs/Network/network.py +++ b/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( diff --git a/tuxbot/cogs/Polls/functions/__init__.py b/tuxbot/cogs/Polls/functions/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tuxbot/cogs/Utils/functions/__init__.py b/tuxbot/cogs/Utils/functions/__init__.py new file mode 100644 index 0000000..e69de29