Пример #1
0
 async def handle(self, context) -> None:
     current_frame = context.get('current_frame')
     self.send(
         lyr.Text(t('FOUND', frame_number=current_frame)),
         lyr.Text(t.DO_YOU_WANT_AGAIN),
         
     )
Пример #2
0
def test_flush():
    args = []
    kwargs = {}

    async def do_flush(*a, **k):
        args.extend(a)
        kwargs.update(k)

    mm = MiddlewareManager.instance()
    mm.middlewares = [AutoSleep]

    flush = mm.get('flush', do_flush)
    run(flush(None, [lyr.Stack([lyr.Text('hello'), lyr.Text('wassup')])]))

    assert args == [
        None,
        [
            lyr.Stack([
                lyr.RawText('hello'),
            ]),
            lyr.Stack([
                lyr.Sleep(0.7),
            ]),
            lyr.Stack([
                lyr.RawText('wassup'),
            ]),
        ]
    ]

    assert kwargs == {}
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'
                                    },
                                )
                            ]])
    ]
Пример #4
0
def test_match_layer():
    s = make_stack(
        layers.Text('yolo'),
        layers.Text('pouet'),
        fbl.QuickRepliesList([]),
    )

    s.match_exp('(Text|RawText)+ QuickRepliesList?')
Пример #5
0
    async def handle(self, context):
        text = lyr.Text(t.CONTINUE)

        if not context.get('started'):
            text = lyr.Text(t.BEGIN)
            FrameContext(context).configure_context()
            context['started'] = True

        self.send(text, WadridState.reply_keyboard())
Пример #6
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'},
             )
         ]]))
Пример #7
0
    async def handle(self, context) -> None:
        user_number = self.trigger.user_number

        self.send(lyr.Text("WRONG"))

        if user_number < context['number']:
            self.send(lyr.Text("HIGHER"))
        else:
            self.send(lyr.Text("LOWER"))
Пример #8
0
 async def handle(self):
     self.send(lyr.Text(t.HELLO))
     self.send(
         lyr.Text(t.HOW_ARE_YOU),
         lyr.QuickRepliesList([
             lyr.QuickRepliesList.TextOption('yes', t.YES, intents.YES),
             lyr.QuickRepliesList.TextOption('no', t.NO, intents.NO),
         ]),
     )
Пример #9
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'
                                       })
                               ]]))
Пример #10
0
    async def handle(self, context):
        name = await self.request.user.get_friendly_name()
        text = lyr.Text(t('WELCOME', name=name))

        if self.trigger.get('loop'):
            text = lyr.Text(t.LOOP)
        else:
            await FrameContext(context).init_context()

        context['started'] = False

        self.send(text, WadridState.reply_keyboard())
Пример #11
0
    async def error(self) -> None:
        """
        This happens when something goes wrong (it's the equivalent of the
        HTTP error 500).
        """

        self.send(layers.Text(translate.ERROR))
Пример #12
0
    async def error(self) -> None:
        """
        This happens when something goes wrong (it"s the equivalent of the
        HTTP error 500).
        """

        self.send(lyr.Text(t.ERROR))
Пример #13
0
 async def handle(self, context) -> None:
     # current_value = context.get('n')
     # url = frame_url(current_value)
     # answers = context['answers']
     self.send(
         lyr.Text("Has the rocket launched? (%s) " %
                  (str(context['list']))))
Пример #14
0
    async def confused(self) -> None:
        """
        This is called when the user sends a message that triggers no
        transitions.
        """

        self.send(lyr.Text(t.CONFUSED))
Пример #15
0
    async def handle(self, context):
        frame_ctx = FrameContext(context)
        current_frame = frame_ctx.get_current_frame()

        frame_ctx.configure_context()

        self.send(lyr.Text(t('FOUND', frame=current_frame)),
                  WadridState.reply_keyboard())
Пример #16
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'),
            ]]),
        )
Пример #17
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)
Пример #18
0
 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',
                                     },
                                 )
                             ]]))
