Exemplo n.º 1
0
def send_message(message):

    if message['data'].startswith('/gif '):
        _, search_term = message['data'].split('/gif ')
        gif = cribby.find_gif(search_term) or 'Whoopsie!'
        emit('gif', {
            'nickname': message['nickname'],
            'gif': gif
        },
             room=message['game'])
        return
    elif message['data'].startswith('/') and ' ' in message['data']:
        type, request = message['data'].strip('/').split(' ')
        if type in {'blob', 'piggy', 'meow'}:
            found, known_animations = cribby.find_animation(type, request)
            if found:
                emit('animation', {
                    'nickname': message['nickname'],
                    'type': type,
                    'instance': request
                },
                     room=message['game'])
            else:
                known = ', '.join(k for k in sorted(known_animations))
                msg = "Heyo! {}s I know about are: {}. <br /><b>*Only you can see this message*</b>".format(
                    type, known)
                emit('new_message', {
                    'type': 'chat',
                    'nickname': 'cribby',
                    'data': msg
                })
            return

    if message.get('private', '') == 'true':
        emit(
            'new_message', {
                'type': 'chat',
                'data': message['data'],
                'nickname': message['nickname']
            })
    else:
        emit('new_message', {
            'type': 'chat',
            'data': message['data'],
            'nickname': message['nickname']
        },
             room=message['game'])
Exemplo n.º 2
0
 def test_unknown_piggy(self):
     request = 'not_a_blob'
     assert cribby.find_animation('piggy', request) == (False, KNOWN_PIGGYS)
Exemplo n.º 3
0
 def test_find_piggy(self):
     request = 'wave'
     assert cribby.find_animation('piggy', request) == (True, [])
Exemplo n.º 4
0
 def test_unknown_meow(self):
     request = 'not_a_blob'
     assert cribby.find_animation('meow', request) == (False, KNOWN_MEOWS)
Exemplo n.º 5
0
 def test_find_meow(self):
     request = 'wave'
     assert cribby.find_animation('meow', request) == (True, [])
Exemplo n.º 6
0
 def test_unknown_blob(self):
     request = 'not_a_blob'
     assert cribby.find_animation('blob', request) == (False, KNOWN_BLOBS)
Exemplo n.º 7
0
 def test_find_blob(self):
     request = 'wave'
     assert cribby.find_animation('blob', request) == (True, [])