2021-01-25 17:28:59 +01:00
|
|
|
from discord.ext import commands
|
2021-04-22 18:11:55 +02:00
|
|
|
from discord.ext.commands import Context
|
2021-01-25 17:28:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
def _(x):
|
|
|
|
return x
|
|
|
|
|
|
|
|
|
|
|
|
class IPConverter(commands.Converter):
|
2021-04-22 18:11:55 +02:00
|
|
|
async def convert(self, ctx: Context, argument: str): # 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-04-22 18:11:55 +02:00
|
|
|
async def convert(self, ctx: Context, argument: str): # 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):
|
2021-04-22 18:11:55 +02:00
|
|
|
async def convert(self, ctx: Context, argument: str): # skipcq: PYL-W0613
|
2021-03-02 19:00:08 +01:00
|
|
|
return argument.lower()
|
2021-01-26 15:24:10 +01:00
|
|
|
|
|
|
|
|
2021-04-24 22:34:53 +02:00
|
|
|
class IPParamsConverter(commands.Converter):
|
2021-04-22 18:11:55 +02:00
|
|
|
async def convert(self, ctx: Context, argument: str): # skipcq: PYL-W0613
|
2021-01-25 17:28:59 +01:00
|
|
|
if not argument:
|
2021-04-24 22:34:53 +02:00
|
|
|
return None
|
2021-01-25 17:28:59 +01:00
|
|
|
|
2021-04-24 22:34:53 +02:00
|
|
|
params = {
|
|
|
|
"inet": "",
|
|
|
|
"map": "map" in argument.lower(),
|
|
|
|
}
|
|
|
|
|
|
|
|
if "4" in argument:
|
|
|
|
params["inet"] = "4"
|
|
|
|
elif "6" in argument:
|
|
|
|
params["inet"] = "6"
|
|
|
|
elif len(arg := argument.split(" ")) >= 2:
|
|
|
|
params["inet"] = arg[0]
|
|
|
|
|
|
|
|
return params
|
2021-04-22 18:11:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ASConverter(commands.Converter):
|
|
|
|
async def convert(self, ctx: Context, argument: str): # skipcq: PYL-W0613
|
|
|
|
return argument.lower().lstrip("as")
|