Closed Katazui closed 12 years ago
There is. I left it out to ensure staying under 140 characters. I will get you the code for it though. I am on vacation until Monday, so please be aware it will be a few days for me to get a chance to get the code for you.
Oh, have fun!
But, isn't there like a Variable for the DJ name, Song, and artist already? But, I looked everywhere but can't find it.
I'm using the song start/new song events variables in there. Check the API notes on that event and you should see it in the new song object.
We have the
data.metadata.current_song.metadata.song
data.metadata.current_song.metadata.artist
But I want Dj Name., but it doesn't seem to work
data.metadata.current_song.metadata.djname
OK, just took a peek at the API page.
data.current_dj will return the user ID of the current DJ. you will then have to compare that against the user list object to pull the DJs name.
so theUsersList[data.current_dj].name should return the user name.
asdfasldkfjsadlfjsadf.
I'll take a "peek" at the page. Thanks for your help.
Okay, it still didn't work.
I'm trying to add these variables to another bot, and this crash when the event triggers. So, what can be the problem?
data.metadata.current_song.metadata.song
data.metadata.current_song.metadata.artist
I'll be back home sometime monday afternoon, and I'll get the code snippet for you.
OK, first off you need this code: //user theUsersList code from https://github.com/alaingilbert/Turntable-API/blob/master/examples/users_list.js var theUsersList = {};
bot.on('roomChanged', function (data) { // Reset the users list theUsersList = { };
var users = data.users; for (var i=0; i<users.length; i++) { var user = users[i]; theUsersList[user.userid] = user; console.log('added ' + user + ' to theUsersList'); } });
bot.on('registered', function (data) { var user = data.user[0]; theUsersList[user.userid] = user; });
bot.on('deregistered', function (data) { var user = data.user[0]; delete theUsersList[user.userid]; });
this code stores all the friendly users name (as well as all the other data, but you just need the name)
then in the tweeting code you will use theUsersList[data.current_dj].name in order to pull the DJs name.
This is because we use the new_song event which only returns the users ID under data.current_dj and we need to compare to the object to return the users name.
So, what about the Song Name and Song Artist? Those 2 variables doesn't work for me.
Just verified it all from my bot:
var twitter = require('ntwitter'); bot.on('newsong', function (data){ if (ROOMID == '4f4d8e8aa3f7517d700009c5') { // Tweet the new song from the @TerrorBot account. Give the DJ name, the song, and #turntablefm hashtag var twit = new twitter({ consumer_key: 'xxxxxxxxxx', consumer_secret: 'xxxxxxxxx', access_token_key: 'xxxxxxxxxxxx-xxx', access_token_secret: 'xxxxxxxxxxxxxxxx' }); try { bot.roomInfo(true, function(data) { var currSong = data.room.metadata.current_song.metadata.song; var currArtist = data.room.metadata.current_song.metadata.artist; var currDJ = theUsersList[data.room.metadata.current_dj].name; twit .verifyCredentials(function (err, data) { console.log(data); }) .updateStatus(currDJ + ' is now playing! ' + currSong + ' by: ' + currArtist + ' #turntablefm http://turntable.fm/while_icode_dropbeatz_infinite_muzik' , function (err, data) { console.log(data); } ); }); } catch (err) { bot.speak(err.toString()); } } });
with the results of:
https://dl.dropbox.com/u/51430720/Photo%20Jun%2012%2C%205%2007%2006%20PM.png
Works perfect as long as you are also using the userslist object (or could be pulled from a database).
Oh, yay, cool. I didn't know why the same exact code wasn't working for me. Thanks.
Is there a way to show "Katazui is now playing Song by Artist. #turntable tt.fm/blahblahblah". Show the DJ name too in the tweet.