Browse Source

Compatibility for esipysi .10

drop the invoke decorators and use the default session in each esi call
tidy up some formatting here and there
pull/4/head
Mike 3 years ago
parent
commit
f8eff48b42
  1. 1
      cogs/about.py
  2. 6
      cogs/eft.py
  3. 8
      cogs/esiprice.py
  4. 8
      cogs/insurance.py
  5. 16
      cogs/killstream.py
  6. 12
      cogs/reminder.py
  7. 10
      cogs/route.py
  8. 77
      cogs/thera.py
  9. 4
      cogs/units.py
  10. 3
      cogs/utils/eft.py
  11. 167
      cogs/utils/esi.py
  12. 8
      cogs/where.py
  13. 20
      cogs/who.py
  14. 2
      cogs/zkill.py

1
cogs/about.py

@ -54,7 +54,6 @@ class About(commands.Cog):
embed.add_field(name=server.name, value=f"{len(server.members)} Members")
return await ctx.send(embed=embed)
@commands.command(hidden=True)
async def uptime(self, ctx):
"""

6
cogs/eft.py

@ -198,11 +198,5 @@ class EFT(commands.Cog):
return await message.channel.send(embed=embed)
def setup(bot):
bot.add_cog(EFT(bot))

8
cogs/esiprice.py

@ -90,14 +90,6 @@ class EsiPrice(commands.Cog):
market_info = "No Market Data"
return market_info[str(itemid)]
@price.before_invoke
async def before_invoke(self, ctx):
await self.bot.esi.esi.start_session()
@price.after_invoke
async def after_invoke(self, ctx):
await self.bot.esi.esi.stop_session()
def setup(bot):
bot.add_cog(EsiPrice(bot))

8
cogs/insurance.py

@ -56,14 +56,6 @@ class Insurance(commands.Cog):
"Ship not found or insurance rates not available for shipname"
)
@insure.before_invoke
async def before_invoke(self, ctx):
await self.bot.esi.esi.start_session()
@insure.after_invoke
async def after_invoke(self, ctx):
await self.bot.esi.esi.stop_session()
def setup(bot):
bot.add_cog(Insurance(bot))

16
cogs/killstream.py

@ -50,7 +50,6 @@ class Killstream(commands.Cog):
break
async def announce_kill(self, losstype, killpackage, channel):
await self.bot.esi.esi.start_session()
kill_id = killpackage.get("killmail_id")
# Check if kill has been announced
kill_key = self.__kill_key(kill_id, channel)
@ -153,7 +152,6 @@ class Killstream(commands.Cog):
text=f"killed {pendulum.parse(killpackage['killmail_time']).diff_for_humans()}"
)
announce_chan = get(self.bot.get_all_channels(), id=channel)
await self.bot.esi.esi.stop_session()
return await announce_chan.send(embed=e)
def __kill_key(self, kill_id, channel_id):
@ -452,20 +450,6 @@ class Killstream(commands.Cog):
async def before_killstream(self):
await self.bot.wait_until_ready()
@killwatch.before_invoke
@corp.before_invoke
@alliance.before_invoke
@char.before_invoke
async def before_invoke(self, ctx):
await self.bot.esi.esi.start_session()
@killwatch.after_invoke
@corp.after_invoke
@alliance.after_invoke
@char.after_invoke
async def after_invoke(self, ctx):
await self.bot.esi.esi.stop_session()
def setup(bot):
bot.add_cog(Killstream(bot))

12
cogs/reminder.py

@ -30,7 +30,9 @@ class Reminder(commands.Cog):
try:
timeguess = search_dates(reminder)
except SystemError:
return await ctx.send("I was not able to parse the time in your reminder properly")
return await ctx.send(
"I was not able to parse the time in your reminder properly"
)
if not timeguess:
return await ctx.send("I was not able to parse a time in your reminder.")
else:
@ -49,7 +51,13 @@ class Reminder(commands.Cog):
message = self.sanitize(message)
remindtime = dateparser.parse(
time, languages=["en"], settings={"TIMEZONE": "UTC", 'RETURN_AS_TIMEZONE_AWARE': False, "PREFER_DATES_FROM": "future"}
time,
languages=["en"],
settings={
"TIMEZONE": "UTC",
"RETURN_AS_TIMEZONE_AWARE": False,
"PREFER_DATES_FROM": "future",
},
)
now = datetime.datetime.utcnow()

10
cogs/route.py

@ -108,16 +108,6 @@ class Route(commands.Cog):
f"{origin_info['name']}{destination_info['name']}: {dis_ly:.3f} ly"
)
@ly.before_invoke
@route.before_invoke
async def before_invoke(self, ctx):
await self.bot.esi.esi.start_session()
@ly.after_invoke
@route.after_invoke
async def after_invoke(self, ctx):
await self.bot.esi.esi.stop_session()
def setup(bot):
bot.add_cog(Route(bot))

77
cogs/thera.py

@ -10,7 +10,7 @@ log = logging.getLogger(__name__)
class Thera(commands.Cog):
def __init__(self, bot):
self.bot = bot
self.api = 'https://www.eve-scout.com/api/wormholes?systemSearch={}'
self.api = "https://www.eve-scout.com/api/wormholes?systemSearch={}"
@commands.command(pass_context=True)
async def thera(self, ctx, *, system):
@ -18,24 +18,24 @@ class Thera(commands.Cog):
Search Eve-Scout for the nearest reported thera hole near [system]
"""
if not system:
raise commands.MissingRequiredArgument('Missing a system name.')
raise commands.MissingRequiredArgument("Missing a system name.")
await ctx.trigger_typing()
origin_lookup = await self.bot.esi.loose_search('solar_system', system)
origin_lookup = await self.bot.esi.loose_search("solar_system", system)
try:
system_id = origin_lookup['solar_system'][0]
system_id = origin_lookup["solar_system"][0]
except KeyError:
raise commands.BadArgument('Cannot find a system with that name!')
raise commands.BadArgument("Cannot find a system with that name!")
system_info = await self.bot.esi.system_info(system_id=system_id)
try:
system_name = system_info['name']
system_name = system_info["name"]
except KeyError:
raise commands.BadArgument('Could not fetch system info!')
raise commands.BadArgument("Could not fetch system info!")
if system_name == 'Thera':
return await ctx.send('Are you already in Thera?')
if system_name == "Thera":
return await ctx.send("Are you already in Thera?")
async with self.bot.session.get(self.api.format(system_name)) as response:
if response.status != 200:
@ -43,34 +43,47 @@ class Thera(commands.Cog):
result = await response.json()
if result:
try:
nearest = sorted(result, key=operator.itemgetter('jumps'))
nearest = sorted(result, key=operator.itemgetter("jumps"))
except KeyError:
return await ctx.send('Could not find a connection to Thera.')
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'])
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 = 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)}",
)
return await ctx.send(embed=embed)
return await ctx.send('Could not find a connection to Thera.')
@thera.before_invoke
async def before_invoke(self, ctx):
await self.bot.esi.esi.start_session()
@thera.after_invoke
async def after_invoke(self, ctx):
await self.bot.esi.esi.stop_session()
return await ctx.send("Could not find a connection to Thera.")
def setup(bot):

