コード例 #1
0
 def test_first_button(self):
     g = gadget('Press your buttons').first_button(timeout=5000)
     self.assertEqual(g._response['outputSpeech']['text'], 'Press your buttons')
     self.assertEqual(g._response['shouldEndSession'], False)
     self.assertEqual(len(g._response['directives']), 1)
     directive = g._response['directives'][0]
     self.assertEqual(directive['type'], 'GameEngine.StartInputHandler')
     self.assertEqual(directive['timeout'], 5000)
     self.assertEqual(directive['proxies'], [])
     recognizers = {
         'button_down_recognizer': {
             'type': 'match',
             'fuzzy': False,
             'anchor': 'end',
             'pattern': [{'action': 'down'}]
         }
     }
     events = {
         'timeout': {
             'meets': ['timed out'],
             'reports': 'nothing',
             'shouldEndInputHandler': True
         },
         'button_down_event': {
             'meets': ['button_down_recognizer'],
             'reports': 'matches',
             'shouldEndInputHandler': True
         }
     }
     self.assertEqual(directive['recognizers'], recognizers)
     self.assertEqual(directive['events'], events)
コード例 #2
0
def start_roll_call():
    """Identifies all Echo Buttons that are present."""
    speech = 'Players, press your buttons now.'
    prompt = "I'm still waiting for you to press your buttons."
    session.attributes['players'] = []
    session.attributes['activity'] = 'roll call'
    return gadget(speech).reprompt(prompt).roll_call(
        timeout=10000, max_buttons=session.attributes['max_players'])
コード例 #3
0
 def test_start_input_handler(self):
     g = gadget('foo')._start_input_handler(timeout=5000)
     self.assertEqual(g._response['outputSpeech'], {'type': 'PlainText', 'text': 'foo'})
     self.assertEqual(g._response['shouldEndSession'], False)
     self.assertEqual(g._response['directives'][0]['type'], 'GameEngine.StartInputHandler')
     self.assertEqual(g._response['directives'][0]['timeout'], 5000)
     self.assertEqual(g._response['directives'][0]['proxies'], [])
     self.assertEqual(g._response['directives'][0]['recognizers'], {})
     self.assertEqual(g._response['directives'][0]['events'], {})
コード例 #4
0
def start_round():
    """Prompts all users to press their buttons and responds to the first one."""
    if not session.attributes['players']:
        return question(
            "I don't see any players yet.  Start the roll call first.")
    session.attributes['activity'] = 'new round'
    return gadget('Press your button to buzz in.').first_button(
        timeout=8000,
        gadget_ids=[p['gid'] for p in session.attributes['players']],
        animations=[animation(repeat=4).crossfade(duration=200).off()])
コード例 #5
0
 def buzz_in(input_event):
     """Acknowledges the first button that was pressed with speech and a 'breathing' animation."""
     gid = input_event['gadgetId']
     try:
         pid = [p['pid'] for p in session.attributes['players'] if p['gid'] == gid][0]
     except LookupError:
         return question("I couldn't find the player associated with that button.")
     return gadget("Player {}, you buzzed in first.".format(pid)).set_light(
         targets=[gid],
         animations=[animation(repeat=3).breathe(duration=500, color='00FF00')]
     )
コード例 #6
0
 def register_player(event_name, input_event):
     """Adds a player's button to the list of known buttons and makes the button pulse yellow."""
     if input_event['action'] == 'down':
         button_number = event_name[-1]
         gid = input_event['gadgetId']
         session.attributes['players'].append({'pid': button_number, 'gid': gid})
         speech = ""
         if event_name.endswith('2'):
             session.attributes['activity'] = 'roll call complete'
             speech = 'I found {} buttons. Ready to start the round?'.format(2)
         return gadget(speech).set_light(
             targets=[gid],
             animations=[animation().on(color='FFFF00')]
         )
コード例 #7
0
 def test_roll_call(self):
     g = gadget('Starting roll call').roll_call(timeout=10000, max_buttons=2)
     self.assertEqual(g._response['outputSpeech']['text'], 'Starting roll call')
     self.assertEqual(g._response['shouldEndSession'], False)
     self.assertEqual(len(g._response['directives']), 1)
     directive = g._response['directives'][0]
     self.assertEqual(directive['type'], 'GameEngine.StartInputHandler')
     self.assertEqual(directive['timeout'], 10000)
     self.assertEqual(directive['proxies'], ['btn1', 'btn2'])
     recognizers = {
         'roll_call_recognizer_btn1': {
             'type': 'match',
             'fuzzy': True,
             'anchor': 'end',
             'pattern': [{'gadgetIds': ['btn1'], 'action': 'down'}]
         },
         'roll_call_recognizer_btn2': {
             'type': 'match',
             'fuzzy': True,
             'anchor': 'end',
             'pattern': [{'gadgetIds': ['btn2'], 'action': 'down'}]
         }
     }
     self.assertEqual(directive['recognizers'], recognizers)
     events = {
         'roll_call_event_btn1': {
             'meets': ['roll_call_recognizer_btn1'],
             'reports': 'matches',
             'shouldEndInputHandler': False,
             'maximumInvocations': 1
         },
         'roll_call_event_btn2': {
             'meets': ['roll_call_recognizer_btn2'],
             'reports': 'matches',
             'shouldEndInputHandler': True,
             'maximumInvocations': 1
         },
         'timeout': {
             'meets': ['timed out'],
             'reports': 'history',
             'shouldEndInputHandler': True
         }
     }
     self.assertEqual(directive['events'], events)
コード例 #8
0
def set_color(button='1', color='red'):
    colors = {
        'white': 'FFFFFF',
        'red': 'FF0000',
        'orange': 'FF3300',
        'yellow': 'FFD400',
        'green': '00FF00',
        'blue': '0000FF',
        'purple': '4B0098',
        'black': '000000'
    }
    hex = colors.get(color, 'FFFFFF')
    try:
        gid = [
            p['gid'] for p in session.attributes['players']
            if p['pid'] == button
        ][0]
    except LookupError:
        return question("I couldn't find that button.").reprompt(
            "What would you like to do?")
    return gadget().set_light(targets=[gid],
                              animations=[animation().on(color=hex)])
コード例 #9
0
 def test_stop_input_handler(self):
     g = gadget().stop('1234567890')
     self.assertEqual(g._response['outputSpeech'], {'type': 'PlainText', 'text': ''})
     self.assertEqual(g._response['shouldEndSession'], False)
     self.assertEqual(g._response['directives'][0]['type'], 'GameEngine.StopInputHandler')
     self.assertEqual(g._response['directives'][0]['originatingRequestId'], '1234567890')