예제 #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}')
예제 #2
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}')
예제 #3
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}')
예제 #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')
예제 #5
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)
예제 #6
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)
예제 #7
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')
예제 #8
0
파일: checks.py 프로젝트: colcrunch/killbot
 async def predicate(ctx):
     if type(ctx.channel) is discord.DMChannel:
         return False
     if await ctx.bot.is_owner(ctx.author):
         return True
     elif ctx.author is ctx.guild.owner:
         return True
     sid = ctx.guild.id
     user = ctx.author.id
     admins = mc.get(f'{sid}_admin')
     return user in admins
예제 #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}')
예제 #10
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}')
예제 #11
0
 async def list_admin(self, ctx):
     """ Lists all bot admins in the current guild. """
     admins = mc.get(f'{ctx.guild.id}_admin')
     if len(admins) is 0 or admins is None:
         return await ctx.send('There are no admins set for this guild yet.'
                               )
     adminis = []
     for admin in admins:
         admini = discord.Guild.get_member(ctx.guild, user_id=admin)
         if admini.nick is None:
             name = admini.name
         else:
             name = admini.nick
         adminis.append(f'{name} ({admini.name}#{admini.discriminator})')
     admins = "\n".join(adminis)
     return await ctx.send(f'```\n' f'Admins: \n' f'{admins}' f'```')
예제 #12
0
    async def on_message(self, message):
        chid = message.channel.id
        if type(message.channel) is discord.TextChannel:
            ignore = mc.get(f'{message.guild.id}_dontListen')
        else:
            ignore = []
        if chid in ignore:
            print("test")
            return
        match = re.match(
            r'(.*)(http[s]?://([A-Za-z]*).[a-zA-z]*(/[a-zA-z]*/?)([0-9]*)[a-zA-Z/]?)',
            message.content)
        """
         Match Groups:
         Group 1 (match[1]): anything preceding the link.
         Group 2 (match[2]): The link in its entirety
         Group 3 (match[3]): The domain of the URL. This is how we determine if/how to process it.
         Group 4 (match[4]): Only used for zkill at the moment, to determine if the URL is a kill or not.
         Group 5 (match[5]): The ID we will need for processing. We know that all the services we want to process use 
                             only numeric IDs, so this is fine. (Though probably not the best if we wanted to add 
                             dscan.me support or something.
        """
        channel = message.channel
        global msg
        msg = message
        if match and (message.author != self.bot.user):
            if match[3] == 'evemarketer':
                typeid = match[5]
                item = sdeutils.type_name(typeid)
                info = await marketutils.get_price(typeid, None)
                content = f'{message.author.mention} shared {message.content}'

                embed = await marketutils.build(info, item, typeid, None)

                if match[1] is not '':
                    return await channel.send(embed=embed)
                else:
                    if commands.bot_has_permissions(manage_messages=True):
                        await channel.purge(check=self.passed)

                    return await channel.send(content=content, embed=embed)
            elif match[3] == 'zkillboard':
                if match[4] == '/kill/':
                    killid = match[5]
                    km = await kbutils.get_mail(killid)
                    content = f'{message.author.mention} shared {message.content}'

                    vic = km['victim']
                    if 'character_id' not in vic:
                        vicChar = None
                    else:
                        vicChar = await esiutils.esi_char(vic['character_id'])
                    vicShip = sdeutils.type_name(vic['ship_type_id'])
                    vicCorp = await esiutils.esi_corp(vic['corporation_id'])
                    if 'alliance_id' in vic:
                        vicAlly = await esiutils.esi_ally(vic['alliance_id'])
                    else:
                        vicAlly = None
                    vicDam = '{:,}'.format(vic['damage_taken'])
                    loc = sdeutils.system_name(km['location'])
                    for attacker in km['attackers']:
                        if attacker['final_blow'] is True:
                            if 'character_id' in attacker:
                                attChar = await esiutils.esi_char(
                                    attacker['character_id'])
                            else:
                                attChar = None
                            attCorp = await esiutils.esi_corp(
                                attacker['corporation_id'])
                            if 'alliance_id' in attacker:
                                attAlly = await esiutils.esi_ally(
                                    attacker['alliance_id'])
                            else:
                                attAlly = None
                            # noinspection PyUnusedLocal
                            attShip = sdeutils.type_name(
                                attacker['ship_type_id'])

                    # noinspection PyUnboundLocalVariable,PyUnboundLocalVariable,PyUnboundLocalVariable
                    dict_km = {
                        'vicChar': vicChar,
                        'vicShip': vicShip,
                        'vicCorp': vicCorp,
                        'vicAlly': vicAlly,
                        'vicDam': vicDam,
                        'time': km['time'],
                        'vicST': vic['ship_type_id'],
                        'attChar': attChar,
                        'attCorp': attCorp,
                        'attAlly': attAlly,
                        'value': km['value'],
                        'loc': loc,
                        'kid': killid
                    }

                    embed = await kbutils.build_kill(dict_km, 'api')

                    if match[1] is not '':
                        return await channel.send(embed=embed)
                    else:
                        if commands.bot_has_permissions(manage_messages=True):
                            await channel.purge(check=self.passed)

                        return await channel.send(content=content, embed=embed)
                elif match[4] == '/character/':
                    cid = match[5]
                    char = await esiutils.esi_char(cid)

                    stats = await kbutils.get_stats(cid)

                    if all(value is None for value in stats.values()):
                        if 'extensions.EsiCommands' in self.bot.extensions:
                            return await channel.send(
                                f'This character has no killboard stats. Please use the `{config.prefix}char '
                                f'command` to display information on this character.'
                            )
                        else:
                            return await channel.send(
                                'This character has no killboard stats.')

                    embed = await kbutils.build_threat(stats, char, cid)

                    return await channel.send(embed=embed)

        else:
            return