Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var PlugAPI = require('plugapi');
  2. //var mysql = require('mySQL');
  3.  
  4. //var connection = mysql.createConnection({
  5. //  host: "localhost",
  6. //  user: 'root',
  7. //  password: 'password'
  8. //});
  9.  
  10. //connection.connect();
  11.  
  12. var bot = new PlugAPI({
  13.     "email": "email@email.com",
  14.     "password": "password"
  15. }, function(bot){
  16.     //Declarations
  17.     var inactiveUserList;
  18.     var mentionResponses = ["That's me!","What can I do for you, Senpai?","私はちょうど何が重要か見つけようとしている。","check out my mixtape fam it's fire"];
  19.     var setHost = "";
  20.  
  21.     bot.connect("theskylounge");
  22.  
  23.     bot.on('roomJoin', function(data) {
  24.         console.log("[INIT]");
  25.         // connection.query('CREATE DATABASE IF NOT EXISTS avanna', function(error, results) {
  26.         //  if(error)
  27.         //  {
  28.         //      console.log(error);
  29.         //  }
  30.         // });
  31.         // connection.query('use avanna');
  32.         // connection.query('CREATE TABLE IF NOT EXISTS `users` (username VARCHAR(24), id VARCHAR(16), lastseen DATE, lastactive DATETIME, cookies INTEGER)', function(error) {
  33.         //  if(error) {
  34.         //      console.log("ERROR IN TABLE CREATION: " + error);
  35.         //  }
  36.         // });
  37.         bot.getUsers().forEach(function(user) {
  38.             updateDB(user.username, user.id);
  39.         });
  40.         bot.woot();
  41.         bot.sendChat("Is anyone there?");
  42.         //getUserID("MistMurk");
  43.     });
  44.  
  45.     bot.on('chat', function(data) {
  46.             console.log(data.from + "> " + data.message);
  47.             //updateDB(data.from.username, data.from.id);
  48.  
  49.             if(data.message.indexOf("@Avanna 2.0") !== -1){
  50.                 bot.sendChat(mentionResponses[Math.floor(Math.random()*mentionResponses.length)]);
  51.             }//*/
  52.  
  53.             var command = data.message.trim();
  54.             if(command.indexOf("!") === 0) {
  55.                 executeCommand(command.substring(1), data.from);
  56.             }//*/
  57.         });
  58.  
  59.     bot.on('advance', function(data) {
  60.         if (data.lastPlay.media !== null && data.lastPlay.dj !== null) {
  61.             var link;
  62.             if(data.lastPlay.media.format == 1) {
  63.                 link = "https://www.youtube.com/watch?v=" + data.lastPlay.media.cid;
  64.             }
  65.             if(data.lastPlay.media.format == 2) {
  66.                 //SC.get('/tracks/' + media.cid, function(sound) {
  67.                 //  link = sound.permalink_url;
  68.                 //})
  69.                 link = data.lastPlay.media.author + " - " + data.lastPlay.media.title;
  70.             }
  71.  
  72.             bot.sendChat("Last Play: " + link);
  73.             bot.sendChat("Stats: " + data.lastPlay.score.positive + ":+1:  " + data.lastPlay.score.grabs + ":star:  " + data.lastPlay.score.negative + ":-1:");
  74.             bot.woot();
  75.  
  76.             if(data.lastPlay.score.grabs > 0){
  77.                 // connection.query('UPDATE `users` SET `cookies` = `cookies` + ' + data.lastPlay.score.grabs + ' WHERE `id` = "' + data.lastPlay.dj.id + '"', function(error, results){
  78.                 //  if(error){
  79.                 //      console.log(error);
  80.                 //  }
  81.                 // });
  82.             }
  83.  
  84.             // connection.query('SELECT * FROM USERS WHERE TIMESTAMPDIFF(MINUTE, lastactive, NOW()) > 60', function(error, results){
  85.             //  if(error){
  86.             //      console.log(error)
  87.             //  }
  88.             //  var newInactiveUserList = [];
  89.             //  var userList = "";
  90.             //  results.forEach(function(user) {
  91.             //      bot.getDJs().forEach(function(dj){
  92.             //          //console.log(dj.username + " is an admin? " + isAdmin(dj.id));
  93.             //          if(!isAdmin(dj.id) && connection.escape(dj.username) === user.username){
  94.             //              var isWarning = true;
  95.             //              for(index in inactiveUserList){
  96.             //                  if(inactiveUserList[index] == dj.id){
  97.             //                      bot.moderateRemoveDJ(dj.id);
  98.             //                      bot.sendChat("WARNING @" + dj.username + ", you have been removed from the wait list for afking. Please rejoin chat before rejoining the wait list.");
  99.             //                      isWarning = false;
  100.             //                  }
  101.             //              }
  102.             //              if(isWarning){
  103.             //                  userList += "@" + dj.username + ", ";
  104.             //                  newInactiveUserList.push(dj.id);
  105.             //              }
  106.  
  107.             //          }
  108.             //      });
  109.             //  });
  110.                 // inactiveUserList = newInactiveUserList;
  111.                 // if(userList.length !== 0){
  112.                 //  bot.sendChat("WARNING " + userList + " you have been afk for more than the alloted time. Please join chat or be removed from the wait list.");
  113.                 // }
  114.             //});//*/
  115.         }
  116.     });
  117.  
  118.     bot.on('vote', function(data) {
  119. /*      if(data.v === -1){
  120.             bot.sendChat("WARNING @" + bot.getUser(data.i).username + ", we do not meh in this room. Additional mehs may lead to removal from the room.");
  121.         }*/
  122.     });
  123.  
  124.     bot.on('djListUpdate', function(data){
  125.         //console.log(data)
  126.         if(data.length != 0){
  127.             var newDj = data[data.length-1];
  128.             console.log(newDj);
  129.             if(setHost !== "" && setHost !== bot.getUser(newDj).username){
  130.                 bot.moderateRemoveDJ(newDj);
  131.             }
  132.         }
  133.     });
  134.  
  135.     bot.on('userJoin', function(data) {
  136.         console.log("[JOIN]", data.username);
  137.         bot.sendChat("Welcome, @" + data.username + "!");
  138.         updateDB(data.username,data.id);
  139.     });
  140.  
  141.     function updateDB(user,id) {
  142.         // connection.query('SELECT * FROM `users` WHERE `id` = "' + id + '"', function(error, results){
  143.         //      if(error){
  144.         //          console.log(error);
  145.         //      }
  146.  
  147.         //      if(results == null || results.length == 0) {
  148.         //          connection.query('INSERT INTO `users` (username, id, lastseen, lastactive, cookies) VALUES ("' + connection.escape(user) + '","' + id + '", CURDATE(), NOW(), 5)', function(error) {
  149.         //              if(error) {
  150.         //                  console.log(error);
  151.         //              }
  152.         //          });
  153.         //      }
  154.         //      else {
  155.         //          updateActive(user,id);
  156.         //      }
  157.         //  });
  158.     }
  159.  
  160.     function updateActive(user,id) {
  161.         // connection.query('UPDATE `users` SET `lastseen` = CURDATE() WHERE `id` = "'+ id + '"', function(error, results) {
  162.         //  if(error) {
  163.         //      console.log(error);
  164.         //  }
  165.         // });
  166.         // connection.query('UPDATE `users` SET `lastactive` = NOW() WHERE `id` = "'+ id + '"', function(error, results) {
  167.         //  if(error) {
  168.         //      console.log(error);
  169.         //  }
  170.         // });
  171.     }
  172.  
  173.     var reconnect = function() { bot.connect("theskylounge"); };
  174.  
  175.     bot.on('close', reconnect);
  176.     bot.on('error', reconnect);
  177.  
  178.     setInterval(function(){timedChatMessages()}, 900000);
  179.  
  180.     function timedChatMessages(){
  181.         bot.sendChat("Please visit http://theskylounge.weebly.com/ for information about this room. Make sure you are running plug3 https://plugcubed.net/ to get the full room experience! 【=◈︿◈=】");
  182.     }
  183.  
  184.     setInterval(function(){dropCookie()}, 1800000)
  185.     function dropCookie(){
  186.         if(Math.random() > .9){
  187.             bot.sendChat("Everyone here gets a cookie! Yay! :cookie:");
  188.             bot.getUsers().forEach(function(user){
  189.                 // connection.query('UPDATE `users` set `cookies` = `cookies` + 1 where id = "' + user.id + '"',function(error, results){
  190.                 //  if(error) {
  191.                 //      console.log(error);
  192.                 //  }
  193.                 // });
  194.             })
  195.         }
  196.     }
  197.  
  198.     function executeCommand(args, from) {
  199.         if (args === "calendar" || args === "events"){
  200.             bot.sendChat("Calendar of events: http://theskylounge.weebly.com/event-calendar.html")
  201.         }
  202.         else if(args === "marco"){
  203.             bot.sendChat("Polo!");
  204.         }
  205.         else if(args === "ping"){
  206.             bot.sendChat("Pong!");
  207.         }
  208.         else if(args.indexOf("cookies") == 0)
  209.         {
  210.             if(args.length === 7){
  211.                 // connection.query('SELECT * FROM `users` WHERE `id` = "' + from.id + '"', function(error, results){
  212.                 //      console.log("got here")
  213.                 //      if(error){
  214.                 //          console.log(error);
  215.                 //      }
  216.                 //      console.log(results);
  217.                 //      if(results.length !== 0){
  218.                 //          console.log(bot.sendChat("@" + from.username + " has " + results[0].cookies + " cookies!"));
  219.                 //      }
  220.                 //  });
  221.             }
  222.         }
  223.         else if(args.indexOf("cookie") == 0){
  224.             // connection.query('SELECT * FROM `users` WHERE `id` = "' + from.id + '"', function(error, results){
  225.             //  if(error){
  226.             //      console.log(error);
  227.             //  }
  228.             //  var user = results[0];
  229.             //  if(user.cookies > 0){
  230.             //      var userIndex = args.indexOf(" ");
  231.             //      if(userIndex !== -1){
  232.             //          if(args.charAt(userIndex+1) === '@'){
  233.             //              userIndex++;
  234.             //          }
  235.             //          var recieve = args.substring(userIndex+1);
  236.             //          if(getUserID(recieve) !== -1){
  237.             //              bot.sendChat("@" + from + " gives @" + recieve + " a cookie! Yum!");
  238.             //              // connection.query('UPDATE `users` SET `cookies`  = `cookies` + 1 WHERE `id` = "' + getUserID(recieve) + '"',function(error, results){
  239.             //              //  if(error){
  240.             //              //      console.log(error);
  241.             //              //  }
  242.             //              // });
  243.             //              // connection.query('UPDATE `users` SET `cookies`  = `cookies` - 1 WHERE `id` = ' + user.id ,function(error, results){
  244.             //              //  if(error){
  245.             //              //      console.log(error);
  246.             //              //  }
  247.             //              // });
  248.             //          }
  249.             //          else{
  250.             //              bot.sendChat("User does not exist! Don't waste your cookies!");
  251.             //          }
  252.             //      }
  253.             //  }
  254.             //  else{
  255.             //      bot.sendChat("@" + from.username + " You have no cookies to give!");
  256.             //  }
  257.             // });
  258.         }
  259.         else if(args === "sets"){
  260.             bot.sendChat("Past sets can be found here: http://theskylounge.weebly.com/live-sets.html");
  261.         }
  262.         else if(args.indexOf("set") == 0 && isAdminUsername(from)){
  263.             if(setHost === ""){
  264.                 var userIndex = args.indexOf(" ");
  265.                 if(userIndex !== -1){
  266.                     if(args.charAt(userIndex+1) === '@'){
  267.                         userIndex++;
  268.                     }
  269.                     var newHost = args.substring(userIndex+1);
  270.                     bot.sendChat("Set hosted! Get ready for your ears to be graced by the glorious music of @" + args.substring(userIndex+1));
  271.                     var djs = bot.getDJs();
  272.                     var id = getUserID(newHost)
  273.                     if(id !== -1){
  274.                         setHost = newHost;
  275.                         djs.forEach(function(dj){
  276.                             if(dj.username !== setHost){
  277.                                 bot.moderateRemoveDJ(dj.id);
  278.                             }
  279.                         });
  280.                     }
  281.                     else{
  282.                         bot.sendChat("User not found!");
  283.                     }                  
  284.                 }
  285.             }
  286.             else{
  287.                 bot.sendChat("Set already hosted! Use !endset to end.");
  288.             }
  289.         }
  290.         else if(args === "endset")
  291.         {
  292.             bot.sendChat("And thus ends the set of @" + setHost + "... Who survived?");
  293.             setHost = "";
  294.         }
  295.         else if(args === "info"){
  296.             bot.sendChat("Please visit our website for more info: http://theskylounge.weebly.com/");
  297.         }
  298.         else if(args === "meme" && (isAdminUsername(from) || from == "PseudoCat")){
  299.             bot.sendChat("http://i2.kym-cdn.com/photos/images/facebook/000/875/509/533.jpg");
  300.         }
  301.         else if(args === "facebook"){
  302.             bot.sendChat("https://www.facebook.com/groups/porterrobinsonofficial/");
  303.         }
  304.         else if(args === "sponsor" || args === "partner" || args == "sponsors" || args == "partners"){
  305.             bot.sendChat("We are proud sponsors of: http://theskylounge.weebly.com/sponsors.html");
  306.         }
  307.         else if(args === "rules"){
  308.             bot.sendChat("http://theskylounge.weebly.com/rules.html");
  309.         }
  310.         else if(args === "skip" && isAdminUsername(from)){
  311.             bot.moderateForceSkip();
  312.         }
  313.         // else if(args.indexOf("lastactive") === 0){
  314.         //  var userIndex = args.indexOf(" ");
  315.         //  if(userIndex !== -1){
  316.         //      if(args.charAt(userIndex+1) === '@'){
  317.         //          userIndex++;
  318.         //      }
  319.         //      var user = args.substring(userIndex+1);
  320.         //      var userId = getUserID(user);
  321.         //      connection.query('SELECT * FROM `users` WHERE `id` = "' + userId + '"', function(error, results){
  322.         //          console.log("got here")
  323.         //          if(error){
  324.         //              console.log(error);
  325.         //          }
  326.         //          console.log(results);
  327.         //          if(results.length !== 0){
  328.         //              console.log(bot.sendChat("@" + user + " was last seen " + results[0].lastactive));
  329.         //          }
  330.         //      });
  331.         //  }
  332.         // }
  333.  
  334.     }
  335.  
  336.     function isAdmin(id){
  337.         var staff = bot.getStaff();
  338.         for(admin in staff){
  339.             if(staff[admin].role > 1 && id == staff[admin].id){
  340.                 return true;
  341.             }
  342.         }
  343.         return false;
  344.     }
  345.  
  346.     function isAdminUsername(username){
  347.         var staff = bot.getStaff();
  348.         for(admin in staff){
  349.             if(staff[admin].role > 1 && username == staff[admin].username){
  350.                 return true;
  351.             }
  352.         }
  353.         return false;
  354.     }
  355.  
  356.     function getUserID(username){
  357.         var users = bot.getUsers();
  358.         for(user in users){
  359.             //console.log(users[user].username + " " + username);
  360.             if(users[user].username === username){
  361.                 console.log(users[user].id);
  362.                 return users[user].id;
  363.             }
  364.         }
  365.         console.log("Failed to find user!");
  366.         return -1;
  367.     }
  368. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement