refactor(all): add black
to all code
This commit is contained in:
parent
cdb891d435
commit
9869312ee8
19 changed files with 428 additions and 391 deletions
tuxbot/cogs/network
|
@ -1,6 +1,18 @@
|
|||
from collections import namedtuple
|
||||
|
||||
from .network import Network
|
||||
from ...core.bot import Tux
|
||||
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro releaselevel")
|
||||
version_info = VersionInfo(major=2, minor=0, micro=0, releaselevel="alpha")
|
||||
|
||||
__version__ = "v{}.{}.{}-{}".format(
|
||||
version_info.major,
|
||||
version_info.minor,
|
||||
version_info.micro,
|
||||
version_info.releaselevel
|
||||
).replace("\n", "")
|
||||
|
||||
|
||||
def setup(bot: Tux):
|
||||
bot.add_cog(Network(bot))
|
||||
|
|
|
@ -19,14 +19,13 @@ class Network(commands.Cog, name="Useless"):
|
|||
def __init__(self, bot: TuxBot):
|
||||
self.bot = bot
|
||||
|
||||
@flags.add_flag("-i", "--ip", type=str, default='v4',
|
||||
choices=['v4', '4', 'v6', '6'])
|
||||
@command_extra(name="iplocalise", aliases=['localiseip'])
|
||||
@flags.add_flag(
|
||||
"-i", "--ip", type=str, default="v4", choices=["v4", "4", "v6", "6"]
|
||||
)
|
||||
@command_extra(name="iplocalise", aliases=["localiseip"])
|
||||
@commands.cooldown(1, 5, commands.BucketType.user)
|
||||
async def _iplocalise(self, ctx: ContextPlus, target: str, **passed_flags):
|
||||
loading = await ctx.send(
|
||||
"_Récupération des informations..._", deletable=False
|
||||
)
|
||||
loading = await ctx.send("_Récupération des informations..._", deletable=False)
|
||||
|
||||
def get_hostname(dtl, tgt):
|
||||
try:
|
||||
|
@ -35,25 +34,29 @@ class Network(commands.Cog, name="Useless"):
|
|||
try:
|
||||
return socket.gethostbyaddr(tgt)[0]
|
||||
except (ValueError, socket.herror):
|
||||
return 'N/A'
|
||||
return "N/A"
|
||||
|
||||
ip_type = passed_flags.get('ip')
|
||||
ip_type = passed_flags.get("ip")
|
||||
target_copy = target
|
||||
|
||||
# clean https://, last /, ...
|
||||
spltTgt = target.split("://")
|
||||
target = spltTgt[
|
||||
(0, 1)[len(spltTgt) > 1]
|
||||
].split("?")[0].split('/')[0].split(':')[0].lower()
|
||||
target = (
|
||||
spltTgt[(0, 1)[len(spltTgt) > 1]]
|
||||
.split("?")[0]
|
||||
.split("/")[0]
|
||||
.split(":")[0]
|
||||
.lower()
|
||||
)
|
||||
|
||||
try:
|
||||
target = socket.getaddrinfo(
|
||||
target, None,
|
||||
socket.AF_INET if ip_type in ['v4', '4'] else socket.AF_INET6
|
||||
target,
|
||||
None,
|
||||
socket.AF_INET if ip_type in ["v4", "4"] else socket.AF_INET6,
|
||||
)[1][4][0]
|
||||
except socket.gaierror:
|
||||
return \
|
||||
await ctx.send("Erreur, cette adresse n'est pas disponible.")
|
||||
return await ctx.send("Erreur, cette adresse n'est pas disponible.")
|
||||
|
||||
net = Net(target)
|
||||
obj = IPASN(net)
|
||||
|
@ -70,34 +73,38 @@ class Network(commands.Cog, name="Useless"):
|
|||
if api_result:
|
||||
belongs = f"{details.org}"
|
||||
|
||||
osm = f"https://www.openstreetmap.org/" \
|
||||
f"?mlat={details.latitude}" \
|
||||
f"&mlon={details.longitude}" \
|
||||
f"#map=5/{details.latitude}/{details.longitude}" \
|
||||
f"&layers=H"
|
||||
osm = (
|
||||
f"https://www.openstreetmap.org/"
|
||||
f"?mlat={details.latitude}"
|
||||
f"&mlon={details.longitude}"
|
||||
f"#map=5/{details.latitude}/{details.longitude}"
|
||||
f"&layers=H"
|
||||
)
|
||||
|
||||
region = f"[{details.city} - {details.region} " \
|
||||
f"({details.country})]({osm})"
|
||||
flag = f"https://www.countryflags.io/" \
|
||||
f"{details.country}/shiny/64.png"
|
||||
region = (
|
||||
f"[{details.city} - {details.region} " f"({details.country})]({osm})"
|
||||
)
|
||||
flag = f"https://www.countryflags.io/" f"{details.country}/shiny/64.png"
|
||||
else:
|
||||
belongs = f"{ip_info['asn_description']} (AS{ip_info['asn']})"
|
||||
region = f"{ip_info['asn_country_code']}"
|
||||
flag = f"https://www.countryflags.io/" \
|
||||
f"{ip_info['asn_country_code']}/shiny/64.png"
|
||||
flag = (
|
||||
f"https://www.countryflags.io/"
|
||||
f"{ip_info['asn_country_code']}/shiny/64.png"
|
||||
)
|
||||
|
||||
e = discord.Embed(
|
||||
title=f"**Information sur __{target_copy}__ :**"
|
||||
f" `{target}`",
|
||||
color=0x5858d7
|
||||
title=f"**Information sur __{target_copy}__ :**" f" `{target}`",
|
||||
color=0x5858D7,
|
||||
)
|
||||
|
||||
e.add_field(name="Appartient à :", value=belongs)
|
||||
e.add_field(name="RIR :", value=f"{ip_info['asn_registry']}")
|
||||
e.add_field(name="Region :", value=region)
|
||||
|
||||
e.add_field(name="Nom de l'hôte :",
|
||||
value=get_hostname(details, target), inline=False)
|
||||
e.add_field(
|
||||
name="Nom de l'hôte :", value=get_hostname(details, target), inline=False
|
||||
)
|
||||
|
||||
e.set_thumbnail(url=flag)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue