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)
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)
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)
def get_user_by_username(username, callback): db = get_database() user = yield motor.Op(db.users.find_one, {"username": username}) callback(user)
def get_user(user_id, callback): db = get_database() user = yield motor.Op(db.users.find_one, {"user_id": user_id}) callback(user)