setAdmin = function(name){ bot.getProfile(name, function(data){ Dj.update({userid: data.userid},{admin: true},function(err, docs){ bot.speak(name + ' added as an admin.'); }); }); };
setCurrentSong = function(data){ if(data.room.metadata.current_song){ song = data.room.metadata.current_song; dj = data.room.metadata.current_dj; upvotes = data.room.metadata.upvotes; downvotes = data.room.metadata.downvotes; listeners = data.room.metadata.listeners; bot.getProfile(dj, function(data){ Dj.find_or_create_by_userid(dj,data.name,new Dj(), function(err, docs){ log_error(err); var dj = docs; Artist.find_or_create_by_name(song.metadata.artist, song, new Artist(), function(err, docs){ log_error(err); var artist = docs; Track.find_or_create_by_name(song.metadata.song, song.metadata.album, artist.id, song._id, new Track(), function(err, docs){ log_error(err); var track = docs; artist.tracks.push(track.id); artist.save(function(err){log_error(err);}); Play.find_or_create_by_timestamp(song.starttime, dj.id, artist.id, track.id, new Play(), function(err, docs){ currentSong = docs; currentSong.upvotes = upvotes; currentSong.downvotes = downvotes; currentSong.listeners = listeners; }); }); }); }); }); } };
deleteAdmin = function(name){ bot.getProfile(name, function(data){ Dj.update({userid: data.userid},{admin: false},function(err, docs){ log_error(); bot.speak(name + ' is no longer an admin.'); }); }); };
function PopulateCurrent(data) { ttfm.getProfile(data.room.metadata.current_dj, function(profile) { if (profile) { var isAdmin = false; if (profile.userid == Config.AdminId) { isAdmin = true; } // try to add or retrieve dj info DB.DJ.Add(profile.userid, profile.name, profile.created, isAdmin, function(err, dj) { LogError(err); var songTT = data.room.metadata.current_song; // try to add or retrieve artist info DB.Artist.Add(songTT.metadata.artist, function(err, artist) { LogError(err); if (artist) { // if we were able to get the artist, try to add or get the song DB.Song.Add( songTT.metadata.album, artist, songTT.metadata.coverart, songTT.metadata.song, function(err, song) { LogError(err); // if we successfully added or retrieved dj and song entries // then add the play entry if (dj && song) { DB.Play.Add( dj, data.room.metadata.downvotes, data.room.metadata.listeners, song, songTT.starttime, data.room.metadata.upvotes, function(err, play) { LogError(err); currentPlayId = play._id; } ); } } ); } }); }); } }); }