def get_response_rocket_did_launch(mid):
    return [
        lyr.Text(get_url_rocket_frame(mid)),
        lyr.Text(t.LAUNCH),
        tll.InlineKeyboard([[
            tll.InlineKeyboardCallbackButton(
                text=t.YES_LAUNCH,
                payload={
                    'action': 'choose_option_player',
                    'current': mid,
                    'option': 'yes'
                },
            )
        ],
                            [
                                tll.InlineKeyboardCallbackButton(
                                    text=t.NO_LAUNCH,
                                    payload={
                                        'action': 'choose_option_player',
                                        'current': mid,
                                        'option': 'no'
                                    },
                                )
                            ]])
    ]
Example #2
0
    async def handle(self, context) -> None:
        
        bisector = FrameXBisector(settings.VIDEO_NAME)
        limit_left = 0
        limit_right = bisector.count
        current_frame = int((limit_left + limit_right) / 2)
        context.update({
            'current_frame': current_frame,
            'limit_left': limit_left,
            'limit_right': limit_right
        })

        image_url = urljoin(settings.BASE_VIDEO_API_URL,
                    f'video/{quote(settings.VIDEO_NAME)}/frame/{quote(f"{current_frame}")}/')
        self.send(
            lyr.Markdown(t('DID_ROCKET_LAUNCH', frame_number=current_frame, image_url=image_url)),
            tgr.InlineKeyboard([
                [tgr.InlineKeyboardCallbackButton(
                    text='Yes',
                    payload={'decreaseFrame': True}
                )],
                [tgr.InlineKeyboardCallbackButton(
                    text='No',
                    payload={'decreaseFrame': False}
                )]
            ]),
        )
Example #3
0
 async def handle(self) -> None:
     self.send(
         lyr.Text(t.CONGRATULATIONS), lyr.Text('Wanna play again?'),
         tll.InlineKeyboard([[
             tll.InlineKeyboardCallbackButton(
                 text=t.LETS_PLAY,
                 payload={'action': 'again'},
             )
         ]]))
Example #4
0
    async def handle(self) -> None:
        name = await self.request.user.get_friendly_name()

        self.send(
            lyr.Text(t('WELCOME', name=name)),
            tlg.InlineKeyboard([[
                tlg.InlineKeyboardCallbackButton(t.YES, payload='yes'),
                tlg.InlineKeyboardCallbackButton(t.NO, payload='no'),
            ]]),
        )
Example #5
0
    async def handle(self, context) -> None:

        try:
            payload = self.request.get_layer(lyr.Postback).payload
        except KeyError:
            self.send(lyr.Text(t('VIDEO_ERROR')), )
            return
        else:
            frame_number = context.get('frame_number')
            print('Frame_number:', frame_number)
            option = payload.get('option', 'launched')
            print("Option:", option)

        name = await self.request.user.get_friendly_name()
        # left_index = context.get('left_index')
        # right_index = context.get('right_index')

        # Changing the indexes for the new bisection
        # When the rocket launched
        if option == 'launched':
            print('Launched')
            context['right_index'] = frame_number
            context['left_index'], context[
                'right_index'], new_frame_number = bisect(
                    context.get('left_index'), context.get('right_index'))
            context['frame_number'] = new_frame_number
        # When the rocket  not launched
        else:
            print('Not launched')
            context['left_index'] = frame_number
            context['left_index'], context[
                'right_index'], new_frame_number = bisect(
                    context.get('left_index'), context.get('right_index'))
            context['frame_number'] = new_frame_number

        self.send(
            lyr.Text(t('GUESS', name=name)),
            lyr.Text(get_frame_url(frame_number=new_frame_number)),
            tl.InlineKeyboard([[
                tl.InlineKeyboardCallbackButton(text=t.LAUNCHED,
                                                payload={
                                                    'action': 'choose_option',
                                                    'option': 'launched'
                                                })
            ],
                               [
                                   tl.InlineKeyboardCallbackButton(
                                       text=t.NOT_LAUNCHED,
                                       payload={
                                           'action': 'choose_option',
                                           'option': 'not_launched'
                                       })
                               ]]))
Example #6
0
    async def handle(self) -> None:
        name = await self.request.user.get_friendly_name()

        self.send(
            lyr.Text(t('WELCOME', name=name)),
            tl.InlineKeyboard([[
                tl.InlineKeyboardCallbackButton(text=t.START_PLAY,
                                                payload={'action': 'start'})
            ],
                               [
                                   tl.InlineKeyboardCallbackButton(
                                       text=t.QUIT_PLAY,
                                       payload={'action': 'no_start'})
                               ]]))
Example #7
0
 async def handle(self, context) -> None:
     # name = await self.request.user.get_friendly_name()
     frame_number = context.get('frame_number')
     self.send(
         lyr.Text(t('FINISH', frame_number=frame_number)),
         tl.InlineKeyboard([[
             tl.InlineKeyboardCallbackButton(text=t.PLAY_AGAIN,
                                             payload={'action': 'restart'})
         ],
                            [
                                tl.InlineKeyboardCallbackButton(
                                    text=t.QUIT_PLAY,
                                    payload={'action': 'no_restart'})
                            ]]))
    async def handle(self) -> None:
        name = await self.request.user.get_friendly_name()

        self.send(
            lyr.Text(t('WELCOME', name=name)),
            tll.InlineKeyboard([[
                tll.InlineKeyboardCallbackButton(
                    text=t.YES_START,
                    payload={'action': 'play'},
                )
            ],
                                [
                                    tll.InlineKeyboardCallbackButton(
                                        text=t.NO_START,
                                        payload={'action': 'no_play'},
                                    )
                                ]]))
Example #9
0
    async def handle(self) -> None:
        name = await self.request.user.get_friendly_name()

        self.send(
            lyr.Text('Play?'),
            tll.InlineKeyboard([[
                tll.InlineKeyboardCallbackButton(
                    text=t.LETS_PLAY,
                    payload={'action': 'play'},
                )
            ]]),
            lyr.Image(UrlMedia('https://domain/image.jpg'))
            # tll.AnswerInlineQuery(
            #     results=[1, 2, 3],
            #     cache_time=0,
            #     is_personal=True,
            # )
        )
Example #10
0
def test_markdown():
    pattern = ('^Markdown+ '
               '(InlineKeyboard|ReplyKeyboard|ReplyKeyboardRemove)? '
               'Reply?$'
               '|^Markdown InlineKeyboard? Reply? Update$')

    ce = ClassExp(pattern)

    assert repr(ce._compiled_expression) == \
        "re.compile('^(?:Markdown,)+((?:InlineKeyboard,)|(?:ReplyKeyboard,)|" \
        "(?:ReplyKeyboardRemove,))?(?:Reply,)?$" \
        "|^(?:Markdown,)(?:InlineKeyboard,)?(?:Reply,)?(?:Update,)$')"

    assert ce.match([
        lyr.Markdown(''),
        tgr.InlineKeyboard([]),
        tgr.Reply(),
        tgr.Update(),
    ])
Example #11
0
    async def handle(self, context):
        frame_ctx = FrameContext(context)

        if self.trigger.get('bisect'):
            frame_ctx.bisect(self.trigger.rocket_launched)

        url = frame_ctx.get_image_url()

        cancel_kb = tgr.InlineKeyboard([
            [
                tgr.InlineKeyboardCallbackButton(
                    text='Stop search',
                    payload={'action': 'cancel'},
                )
            ],
        ])

        self.send(lyr.Text(url), WadridState.reply_keyboard())
        self.send(lyr.Text(t.FRAME), cancel_kb)
 async def handle(self, context) -> None:
     self.send(
         lyr.Text(t('WIN', now_guess=str(datetime.now()))),
         lyr.Text(t.PLAY_AGAIN),
         tll.InlineKeyboard([[
             tll.InlineKeyboardCallbackButton(
                 text=t.YES_LAUNCH,
                 payload={
                     'action': 'play',
                 },
             )
         ],
                             [
                                 tll.InlineKeyboardCallbackButton(
                                     text=t.NO_LAUNCH,
                                     payload={
                                         'action': 'no_play',
                                     },
                                 )
                             ]]))
Example #13
0
 async def handle(self, context) -> None:
     # Update the frame
     current_frame = int((context.get('limit_left') + context.get('limit_right')) / 2)
     context['current_frame'] = current_frame
     
     image_url = urljoin(settings.BASE_VIDEO_API_URL,
                 f'video/{quote(settings.VIDEO_NAME)}/frame/{quote(f"{current_frame}")}/')
     
     self.send(
         lyr.Markdown(t('DID_ROCKET_LAUNCH', frame_number=current_frame, image_url=image_url)),
         tgr.InlineKeyboard([
             [tgr.InlineKeyboardCallbackButton(
                 text='Yes',
                 payload={'decreaseFrame': True}
             )],
             [tgr.InlineKeyboardCallbackButton(
                 text='No',
                 payload={'decreaseFrame': False}
             )]
         ]),
     )
Example #14
0
    def ask_question(self, middle) -> None:
        """
        Parameters:
            middle(int): Frame we are currently analyzing

        This function is a module used when asking the user
        if the rocket has launched yet or not.
        Used in states S002 and S003.

        Shows the frame first and asks the question afterwards,
        giving two button options to answer either yes or no.
        """
        url = settings.API_URL.format(middle)
        self.send(lyr.Text(t('URL', url=url)))
        self.send(
            lyr.Text(t('DID_IT_LAUNCH', middle=middle)),
            tlg.InlineKeyboard([[
                tlg.InlineKeyboardCallbackButton(t.YES, payload='yes'),
                tlg.InlineKeyboardCallbackButton(t.NO, payload='no'),
            ]]),
        )
Example #15
0
    async def handle(self, context) -> None:
        name = await self.request.user.get_friendly_name()
        # Get information about the images from the video
        frames = get_video_information()

        if frames:
            # Set context of indexes and frames for the video
            context['left_index'] = 0
            context['right_index'] = frames - 1
            # Get the new frame to show using the bisection method
            context['left_index'], context[
                'right_index'], frame_number = bisect(
                    int(context.get('left_index')),
                    int(context.get('right_index')))
            print("Frame number:", frame_number)
            context['frame_number'] = frame_number

            self.send(
                lyr.Text(t('GUESS', name=name)),
                lyr.Text(get_frame_url(frame_number=frame_number)),
                tl.InlineKeyboard([[
                    tl.InlineKeyboardCallbackButton(text=t.LAUNCHED,
                                                    payload={
                                                        'action':
                                                        'choose_option',
                                                        'option': 'launched'
                                                    })
                ],
                                   [
                                       tl.InlineKeyboardCallbackButton(
                                           text=t.NOT_LAUNCHED,
                                           payload={
                                               'action': 'choose_option',
                                               'option': 'not_launched'
                                           })
                                   ]]))
        else:
            self.send(lyr.Text(t('VIDEO_ERROR')), )