Example #1
0
async def esi_char(eid):
    if mc.get(f'{eid}') is None:
        url = f'https://esi.evetech.net/v4/characters/{eid}/?datasource=tranquility'
        async with aiohttp.ClientSession() as session:
            respo = await get(session, url)
        resp = respo['resp']
        corpID = resp['corporation_id']
        dob = datetime.datetime.strptime(resp['birthday'], '%Y-%m-%dT%H:%M:%SZ')
        now = datetime.datetime.utcnow()
        age = now - dob
        name = resp['name']
        gender = resp['gender']
        sec = resp['security_status']

        inf = {'corpid': corpID,
               'dob': dob,
               'age': age,
               'name': name,
               'gender': gender,
               'sec': sec}
        mc.set(f'{eid}', inf, respo['exp'].seconds)
        return inf
    else:
        print(f'Getting char info for {eid} from cache.')
        return mc.get(f'{eid}')
Example #2
0
    async def process_item(self, ctx, item, region):
        region_id = sdeutils.region_id(region)
        item_id = sdeutils.type_id(item)

        if region_id is None:
            region_id = await esiutils.get_id(region, 'region')
            if region_id is None:
                return await ctx.send('Region not found.')
        if item_id is None:
            item_id = await esiutils.get_id(item, 'itype')
            if item_id is None:
                return await ctx.send('Item not found.')
            else:
                # If we have to hit ESI for a type_id, this means that the SDE that is currently in use is likely old.
                if mc.get('sde_update_notice') is None:
                    self.logger.warning(
                        "It appears that the SDE may be out of date. Please run the launcher update"
                        " command")
                    appinf = await self.bot.application_info()
                    owner = self.bot.get_user(appinf.owner.id)
                    await owner.send(
                        "It appears the SDE is out of date, please run `python3 launcher.py update` and "
                        "restart the bot.")
                    # Notifications should only happen once a day.
                    mc.set('sde_update_notice', True, 86400)

                item = await esiutils.esi_type(item_id)
        else:
            item = sdeutils.type_name(item_id)

        info = await market.get_price(item_id, region_id)

        embed = await market.build(info, item, item_id, region)

        return await ctx.send(embed=embed)
Example #3
0
async def get_id(name, ref):
    key_name = name.replace(' ', '+')
    if mc.get(f'{ref}_{key_name}') is None:
        # noinspection PyUnresolvedReferences
        urlName = urllib.parse.quote_plus(name)
        defs = {'ally': 'alliance',
                'corp': 'corporation',
                'char': 'character',
                'itype': 'inventory_type',
                'solsystem': 'solar_system',
                'region': 'region',
                'faction': 'faction',
                'agent': 'agent',
                'con': 'constellation',
                'station': 'station'}
        url = f'https://esi.evetech.net/v2/search/?categories={defs[ref]}&datasource=tranquility&search={urlName}' \
              f'&strict=true'

        async with aiohttp.ClientSession() as session:
            respo = await get(session, url)
        resp = respo['resp']
        exp = respo['exp']
        if defs[ref] in resp:
            eid = str(resp[defs[ref]][0])
        else:
            eid = None
        mc.set(f'{ref}_{key_name}', f'{eid}', exp.seconds)
        return eid
    else:
        print(f'Getting id for {name} from cache.')
        return mc.get(f'{ref}_{key_name}')
Example #4
0
async def esi_sysJumps():
    if mc.get('sysJumps') is None:
        url = 'https://esi.evetech.net/v1/universe/system_jumps/'
        async with aiohttp.ClientSession() as session:
            respo = await get(session, url)
        resp = respo['resp']
        exp = respo['exp']
        mc.set('sysJumps', resp, exp.seconds)
        return resp
    else:
        print("Getting system jump information from cache.")
        return mc.get('sysJumps')
Example #5
0
async def esi_type(eid):
    ed = f'{eid}'
    if mc.get(ed) is None:
        url = f'http://esi.evetech.net/v3/universe/types/{eid}/?datasource=tranquility'
        async with aiohttp.ClientSession() as session:
            respo = await core.get_esi(session, url)
        resp = respo['resp']
        exp = respo['exp']
        if 'name' in resp:
            name = resp['name']
        else:
            name = None
        mc.set(ed, name, exp.seconds)
        return name
    else:
        print(f'Getting type info for {ed} from cache.')
        return mc.get(ed)
