Guest User

Untitled

a guest
Jul 16th, 2018
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. /*
  2. * roboJar: A turntable.fm bot. Chris "inajar" Vickery <chrisinajar@gmail.com>
  3. *
  4. * Redistribution and use in source, minified, binary, or any other forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. * * Redistributions of source code must retain the above copyright
  7. * notice, this list of conditions and the following disclaimer.
  8. * * Redistributions in binary form must reproduce the above copyright
  9. * notice, this list of conditions and the following disclaimer in the
  10. * documentation and/or other materials provided with the distribution.
  11. * * Neither the name, roboJar, nor the names of its contributors may be
  12. * used to endorse or promote products derived from this software without
  13. * specific prior written permission.
  14. *
  15. * Needs more cat facts.
  16. *
  17. */
  18.  
  19. var SlotTimer = function (jj) {
  20. var s = this;
  21. this.j=jj;
  22. var j=jj;
  23. this.slots = [];
  24. //this.j.putDoc('slottimer', { version: 0 }, function(s, doc) {});
  25. this.j.getDoc('slottimer', function(s, doc) {
  26. if (s.j.isset(doc)) {
  27. s.db = doc;
  28. s.j.log("yeah, got my shit");
  29. } else {
  30. j.log("Oh fuck...");
  31. return;
  32. }
  33. if (!s.j.isset(s.db.version)) {
  34. s.db = { version: 0 };
  35. }
  36. }, this);
  37. j.on(this, 'rem_dj', function (d, s) {
  38. var j = s.j;
  39. s.slots.push((new Date()).getTime());
  40. }, this);
  41. j.on(this, 'add_dj', function (d, s) {
  42. var j = s.j;
  43. if (s.slots.length < 1)
  44. return;
  45. var user = d.user[0];
  46. var t = (((new Date()).getTime())-s.slots[0]);
  47. var idle = j.users[user.userid].getIdleTime();
  48. s.slots.splice(0,1);
  49.  
  50. j.log ("Open slots: " +s.slots.length);
  51. var text = "DJ Slot was open for " + (t>1000 ? (t/1000)+" seconds." : t+" msecs.");
  52. if (s.slots.length == 0 && t < 1000) {
  53. if (idle > (1000*60*15)) {
  54. // check for autodj bullshittery
  55. text = '@' + user.name + ' pulled a bullshit move and took a seat in ' + t + 'ms while ' + Math.round(idle/1000/60) + ' minutes idle';
  56.  
  57. // User specific code goes here.... //
  58.  
  59. } else if (t > 500 ) { // 1000-500
  60. text = user.name + ' gets a nice grab in ' + t + 'msecs';
  61. } else if (t > 400 ) { // 400-500
  62. text = user.name + ' spines the seat in ' + t + 'msecs';
  63. } else if (t > 300 ) { // 300-500
  64. text = user.name + ' clickhaxx at ' + t + 'msecs';
  65. } else { // 0-300
  66. text = user.name + ' poops on the room and steals the seat in: ' + t + 'msecs.';
  67. }
  68. }
  69. j.speak(text);
  70.  
  71. if (!j.isset(s.db[user.userid]))
  72. s.db[user.userid] = [];
  73. s.db[user.userid].push({time: t, idle: idle});
  74. }, this);
  75. };
  76.  
  77. SlotTimer.prototype.unload = function(h, d) {
  78. h(d);
  79. };
  80.  
  81. module.exports = SlotTimer;
Add Comment
Please, Sign In to add comment