Пример #19
0
    def get_layers(self):
        out = [
            l.Text(self.text),
        ]

        if self.add_qr:
            out += [
                fbl.QuickReply('foo'),
            ]

        return out
Пример #20
0
 async def handle(self) -> None:
     self.send(
         lyr.Text(t.CONGRATULATIONS),
         fbl.QuickRepliesList([
             fbl.QuickRepliesList.TextOption(
                 slug='again',
                 text=t.PLAY_AGAIN,
                 intent=its.PLAY_AGAIN,
             ),
         ]),
     )
Пример #21
0
    async def handle(self):
        name = await self.request.user.get_friendly_name()

        self.send(
            lyr.Text(t("WELCOME", name=name)),
            ReplyKeyboard(
                keyboard=[
                    [KeyboardButton(t.START)],
                ]
            )
        )
Пример #22
0
    async def handle(self, context) -> None:
        response = await get_video_info()

        if response:
            context['count'] = 0
            context['size'] = response.get('frames', 0)
            context['left'], context['right'], mid = bisect(
                0, context['size'] - 1)

            self.send(*get_response_rocket_did_launch(mid))
        else:
            self.send(lyr.Text(t.ERROR))
Пример #23
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'),
            ]]),
        )
Пример #24
0
def test_story_hello():
    with patch_conf(settings_file=ENGINE_SETTINGS_FILE):
        _, platform = make_test_fsm()

        platform.handle(l.Text('Hello!'), )
        platform.assert_state(HowAreYou)
        platform.assert_sent(
            stack(l.Text(t.HELLO)),
            stack(
                l.Text(t.HOW_ARE_YOU),
                fbl.QuickRepliesList([
                    fbl.QuickRepliesList.TextOption('yes', t.YES, intents.YES),
                    fbl.QuickRepliesList.TextOption('no', t.NO, intents.NO),
                ])),
        )

        platform.handle(
            l.Text('Yes'),
            fbl.QuickReply('yes'),
        )
        platform.assert_sent(stack(l.Text(t.GREAT)))
Пример #25
0
    async def handle(self) -> None:
        name = await self.request.user.get_friendly_name()

        self.send(
            lyr.Text(t('WELCOME', name=name)),
            fbl.QuickRepliesList([
                fbl.QuickRepliesList.TextOption(
                    slug='play',
                    text=t.LETS_PLAY,
                    intent=its.LETS_PLAY,
                ),
            ]),
        )
Пример #26
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')), )
Пример #27
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'})
                               ]]))
Пример #28
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'})
                            ]]))
Пример #29
0
def test_stack():
    l1 = layers.Text('hello')
    l2 = layers.Text('sup?')
    l3 = fbl.QuickRepliesList([
        fbl.QuickRepliesList.TextOption('foo', 'Foo'),
        fbl.QuickRepliesList.TextOption('bar', 'Bar', intents.BAR),
        fbl.QuickRepliesList.LocationOption(),
    ])

    stack = layers.Stack([l1])

    assert stack.has_layer(layers.Text)
    assert not stack.has_layer(fbl.QuickRepliesList)
    assert stack.get_layer(layers.Text) == l1

    with pytest.raises(KeyError):
        assert stack.get_layer(fbl.QuickRepliesList) is None

    stack.layers = [l1, l2, l3]

    assert stack.has_layer(fbl.QuickRepliesList)
    assert stack.get_layer(layers.Text) == l1
    assert stack.get_layers(layers.Text) == [l1, l2]
    assert stack.get_layer(fbl.QuickRepliesList) == l3
Пример #30
0
    async def handle(self) -> None:
        name = await self.request.user.get_friendly_name()

        keyboardButtons = [
            telegram_layers.KeyboardButton(text=translate.YES,
                                           choice='yes',
                                           intent=intents.LETS_PLAY),
            telegram_layers.KeyboardButton(text=translate.NO,
                                           choice='no',
                                           intent=intents.LETS_NOT_PLAY)
        ]

        self.send(
            layers.Text(translate('WELCOME', name=name)),
            telegram_layers.ReplyKeyboard(keyboard=[keyboardButtons],
                                          one_time_keyboard=True))