Example #6
0
async def esi_status():
    if mc.get('status') is None:
        url = "https://esi.evetech.net/latest/status/?datasource=tranquility"
        async with aiohttp.ClientSession() as session:
            respo = await get(session, url)
        if respo['code'] is not 200:
            return None
        resp = respo['resp']
        exp = respo['exp']
        print(exp)
        if 'players' in resp:
            mc.set('status', resp['players'], exp.seconds)
            return resp['players']
        else:
            return None
    else:
        print('Getting status from cache')
        return mc.get('status')
Example #7
0
async def esi_system(eid):
    if mc.get(f'{eid}') is None:
        url = f'https://esi.evetech.net/v3/universe/systems/{eid}/?datasource=tranquility'
        async with aiohttp.ClientSession() as session:
            respo = await get(session, url)
        resp = respo['resp']
        exp = respo['exp']

        name = resp['name']
        star = resp['star_id']
        sec = round(resp['security_status'], 2)
        constellation = resp['constellation_id']
        planets = len(resp['planets'])
        listlen = []
        for planet in resp['planets']:
            if 'moons' in planet:
                listlen.append(len(planet['moons']))

        moons = sum(listlen)
        secClass = resp['security_class']
        gates = len(resp['stargates'])
        if 'stations' in resp:
            stations = len(resp['stations'])
        else:
            stations = None

        inf = {'name': name,
               'star': star,
               'sec': sec,
               'secClass': secClass,
               'const': constellation,
               'planets': planets,
               'moons': moons,
               'gates': gates,
               'stations': stations}
        mc.set(f'{eid}', inf, exp.seconds)
        return inf
    else:
        print(f"Getting system information for {eid} from cache.")
        return mc.get(f'{eid}')
Example #8
0
async def esi_ally(eid):
    if mc.get(f'{eid}') is None:
        url = f'https://esi.evetech.net/v3/alliances/{eid}/?datasource=tranquility'
        async with aiohttp.ClientSession() as session:
            respo = await get(session, url)
        resp = respo['resp']
        exp = respo['exp']
        name = resp['name']
        founder = resp['creator_id']
        create_corp = resp['creator_corporation_id']
        ticker = resp['ticker']
        founded = datetime.datetime.strptime(resp['date_founded'], '%Y-%m-%dT%H:%M:%SZ')
        exec_corp = resp['executor_corporation_id']

        inf = {
            'name': name,
            'founder': founder,
            'create_corp': create_corp,
            'ticker': ticker,
            'founded': founded,
            'exec': exec_corp
        }
        mc.set(f'{eid}', inf, exp.seconds)
        mc.set(f'ally_{ticker}', eid, exp.seconds)
        name = name.replace(' ','')
        mc.set(f'ally_{name}', eid, exp.seconds)
        return inf
    else:
        print(f'Getting alliance info for {eid} from cache.')
        return mc.get(f'{eid}')
Example #9
0
async def esi_corp(eid):
    if mc.get(f'{eid}') is None:
        url = f'https://esi.evetech.net/v4/corporations/{eid}/?datasource=tranquility'
        async with aiohttp.ClientSession() as session:
            respo = await get(session, url)
        resp = respo['resp']
        exp = respo['exp']
        name = resp['name']
        ticker = resp['ticker']
        member = resp['member_count']
        ceoid = resp['ceo_id']
        if 'alliance_id' in resp:
            ally = resp['alliance_id']
        else:
            ally = None
        if 'date_founded' in resp:
            dob = datetime.datetime.strptime(resp['date_founded'], '%Y-%m-%dT%H:%M:%SZ')
        else:
            dob = None
        if 'url' not in resp or resp['url'] == 'http://' or resp['url'] == '' or resp['url'] == 'https://':
            url = None
        else:
            url = resp['url']

        inf = {'name': name,
               'ticker': ticker,
               'member': member,
               'ceoid': ceoid,
               'dob': dob,
               'url': url,
               'ally': ally}
        mc.set(f'{eid}', inf, exp.seconds)
        sanitized_ticker = ticker.replace(" ", "+")
        mc.set(f'corp_{sanitized_ticker}', eid, exp.seconds)
        name = name.replace(' ','')
        mc.set(f'corp_{name}', eid, exp.seconds)
        return inf
    else:
        print(f'Getting corp info for {eid} from cache.')
        return mc.get(f'{eid}')