Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var PlugAPI = require('plugapi');
- //var mysql = require('mySQL');
- //var connection = mysql.createConnection({
- // host: "localhost",
- // user: 'root',
- // password: 'password'
- //});
- //connection.connect();
- var bot = new PlugAPI({
- "email": "email@email.com",
- "password": "password"
- }, function(bot){
- //Declarations
- var inactiveUserList;
- var mentionResponses = ["That's me!","What can I do for you, Senpai?","私はちょうど何が重要か見つけようとしている。","check out my mixtape fam it's fire"];
- var setHost = "";
- bot.connect("theskylounge");
- bot.on('roomJoin', function(data) {
- console.log("[INIT]");
- // connection.query('CREATE DATABASE IF NOT EXISTS avanna', function(error, results) {
- // if(error)
- // {
- // console.log(error);
- // }
- // });
- // connection.query('use avanna');
- // connection.query('CREATE TABLE IF NOT EXISTS `users` (username VARCHAR(24), id VARCHAR(16), lastseen DATE, lastactive DATETIME, cookies INTEGER)', function(error) {
- // if(error) {
- // console.log("ERROR IN TABLE CREATION: " + error);
- // }
- // });
- bot.getUsers().forEach(function(user) {
- updateDB(user.username, user.id);
- });
- bot.woot();
- bot.sendChat("Is anyone there?");
- //getUserID("MistMurk");
- });
- bot.on('chat', function(data) {
- console.log(data.from + "> " + data.message);
- //updateDB(data.from.username, data.from.id);
- if(data.message.indexOf("@Avanna 2.0") !== -1){
- bot.sendChat(mentionResponses[Math.floor(Math.random()*mentionResponses.length)]);
- }//*/
- var command = data.message.trim();
- if(command.indexOf("!") === 0) {
- executeCommand(command.substring(1), data.from);
- }//*/
- });
- bot.on('advance', function(data) {
- if (data.lastPlay.media !== null && data.lastPlay.dj !== null) {
- var link;
- if(data.lastPlay.media.format == 1) {
- link = "https://www.youtube.com/watch?v=" + data.lastPlay.media.cid;
- }
- if(data.lastPlay.media.format == 2) {
- //SC.get('/tracks/' + media.cid, function(sound) {
- // link = sound.permalink_url;
- //})
- link = data.lastPlay.media.author + " - " + data.lastPlay.media.title;
- }
- bot.sendChat("Last Play: " + link);
- bot.sendChat("Stats: " + data.lastPlay.score.positive + ":+1: " + data.lastPlay.score.grabs + ":star: " + data.lastPlay.score.negative + ":-1:");
- bot.woot();
- if(data.lastPlay.score.grabs > 0){
- // connection.query('UPDATE `users` SET `cookies` = `cookies` + ' + data.lastPlay.score.grabs + ' WHERE `id` = "' + data.lastPlay.dj.id + '"', function(error, results){
- // if(error){
- // console.log(error);
- // }
- // });
- }
- // connection.query('SELECT * FROM USERS WHERE TIMESTAMPDIFF(MINUTE, lastactive, NOW()) > 60', function(error, results){
- // if(error){
- // console.log(error)
- // }
- // var newInactiveUserList = [];
- // var userList = "";
- // results.forEach(function(user) {
- // bot.getDJs().forEach(function(dj){
- // //console.log(dj.username + " is an admin? " + isAdmin(dj.id));
- // if(!isAdmin(dj.id) && connection.escape(dj.username) === user.username){
- // var isWarning = true;
- // for(index in inactiveUserList){
- // if(inactiveUserList[index] == dj.id){
- // bot.moderateRemoveDJ(dj.id);
- // bot.sendChat("WARNING @" + dj.username + ", you have been removed from the wait list for afking. Please rejoin chat before rejoining the wait list.");
- // isWarning = false;
- // }
- // }
- // if(isWarning){
- // userList += "@" + dj.username + ", ";
- // newInactiveUserList.push(dj.id);
- // }
- // }
- // });
- // });
- // inactiveUserList = newInactiveUserList;
- // if(userList.length !== 0){
- // bot.sendChat("WARNING " + userList + " you have been afk for more than the alloted time. Please join chat or be removed from the wait list.");
- // }
- //});//*/
- }
- });
- bot.on('vote', function(data) {
- /* if(data.v === -1){
- bot.sendChat("WARNING @" + bot.getUser(data.i).username + ", we do not meh in this room. Additional mehs may lead to removal from the room.");
- }*/
- });
- bot.on('djListUpdate', function(data){
- //console.log(data)
- if(data.length != 0){
- var newDj = data[data.length-1];
- console.log(newDj);
- if(setHost !== "" && setHost !== bot.getUser(newDj).username){
- bot.moderateRemoveDJ(newDj);
- }
- }
- });
- bot.on('userJoin', function(data) {
- console.log("[JOIN]", data.username);
- bot.sendChat("Welcome, @" + data.username + "!");
- updateDB(data.username,data.id);
- });
- function updateDB(user,id) {
- // connection.query('SELECT * FROM `users` WHERE `id` = "' + id + '"', function(error, results){
- // if(error){
- // console.log(error);
- // }
- // if(results == null || results.length == 0) {
- // connection.query('INSERT INTO `users` (username, id, lastseen, lastactive, cookies) VALUES ("' + connection.escape(user) + '","' + id + '", CURDATE(), NOW(), 5)', function(error) {
- // if(error) {
- // console.log(error);
- // }
- // });
- // }
- // else {
- // updateActive(user,id);
- // }
- // });
- }
- function updateActive(user,id) {
- // connection.query('UPDATE `users` SET `lastseen` = CURDATE() WHERE `id` = "'+ id + '"', function(error, results) {
- // if(error) {
- // console.log(error);
- // }
- // });
- // connection.query('UPDATE `users` SET `lastactive` = NOW() WHERE `id` = "'+ id + '"', function(error, results) {
- // if(error) {
- // console.log(error);
- // }
- // });
- }
- var reconnect = function() { bot.connect("theskylounge"); };
- bot.on('close', reconnect);
- bot.on('error', reconnect);
- setInterval(function(){timedChatMessages()}, 900000);
- function timedChatMessages(){
- 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! 【=◈︿◈=】");
- }
- setInterval(function(){dropCookie()}, 1800000)
- function dropCookie(){
- if(Math.random() > .9){
- bot.sendChat("Everyone here gets a cookie! Yay! :cookie:");
- bot.getUsers().forEach(function(user){
- // connection.query('UPDATE `users` set `cookies` = `cookies` + 1 where id = "' + user.id + '"',function(error, results){
- // if(error) {
- // console.log(error);
- // }
- // });
- })
- }
- }
- function executeCommand(args, from) {
- if (args === "calendar" || args === "events"){
- bot.sendChat("Calendar of events: http://theskylounge.weebly.com/event-calendar.html")
- }
- else if(args === "marco"){
- bot.sendChat("Polo!");
- }
- else if(args === "ping"){
- bot.sendChat("Pong!");
- }
- else if(args.indexOf("cookies") == 0)
- {
- if(args.length === 7){
- // connection.query('SELECT * FROM `users` WHERE `id` = "' + from.id + '"', function(error, results){
- // console.log("got here")
- // if(error){
- // console.log(error);
- // }
- // console.log(results);
- // if(results.length !== 0){
- // console.log(bot.sendChat("@" + from.username + " has " + results[0].cookies + " cookies!"));
- // }
- // });
- }
- }
- else if(args.indexOf("cookie") == 0){
- // connection.query('SELECT * FROM `users` WHERE `id` = "' + from.id + '"', function(error, results){
- // if(error){
- // console.log(error);
- // }
- // var user = results[0];
- // if(user.cookies > 0){
- // var userIndex = args.indexOf(" ");
- // if(userIndex !== -1){
- // if(args.charAt(userIndex+1) === '@'){
- // userIndex++;
- // }
- // var recieve = args.substring(userIndex+1);
- // if(getUserID(recieve) !== -1){
- // bot.sendChat("@" + from + " gives @" + recieve + " a cookie! Yum!");
- // // connection.query('UPDATE `users` SET `cookies` = `cookies` + 1 WHERE `id` = "' + getUserID(recieve) + '"',function(error, results){
- // // if(error){
- // // console.log(error);
- // // }
- // // });
- // // connection.query('UPDATE `users` SET `cookies` = `cookies` - 1 WHERE `id` = ' + user.id ,function(error, results){
- // // if(error){
- // // console.log(error);
- // // }
- // // });
- // }
- // else{
- // bot.sendChat("User does not exist! Don't waste your cookies!");
- // }
- // }
- // }
- // else{
- // bot.sendChat("@" + from.username + " You have no cookies to give!");
- // }
- // });
- }
- else if(args === "sets"){
- bot.sendChat("Past sets can be found here: http://theskylounge.weebly.com/live-sets.html");
- }
- else if(args.indexOf("set") == 0 && isAdminUsername(from)){
- if(setHost === ""){
- var userIndex = args.indexOf(" ");
- if(userIndex !== -1){
- if(args.charAt(userIndex+1) === '@'){
- userIndex++;
- }
- var newHost = args.substring(userIndex+1);
- bot.sendChat("Set hosted! Get ready for your ears to be graced by the glorious music of @" + args.substring(userIndex+1));
- var djs = bot.getDJs();
- var id = getUserID(newHost)
- if(id !== -1){
- setHost = newHost;
- djs.forEach(function(dj){
- if(dj.username !== setHost){
- bot.moderateRemoveDJ(dj.id);
- }
- });
- }
- else{
- bot.sendChat("User not found!");
- }
- }
- }
- else{
- bot.sendChat("Set already hosted! Use !endset to end.");
- }
- }
- else if(args === "endset")
- {
- bot.sendChat("And thus ends the set of @" + setHost + "... Who survived?");
- setHost = "";
- }
- else if(args === "info"){
- bot.sendChat("Please visit our website for more info: http://theskylounge.weebly.com/");
- }
- else if(args === "meme" && (isAdminUsername(from) || from == "PseudoCat")){
- bot.sendChat("http://i2.kym-cdn.com/photos/images/facebook/000/875/509/533.jpg");
- }
- else if(args === "facebook"){
- bot.sendChat("https://www.facebook.com/groups/porterrobinsonofficial/");
- }
- else if(args === "sponsor" || args === "partner" || args == "sponsors" || args == "partners"){
- bot.sendChat("We are proud sponsors of: http://theskylounge.weebly.com/sponsors.html");
- }
- else if(args === "rules"){
- bot.sendChat("http://theskylounge.weebly.com/rules.html");
- }
- else if(args === "skip" && isAdminUsername(from)){
- bot.moderateForceSkip();
- }
- // else if(args.indexOf("lastactive") === 0){
- // var userIndex = args.indexOf(" ");
- // if(userIndex !== -1){
- // if(args.charAt(userIndex+1) === '@'){
- // userIndex++;
- // }
- // var user = args.substring(userIndex+1);
- // var userId = getUserID(user);
- // connection.query('SELECT * FROM `users` WHERE `id` = "' + userId + '"', function(error, results){
- // console.log("got here")
- // if(error){
- // console.log(error);
- // }
- // console.log(results);
- // if(results.length !== 0){
- // console.log(bot.sendChat("@" + user + " was last seen " + results[0].lastactive));
- // }
- // });
- // }
- // }
- }
- function isAdmin(id){
- var staff = bot.getStaff();
- for(admin in staff){
- if(staff[admin].role > 1 && id == staff[admin].id){
- return true;
- }
- }
- return false;
- }
- function isAdminUsername(username){
- var staff = bot.getStaff();
- for(admin in staff){
- if(staff[admin].role > 1 && username == staff[admin].username){
- return true;
- }
- }
- return false;
- }
- function getUserID(username){
- var users = bot.getUsers();
- for(user in users){
- //console.log(users[user].username + " " + username);
- if(users[user].username === username){
- console.log(users[user].id);
- return users[user].id;
- }
- }
- console.log("Failed to find user!");
- return -1;
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement