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'])
def test_unknown_piggy(self): request = 'not_a_blob' assert cribby.find_animation('piggy', request) == (False, KNOWN_PIGGYS)
def test_find_piggy(self): request = 'wave' assert cribby.find_animation('piggy', request) == (True, [])
def test_unknown_meow(self): request = 'not_a_blob' assert cribby.find_animation('meow', request) == (False, KNOWN_MEOWS)
def test_find_meow(self): request = 'wave' assert cribby.find_animation('meow', request) == (True, [])
def test_unknown_blob(self): request = 'not_a_blob' assert cribby.find_animation('blob', request) == (False, KNOWN_BLOBS)
def test_find_blob(self): request = 'wave' assert cribby.find_animation('blob', request) == (True, [])