2021-01-25 17:28:59 +01:00
|
|
|
import re
|
|
|
|
|
|
|
|
from discord.ext import commands
|
|
|
|
|
2021-01-26 17:11:30 +01:00
|
|
|
from tuxbot.cogs.Network.functions.exceptions import (
|
|
|
|
InvalidIp,
|
|
|
|
InvalidDomain,
|
|
|
|
InvalidQueryType,
|
|
|
|
)
|
2021-01-25 17:28:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
def _(x):
|
|
|
|
return x
|
|
|
|
|
|
|
|
|
|
|
|
class IPConverter(commands.Converter):
|
2021-01-26 09:43:25 +01:00
|
|
|
async def convert(self, ctx, argument): # skipcq: PYL-W0613
|
2021-01-25 17:28:59 +01:00
|
|
|
argument = argument.replace("http://", "").replace("https://", "")
|
2021-02-11 18:21:50 +01:00
|
|
|
argument = argument.rstrip("/")
|
2021-01-25 17:28:59 +01:00
|
|
|
|
2021-03-02 19:00:08 +01:00
|
|
|
if argument.startswith("`") and argument.endswith("`"):
|
|
|
|
argument = argument.lstrip("`").rstrip("`")
|
2021-01-25 17:28:59 +01:00
|
|
|
|
2021-03-02 19:00:08 +01:00
|
|
|
return argument.lower()
|
2021-01-25 17:28:59 +01:00
|
|
|
|
|
|
|
|
2021-03-02 19:00:08 +01:00
|
|
|
class DomainConverter(commands.Converter):
|
2021-01-26 15:24:10 +01:00
|
|
|
async def convert(self, ctx, argument): # skipcq: PYL-W0613
|
2021-01-26 17:11:30 +01:00
|
|
|
if not argument.startswith("http"):
|
|
|
|
return f"http://{argument}"
|
|
|
|
|
|
|
|
return argument
|
|
|
|
|
|
|
|
|
|
|
|
class QueryTypeConverter(commands.Converter):
|
|
|
|
async def convert(self, ctx, argument): # skipcq: PYL-W0613
|
2021-03-02 19:00:08 +01:00
|
|
|
return argument.lower()
|
2021-01-26 15:24:10 +01:00
|
|
|
|
|
|
|
|
2021-01-25 17:28:59 +01:00
|
|
|
class IPVersionConverter(commands.Converter):
|
2021-01-26 09:43:25 +01:00
|
|
|
async def convert(self, ctx, argument): # skipcq: PYL-W0613
|
2021-01-25 17:28:59 +01:00
|
|
|
if not argument:
|
|
|
|
return argument
|
|
|
|
|
2021-03-02 19:00:08 +01:00
|
|
|
return argument.replace("-", "").replace("ip", "").replace("v", "")
|