Skip to content

Instantly share code, notes, and snippets.

@mxmzb
Created January 20, 2015 15:24
Show Gist options
  • Select an option

  • Save mxmzb/33a8703de838faab744e to your computer and use it in GitHub Desktop.

Select an option

Save mxmzb/33a8703de838faab744e to your computer and use it in GitHub Desktop.
var addPendingFriends = function() {
console.log("searching for pending friend requests...");
console.log(bot.steamID);
var bot_db = models.Bot.where({ steam_id: bot.steamID }).fetch(); // i need the model here, not a promise
new models.User().botStatusPending().fetchAll().then(function(users){
users.forEach(function(user){
console.log(bot_db.get('id'));
if(bot.friends[user.get('steam_id')] && bot.friends[user.get('steam_id')] == 2) {
console.log(bot_db);
// at this point i need the id of bot_db outside of a promise to use it in another query.
bot_db.then(function(bot_model){
bot_model.set({ friends_count: real_friends_count() }).save()
})
.catch(function(e) {
console.error(e);
});
console.log(user.get('steam_id') + " was added as a friend.");
console.log("Bot " + config.steam_user + " has now " + real_friends_count() + " friends.");
}
});
})
.catch(function(e) {
console.error(e);
});
console.log("finished searching");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment