MoritzHayden / drg-api

DRG API is a free API which returns Deep Rock Galactic information and resources.
https://drgapi.com
MIT License
18 stars 3 forks source link

New Endpoint: Current Mission Data #10

Open chrislowcher opened 11 months ago

chrislowcher commented 11 months ago

Really glad I stumbled upon this project, I have been hoping to find a DRG api for some time now.

Would be awesome to get an endpoint that returned the current active missions along with the mission modifiers, biome, etc. Not sure if there is something similar to the official GSG deepdive endpoint as I don't know much about it.

Is it possible to do something similar to how to deep dive data is pulled? Obviously it is much more frequent as the missions change every 30 mins.

MoritzHayden commented 11 months ago

I'm glad you're getting some use out of it! Thank you for your suggestion.

We could probably take advantage of @rolfosian's drgmissions mission data endpoint for this. Since the missions cycle every 30 minutes, it probably wouldn't make sense to cache the result in a JSON file like we're doing for the deep dives. Instead, we could simply call the drgmissions service and have Bosco return the result in a prettified embed.

rolfosian commented 11 months ago

I started on something like this for a discord bot to go with drgmissions a few weeks ago but lost interest and didn't continue as the website already exists and I think the homepage with the mission icons at https://doublexp.net/ does a better job to show everything than a bot could in any case. Here's what I had anyway without the config and the discord event decorators/30 min scheduler in case you're interested:

def fetch_missions_metadata(domain_url):    
    mission_data = requests.get(f'{domain_url}json?data=current').content
    mission_data = json.loads(mission_data)

    Biomes = {}
    for biome, missions in mission_data['Biomes'].items():
        Biomes[biome] = []
        for mission in missions:
            mission['icon_url'] = f'{domain_url}/png?img={biome.replace(" ", "-")}{str(mission["id"])}'
            Biomes[biome].append(mission)

    return Biomes

def create_mission_embed(biome, mission):
    embed = discord.Embed(title=biome, color=discord.Color.blue())
    embed.set_image(url=mission['icon_url'])
    return embed

def array_mission_embeds(Biomes):
    Biomes_Embeds = {}

    for biome, missions in Biomes.items():
        Biomes_Embeds[biome] = []
        for mission in missions:
            mission_embed = create_mission_embed(biome, mission['icon_url'])
            Biomes_Embeds[biome].append(mission_embed)

    return Biomes_Embeds

domain_url = 'https://doublexp.net/'
Biomes = fetch_missions_metadata(domain_url)
Biomes_Embeds = array_mission_embeds(Biomes)

async def send_to_channel(channel_id, Biomes_Embeds):
    pass
async def send_missions_icons(channels):
    coroutines = [send_to_channel(channel) for channel in channels]
    await asyncio.gather(*coroutines)
    pass