|
|
@ -1,22 +1,31 @@ |
|
|
|
import logging |
|
|
|
import operator |
|
|
|
from discord.embeds import Embed |
|
|
|
from discord.ext import commands |
|
|
|
import pendulum |
|
|
|
from cogs.route import Route |
|
|
|
|
|
|
|
log = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
|
|
|
# Ugly but it works |
|
|
|
def security_to_type(security: int) -> str: |
|
|
|
if security <= 0: |
|
|
|
return "nullsec" |
|
|
|
elif 0 < security < 0.5: |
|
|
|
return "lowsec" |
|
|
|
else: |
|
|
|
return "highsec" |
|
|
|
|
|
|
|
|
|
|
|
class Thera(commands.Cog): |
|
|
|
def __init__(self, bot): |
|
|
|
self.bot = bot |
|
|
|
self.api = "https://www.eve-scout.com/api/wormholes?systemSearch={}" |
|
|
|
|
|
|
|
@commands.command(pass_context=True) |
|
|
|
async def thera(self, ctx, *, system): |
|
|
|
async def thera(self, ctx, system, force_status=None): |
|
|
|
""" |
|
|
|
Search Eve-Scout for the nearest reported thera hole near [system] |
|
|
|
Append <highsec|lowsec|nullsec> at the end to only search for exits in systems with such security status. |
|
|
|
""" |
|
|
|
if not system: |
|
|
|
raise commands.MissingRequiredArgument("Missing a system name.") |
|
|
@ -42,50 +51,52 @@ class Thera(commands.Cog): |
|
|
|
if response.status != 200: |
|
|
|
raise TimeoutError |
|
|
|
result = await response.json() |
|
|
|
if result: |
|
|
|
try: |
|
|
|
nearest = sorted(result, key=operator.itemgetter("jumps")) |
|
|
|
except KeyError: |
|
|
|
return await ctx.send("Could not find a connection to Thera.") |
|
|
|
for i in nearest: |
|
|
|
if i["sourceWormholeType"]["dest"] in { |
|
|
|
"nullsec", |
|
|
|
"lowsec", |
|
|
|
"highsec", |
|
|
|
}: |
|
|
|
time_until_eol = pendulum.parse(i["wormholeEstimatedEol"]) |
|
|
|
|
|
|
|
embed = Embed( |
|
|
|
title=f"Closest Thera connection from {system_name}" |
|
|
|
) |
|
|
|
embed.set_footer(text="All data is pulled from eve-scout.com") |
|
|
|
embed.add_field( |
|
|
|
name="System", value=i["destinationSolarSystem"]["name"] |
|
|
|
) |
|
|
|
embed.add_field( |
|
|
|
name="Region", |
|
|
|
value=i["destinationSolarSystem"]["region"]["name"], |
|
|
|
) |
|
|
|
embed.add_field(name="Jumps", value=i["jumps"], inline=True) |
|
|
|
embed.add_field( |
|
|
|
name="Out Sig", value=i["signatureId"], inline=True |
|
|
|
) |
|
|
|
embed.add_field( |
|
|
|
name="In Sig", |
|
|
|
value=i["wormholeDestinationSignatureId"], |
|
|
|
inline=True, |
|
|
|
) |
|
|
|
embed.add_field( |
|
|
|
name="Mass", value=i["wormholeMass"].capitalize() |
|
|
|
) |
|
|
|
embed.add_field( |
|
|
|
name="Est. EOL", |
|
|
|
value=f"Less than {time_until_eol.diff_for_humans(absolute=True)}", |
|
|
|
) |
|
|
|
embed.description = f'http://evemaps.dotlan.net/route/{system_name}:{i["destinationSolarSystem"]["name"]}' |
|
|
|
return await ctx.send(embed=embed) |
|
|
|
|
|
|
|
return await ctx.send("Could not find a connection to Thera.") |
|
|
|
if not result: |
|
|
|
raise ValueError |
|
|
|
|
|
|
|
for i in sorted(result, key=lambda info: info['jumps']): |
|
|
|
# This will ignore wormhole systems |
|
|
|
if i['jumps'] <= 0: |
|
|
|
continue |
|
|
|
|
|
|
|
destination = i["destinationSolarSystem"] |
|
|
|
|
|
|
|
if force_status is not None: |
|
|
|
if security_to_type(destination["security"]) != force_status: |
|
|
|
continue |
|
|
|
|
|
|
|
time_until_eol = pendulum.parse(i["wormholeEstimatedEol"]) |
|
|
|
|
|
|
|
embed = Embed(title=f"Closest Thera connection from {system_name}") |
|
|
|
embed.add_field( |
|
|
|
name="System", |
|
|
|
value=f'{destination["name"]} ({destination["security"]:.2f})' |
|
|
|
) |
|
|
|
embed.add_field( |
|
|
|
name="Region", |
|
|
|
value=destination["region"]["name"], |
|
|
|
) |
|
|
|
embed.add_field(name="Jumps", value=i["jumps"], inline=True) |
|
|
|
embed.add_field( |
|
|
|
name="Out Sig", value=i["signatureId"], inline=True |
|
|
|
) |
|
|
|
embed.add_field( |
|
|
|
name="In Sig", |
|
|
|
value=i["wormholeDestinationSignatureId"], |
|
|
|
inline=True, |
|
|
|
) |
|
|
|
embed.add_field( |
|
|
|
name="Mass", value=i["wormholeMass"].capitalize() |
|
|
|
) |
|
|
|
embed.add_field( |
|
|
|
name="Est. EOL", |
|
|
|
value=f"Less than {time_until_eol.diff_for_humans(absolute=True)}", |
|
|
|
) |
|
|
|
embed.description = f'http://evemaps.dotlan.net/route/{system_name}:{destination["name"]}' |
|
|
|
embed.set_footer(text="All data is pulled from eve-scout.com") |
|
|
|
return await ctx.send(embed=embed) |
|
|
|
|
|
|
|
return await ctx.send("Could not find a connection to Thera.") |
|
|
|
|
|
|
|
|
|
|
|
def setup(bot): |
|
|
|