Example #1
0
def add_user(user_id, username, callback):
    db = get_database()
    user = yield motor.Op(db.users.insert, {
        "username": username,
        "user_id": user_id
    })
    callback(user)
Example #2
0
def list_games(callback):
    """ List all active games """

    db = get_database()
    cursor = db.games.find()
    cursor.limit(1000)
    games = yield motor.Op(cursor.to_list)
    [g.pop('_id') for g in games]
    callback(games)
Example #3
0
def create_new(user, callback):
    """ Create a new Game """

    db = get_database()
    game_id = yield async(get_next_sequence, "games")
    yield motor.Op(db.games.insert, {
        "host": user['username'],
        'host_user_id': user['user_id'],
        "game_id": game_id
    })
    callback(game_id)
Example #4
0
def get_user_by_username(username, callback):
    db = get_database()
    user = yield motor.Op(db.users.find_one, {"username": username})
    callback(user)
Example #5
0
def get_user(user_id, callback):

    db = get_database()
    user = yield motor.Op(db.users.find_one, {"user_id": user_id})
    callback(user)