from botstory.middlewares import any, location, option, sticker, text
import emoji
import logging

logger = logging.getLogger(__name__)


def setup(story):
    logger.info('[!] setup query stories [!]')

    @story.on(location.Any())
    def handle_location():
        @story.part()
        async def show_earth_of_location(ctx):
            logger.debug('# show earth of passed location')
            # TODO:
            # -
            await story.say(
                emoji.emojize('There will come GIBS!\n'
                              ':earth_americas::earth_africa::earth_asia:',
                              use_aliases=True),
                user=ctx['user'],
            )

@@ -63,16 +63,78 @@
 r, text%0A
+from botstory.ast.story_context import get_message_attachment%0A
 import e
@@ -196,74 +196,181 @@
 _)%0A%0A
-%0Adef setup(story):%0A    logger.info('%5B!%5D setup query stories %5B!%5D')%0A
+satellite_image = 'https://gibs.earthdata.nasa.gov/wmts/epsg4326/best/MODIS_Terra_CorrectedReflectance_TrueColor/default/2012-07-09/250m/%7Bz%7D/%7By%7D/%7Bx%7D.jpg'%0A%0A%0Adef setup(story):
 %0A   
@@ -568,31 +568,390 @@
     
-# TODO:%0A            # -
+location = get_message_attachment(ctx, 'location')%5B'payload'%5D%5B'coordinates'%5D%0A            # TODO: convert long, lat to MODIS tiles%0A            logger.debug(location)%0A            await story.send_image(%0A                satellite_image.format(%0A                    x=0,%0A                    y=0,%0A                    z=9,%0A                ),%0A                user=ctx%5B'user'%5D,%0A            )
 %0A   

return random satellite image