alaingilbert / Turntable-API

Allows you to create bots for turntable.fm
http://alaingilbert.github.com/Turntable-API/
MIT License
317 stars 98 forks source link

AFK Police finished too quick? #68

Open Katazui opened 12 years ago

Katazui commented 12 years ago

Here, I have 3 questions. For the AFK Police.

First question: How do I make the '+dj+' things to show their real DJ names not their IDs.

afkCheck = function () {
   var afkLimit = 7; //An Afk Limit of 7+1 minutes.
   for (i = 0; i < djs.length; i++) {
      dj = djs[i]; //Pick a DJ
      if (isAfk(dj, afkLimit)) { 
         bot.speak('@'+dj+', don\'t fall alseep on the decks! Wake up!');
         bot.pm('Hey! Don\'t fall alseep on the decks! Wake up! You have 1 minute to respond before you get remove from the decks!', dj);
         setTimeout(function() {
         bot.remDj(dj);
         bot.speak('@'+dj+', you were remove because you were AFK on the decks for 8 minutes.');
      }, 60000);

      };
   };
};

Second Question: So, this repeats every 5 seconds, and when the Dude AFK Limit DOES hit, won't the bot give the Dude the speech every 5 seconds? Is there some way you can stop that? With variables and stuff?

setInterval(afkCheck, 5000) //This repeats the check every five seconds.

Third Question: Soooo, is there a way so that the TimeStamp updates? By, Speaking, PMing, Laming, Awesoming? Cause, I don't think this works. I just see speak, but I don't know what to put there.

bot.on('roomChanged', function (data) { djs = data.room.metadata.djs; });

bot.on('add_dj', function (data) { djs.push(data.user[0].userid); });

bot.on('rem_dj', function (data) { djs.splice(djs.indexOf(data.user[0].userid), 1); });

    justSaw = function (uid) {
    return lastSeen[uid] = Date.now();
    };

    bot.on('speak', function (data) {
    //your other code
    justSaw(data.userid);
    });

    isAfk = function (userId, num) {
   var last = lastSeen[userId];
   var age_ms = Date.now() - last;
   var age_m = Math.floor(age_ms / 1000 / 60);
   if (age_m >= num) {
      return true;
   };
   return false;
};
x3chaos commented 12 years ago

You probably just need to use bot.getProfile(userid, callback). Use the callback - specifically, data.name - and do something like "console.log(data.name + ' started DJing.');". EDIT: Sorry, that only covers the first question. I don't know anything about setinterval or any of that stuff because I use an activity log object that contains timestamps for every user id. :P

Katazui commented 12 years ago

Oh thanks, but, can you show me? How to write their real DJ names down? Thanks, lol :3

TerrordactylDesigns commented 12 years ago

@Katazui use the code for usersList object if the getProfile call is confusing to you.

https://github.com/alaingilbert/Turntable-API/blob/master/examples/users_list.js

then you can just use theUsersList[dj].name to pull their screen name from the object based on their userID.

Katazui commented 12 years ago

Cool, Thanks got that one down.