4
cogs/units.py

@ -22,7 +22,9 @@ class Units(commands.Cog):
try:
src, dst = unitstring.split(" to ")
except ValueError:
return await ctx.send('Error unpacking your conversion, try something like "3 pounds to kilograms"')
return await ctx.send(
'Error unpacking your conversion, try something like "3 pounds to kilograms"'
)
return await ctx.send(round(self.Q(src).to(dst), 2))

3
cogs/utils/eft.py

@ -214,6 +214,7 @@ def getfit(lines):
fit.cargo.append(cargo)
return fit
class EftImportError(Exception):
"""Exception class emitted and consumed by EFT importer internally."""
@ -624,4 +625,4 @@ class MultiItemSpec(BaseItemSpec):
@property
def isCargo(self):
return True
return True

167
cogs/utils/esi.py

@ -25,114 +25,127 @@ class ESI:
# self.auth_esi = EsiAuth(config.client_id, config.secret_key)
async def search(self, scope, entity):
entity_search = self.esi.get_operation("get_search")
result = await entity_search.execute(
categories=scope, search=entity, strict="true"
)
return result.json()
async with self.esi.session() as sesh:
entity_search = sesh.get_operation("get_search")
result = await entity_search.execute(
categories=scope, search=entity, strict="true"
)
return result.json()
async def loose_search(self, scope, entity):
entity_search = self.esi.get_operation("get_search")
result = await entity_search.execute(
categories=scope, search=entity, strict="false"
)
return result.json()
async with self.esi.session() as sesh:
entity_search = sesh.get_operation("get_search")
result = await entity_search.execute(
categories=scope, search=entity, strict="false"
)
return result.json()
async def kill_lookup(self, kill_id, kill_hash):
kill_call = self.esi.get_operation("get_killmails_killmail_id_killmail_hash")
result = await kill_call.execute(killmail_id=kill_id, killmail_hash=kill_hash)
return result.json()
async with self.esi.session() as sesh:
kill_call = sesh.get_operation("get_killmails_killmail_id_killmail_hash")
result = await kill_call.execute(
killmail_id=kill_id, killmail_hash=kill_hash
)
return result.json()
async def character_sheet(self, character_id):
character_sheet_op = self.esi.get_operation("get_characters_character_id")
result = await character_sheet_op.execute(character_id=character_id)
return result.json()
async with self.esi.session() as sesh:
character_sheet_op = sesh.get_operation("get_characters_character_id")
result = await character_sheet_op.execute(character_id=character_id)
return result.json()
async def corporation_history(self, character_id):
corp_history_op = self.esi.get_operation(
"get_characters_character_id_corporationhistory"
)
result = await corp_history_op.execute(character_id=character_id)
return result.json()
async with self.esi.session() as sesh:
corp_history_op = sesh.get_operation(
"get_characters_character_id_corporationhistory"
)
result = await corp_history_op.execute(character_id=character_id)
return result.json()
async def corporation_sheet(self, corporation_id):
corporation_sheet_op = self.esi.get_operation("get_corporations_corporation_id")
result = await corporation_sheet_op.execute(corporation_id=corporation_id)
return result.json()
async with self.esi.session() as sesh:
corporation_sheet_op = sesh.get_operation("get_corporations_corporation_id")
result = await corporation_sheet_op.execute(corporation_id=corporation_id)
return result.json()
async def alliance_sheet(self, alliance_id):
alliance_sheet_op = self.esi.get_operation("get_alliances_alliance_id")
result = await alliance_sheet_op.execute(alliance_id=alliance_id)
return result.json()
async with self.esi.session() as sesh:
alliance_sheet_op = sesh.get_operation("get_alliances_alliance_id")
result = await alliance_sheet_op.execute(alliance_id=alliance_id)
return result.json()
async def insurance_prices(self):
insurance_op = self.esi.get_operation("get_insurance_prices")
result = await insurance_op.execute()
return result.json()
async with self.esi.session() as sesh:
insurance_op = sesh.get_operation("get_insurance_prices")
result = await insurance_op.execute()
return result.json()
async def ship_info(self, ship_id):
ship_op = self.esi.get_operation("get_universe_types_type_id")
result = await ship_op.execute(type_id=ship_id)
return result.json()
async with self.esi.session() as sesh:
ship_op = sesh.get_operation("get_universe_types_type_id")
result = await ship_op.execute(type_id=ship_id)
return result.json()
async def system_info(self, system_id):
system_op = self.esi.get_operation("get_universe_systems_system_id")
result = await system_op.execute(system_id=system_id)
return result.json()
async with self.esi.session() as sesh:
system_op = sesh.get_operation("get_universe_systems_system_id")
result = await system_op.execute(system_id=system_id)
return result.json()
async def constellation_info(self, constellation_id):
const_op = self.esi.get_operation(
"get_universe_constellations_constellation_id"
)
result = await const_op.execute(constellation_id=constellation_id)
return result.json()
async with self.esi.session() as sesh:
const_op = sesh.get_operation(
"get_universe_constellations_constellation_id"
)
result = await const_op.execute(constellation_id=constellation_id)
return result.json()
async def region_info(self, region_id):
region_op = self.esi.get_operation("get_universe_regions_region_id")
result = await region_op.execute(region_id=region_id)
return result.json()
async with self.esi.session() as sesh:
region_op = sesh.get_operation("get_universe_regions_region_id")
result = await region_op.execute(region_id=region_id)
return result.json()
async def route(self, origin_id, destination_id, flag):
route_op = self.esi.get_operation("get_route_origin_destination")
try:
result = await route_op.execute(
origin=origin_id, destination=destination_id, flag=flag
)
except HTTPError:
raise SwaggerError(
"No Route Found, Did you try to navigate to a wormhole maybe?"
)
else:
return result.json()
async with self.esi.session() as sesh:
route_op = sesh.get_operation("get_route_origin_destination")
try:
result = await route_op.execute(
origin=origin_id, destination=destination_id, flag=flag
)
except HTTPError:
raise SwaggerError(
"No Route Found, Did you try to navigate to a wormhole maybe?"
)
else:
return result.json()
async def universe_names(self, ids):
name_op = self.esi.get_operation("post_universe_names")
result = await name_op.execute(ids=ids)
return result.json()
async with self.esi.session() as sesh:
name_op = sesh.get_operation("post_universe_names")
result = await name_op.execute(ids=ids)
return result.json()
async def system_kills(self):
kills_op = self.esi.get_operation("get_universe_system_kills")
result = await kills_op.execute()
return result.json()
async with self.esi.session() as sesh:
kills_op = sesh.get_operation("get_universe_system_kills")
result = await kills_op.execute()
return result.json()
async def system_jumps(self):
jumps_op = self.esi.get_operation("get_universe_system_jumps")
result = await jumps_op.execute()
return result.json()
async with self.esi.session() as sesh:
jumps_op = sesh.get_operation("get_universe_system_jumps")
result = await jumps_op.execute()
return result.json()
async def sov_map(self):
sov_op = self.esi.get_operation("get_sovereignty_map")
result = await sov_op.execute()
return result.json()
async with self.esi.session() as sesh:
sov_op = sesh.get_operation("get_sovereignty_map")
result = await sov_op.execute()
return result.json()
async def system_adm(self):
adm_op = self.esi.get_operation("get_sovereignty_structures")
result = await adm_op.execute()
return result.json()
def raise_or_return(self, result):
print(result)
if result.status != 200:
raise SwaggerError("ESI is down or broken currently :(")
else:
return result
async with self.esi.session() as sesh:
adm_op = sesh.get_operation("get_sovereignty_structures")
result = await adm_op.execute()
return result.json()

