Esempio n. 1
0
def joined(message):
    """Sent by clients when they enter a room.
    A status message is broadcast to all people in the room."""
    room = session.get('room')
    with_bot = False
    if room in bot_rooms.keys():
        with_bot = True
        # Store previous ID
        bot_room = room
        room = str(uuid.uuid4())  # Create private room
        session["room"] = room  # Update session
    join_room(room)
    emit('status', {'msg': session.get('name') + ' has entered the room.'}, room=room)
    if with_bot:
        # Reverse name for CopyCat bot
        if bot_room == "60":
            bot_name = session.get('name')[::-1]
        # Keep instance of bot
        else:
            bot_name = bot_rooms[bot_room]
        b = Bot(bot_name)
        b.setup()
        active_bots[room] = b
        # Greet user
        emit('status', {'msg': b.name() + ' [BOT] has entered the room.'}, room=room)
        emit('message', {'msg':  b.name() + ': ' + b.greet()}, room=room)