8
cogs/where.py

@ -186,14 +186,6 @@ class Where(commands.Cog):
await ctx.send(embed=embed)
@where.before_invoke
async def before_invoke(self, ctx):
await self.bot.esi.esi.start_session()
@where.after_invoke
async def after_invoke(self, ctx):
await self.bot.esi.esi.stop_session()
def setup(bot):
bot.add_cog(Where(bot))

20
cogs/who.py

@ -262,7 +262,7 @@ class Who(commands.Cog):
return "_unknown_"
async def zkill_activity(self, ctx, scope, entity_id):
#go nighty nite for a second to avoid zkill throttle
# go nighty nite for a second to avoid zkill throttle
await asyncio.sleep(1)
async with ctx.session.get(
f"https://zkillboard.com/api/{scope}/{entity_id}/"
@ -284,7 +284,7 @@ class Who(commands.Cog):
return last_active
async def zkill_stats(self, ctx, scope, entity_id):
#go nighty night for a second to avoid a zkill throttle
# go nighty night for a second to avoid a zkill throttle
await asyncio.sleep(1)
async with ctx.session.get(
f"https://zkillboard.com/api/stats/{scope}/{entity_id}/"
@ -332,22 +332,6 @@ class Who(commands.Cog):
"""
await ctx.invoke(self.alliance, alliance=alliance)
@who.before_invoke
@corp.before_invoke
@alliance.before_invoke
@corp_alias.before_invoke
@alliance_alias.before_invoke
async def before_invoke(self, ctx):
await self.bot.esi.esi.start_session()
@who.after_invoke
@corp.after_invoke
@alliance.after_invoke
@corp_alias.after_invoke
@alliance_alias.after_invoke
async def after_invoke(self, ctx):
await self.bot.esi.esi.stop_session()
def setup(bot):
bot.add_cog(Who(bot))

2
cogs/zkill.py

@ -39,7 +39,6 @@ class Zkill(commands.Cog):
except aiohttp.client_exceptions.ContentTypeError:
await report.delete()
return
await self.bot.esi.esi.start_session()
km = await self.bot.esi.kill_lookup(
kill_id=killid, kill_hash=zkb[0]["zkb"]["hash"]
)
@ -129,7 +128,6 @@ class Zkill(commands.Cog):
text=f"killed {pendulum.parse(km['killmail_time']).diff_for_humans()}"
)
e.colour = Color.from_rgb(0, 0, 0) # make it black cuz why not
await self.bot.esi.esi.stop_session()
await report.edit(content=None, embed=e)
# if we dont suppress the original embed right away (before an embed exists maybe?)
# then it shouldnt get suck being present and has the added bonus of keeping the original

Loading…
Cancel
Save