Advertisement
Guest User

Untitled

a guest
Jan 10th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var DubAPI = require('dubapi');
  2.  
  3. new DubAPI({username: 'usuario_aqui', password: 'senha_aqui'}, function(err, bot) {
  4.     if (err) return console.error(err);
  5.  
  6.     var resp=0;
  7.     var count_fila=0;
  8.     var count_downs = { "downdubs":"0"};
  9.     //var teste = 0;
  10.     var chamada = 0;
  11.     var fila = [];
  12.     var fila_user = [];
  13.     var presentes = [];
  14.     var retirados = 0;
  15.  
  16.     bla = function(){
  17.     return new Promise(function(fulfill, reject){
  18.         count_downs = bot.getScore();
  19.         fulfill(resultValue);
  20.     });
  21. };
  22.  
  23.     console.log('Running DubAPI v' + bot.version);
  24.  
  25.     function connect() {bot.connect('radioanao');}
  26.  
  27.     function skip ()
  28.     {
  29.         count_downs = bot.getScore();
  30.     }
  31.  
  32.     skip = function(){
  33.  
  34.     return new Promise(function(fulfill, reject){
  35.         count_downs = bot.getScore();
  36.         fulfill(count_downs);
  37.     });
  38. };
  39.  
  40.  
  41.  
  42.     function skip2()
  43.     {
  44.         count_downs = count_downs.downdubs;
  45.             console.log(count_downs);
  46.     }
  47.  
  48.  
  49.     bot.on('connected', function(name) {
  50.         console.log('Connected to ' + name);
  51.  
  52.         // while(1)
  53.         // {
  54.         //     count_downs = bot.getScore();
  55.         //     while(count_downs == null);
  56.         //     count_downs = count_downs.downdubs;
  57.         //     console.log(count_downs);
  58.         //     //myPromise.then(console.log(count_downs));
  59.         //     //count_downs// = resp.downdubs;
  60.         //     //console.log("count_downs");
  61.         //     if(count_downs !== 0 && count_downs != null)
  62.         //     {
  63.         //         resp = bot.getQueue();
  64.         //         count_fila = resp.length;
  65.         //         console.log(count_downs + " " + count_fila);
  66.         //         if(count_fila <= 2 && count_downs >=3)
  67.         //             bot.moderateSkip();
  68.         //         else if (count_downs >= count_fila/2)
  69.         //             bot.moderateSkip();
  70.         //     }
  71.         //     //wait(5000);
  72.         // }
  73.  
  74.  
  75.     });
  76.  
  77.     function wait(ms){
  78.    var start = new Date().getTime();
  79.    var end = start;
  80.    while(end < start + ms) {
  81.      end = new Date().getTime();
  82.   }
  83. }
  84.  
  85.     bot.on('disconnected', function(name) {
  86.         console.log('Disconnected from ' + name);
  87.  
  88.         setTimeout(connect, 15000);
  89.     });
  90.  
  91.     bot.on('error', function(err) {
  92.         console.error(err);
  93.     });
  94.  
  95.     bot.on(bot.events.userJoin, function(name)
  96.     {
  97.         console.log(name);
  98.         //bot.sendChat(resp.length + " pessoas na fila :3");
  99.     });
  100.  
  101.     bot.on(bot.events.chatMessage, function(data) {
  102.         if((data.message.indexOf("help") !== -1) && (data.user.username.indexOf("Putinha-Bot") == -1) && (data.message.indexOf("@Putinha-Bot") !== -1) && (bot.isMod(data.user) || bot.isManager(data.user) || bot.isOwner(data.user) ||  bot.isCreator(data.user)))
  103.         {
  104.              bot.sendChat("Caso a música tenha os `downvotes necessários`, basta digitar algo no chat para que eu `pule` a música. Para a `Staff` realizar chamada, basta me quotar com a palavra `chamada` e após a contagem, me quotar com a palavra `finalizar`.");      
  105.         }
  106.         // else if((data.message.indexOf("help") !== -1) && (data.user.username.indexOf("Putinha-Bot") == -1) && (data.message.indexOf("@Putinha-Bot") !== -1))
  107.         // {
  108.         //     bot.sendChat("Caso a música tenha os `downvotes necessários`, basta digitar algo no chat para que eu `pule` a música.")
  109.         // }
  110.         else if(data.message.indexOf("@Putinha-Bot") !== -1)
  111.         {
  112.             if(bot.isMod(data.user) || bot.isManager(data.user) || bot.isOwner(data.user) ||  bot.isCreator(data.user))
  113.             {
  114.                //bot.sendChat("@" + data.user.username + " é da Staff.");
  115.                if(data.message.indexOf("chamada") !== -1 && chamada == 0)
  116.                {
  117.                     resp = bot.getQueue();
  118.                     console.log(resp);
  119.                     //resp = JSON.parse(resp);
  120.                     for(var i = 0; i < resp.length; i++)
  121.                     {
  122.                         //console.log(resp[i].user.username);
  123.                         //bot.sendChat(resp[i].user.username);
  124.                         fila.push(resp[i].user.username);
  125.                         fila_user.push(resp[i].uid);
  126.                         console.log("fila[" + i + "] = " + fila[i]);
  127.                     }
  128.  
  129.                     chamada = 1;
  130.  
  131.                     for(var i =0; i < 5; i++)
  132.                         bot.sendChat("@djs CHAMADA " + (i+1) + "/5");// CHAMADA RESPONDAM APENAS UMA VEZ " + (i+1) + "/5");                  
  133.                }
  134.                else if((data.message.indexOf("finalizar") !== -1) && (chamada == 1))
  135.                {
  136.                 //count_downs = bot.getScore();
  137.                 chamada = 0;
  138.                 for(var i = 0; i < fila.length; i++)
  139.                     console.log("fila: " + fila[i]);
  140.                 for(var i = 0; i < presentes.length; i++)
  141.                     console.log("presentes: " + presentes[i]);
  142.                 //{
  143.                 for(var j = 0; j < fila.length; j++)
  144.                     if(presentes.indexOf(fila[j]) == -1)
  145.                     {
  146.                         //bot.moderateRemoveDJ(fila_user[j]);
  147.                         bot.sendChat("@mods `retirem o " + fila[j] + "`");
  148.                         retirados ++;
  149.                     }
  150.                 if(retirados == 0)
  151.                     bot.sendChat("`Todos estão presentes.`");
  152.                 else
  153.                     retirados = 0;
  154.                 fila = [];
  155.                 fila_user = [];
  156.                 presentes = [];
  157.                     //console.log("fila: " + fila[i]);
  158.                 //}
  159.                
  160.                     //console.log("presentes: " + presentes[i]);
  161.                }
  162.  
  163.                // else
  164.                //  bot.sendChat(":thumbsup: (me quote com `help` para mais informações) ");
  165.             // else if(data.message.indexOf("qual o sentido da vida?") !== -1)
  166.             //     bot.sendChat("Leitar e ser leitado.");
  167.             // else if(data.message.indexOf("ping") !== -1)
  168.             //     bot.sendChat("@" + data.user.username + " pong :3");
  169.             // //else if (data.user.username.indexOf("Poneiamigo") !== -1)
  170.             // //{
  171.             //     //bot.sendChat("@" + data.user.username + " sua puta.");
  172.             // //}
  173.             // else if ((data.message.indexOf("puta") !== -1) || (data.message.indexOf("vagabunda") !== -1))
  174.             //     bot.sendChat("Me enche de leitinho quente :3 , " + "@" + data.user.username);
  175.              
  176.             }
  177.             else if ((data.user.username.indexOf("Craviee") !== -1) && (data.message.indexOf("skip") !== -1))
  178.                 bot.moderateSkip();
  179.             else if (data.user.username.indexOf("Craviee") !== -1)
  180.                 bot.sendChat(":thumbsup:");
  181.             // else
  182.             //     bot.sendChat(":thumbsup: (me quote com `help` para mais informações) ");
  183.         }
  184.             else if(chamada == 1)
  185.          {
  186.              //console.log(data.user.username + ': ' + data.message);
  187.             //  for(var i = 0; i < resp.length; i++)
  188.             // {
  189.             //     console.log( "fila[" + i + "] = " + fila[i] + " " + data.user.username);
  190.             //      if(fila[i] == data.user.username)
  191.             //      {
  192.             //          //bot.sendChat("@" + data.user.username + " presente");
  193.             //          console.log( "fila[" + i + "] = " + fila[i] + " presente");
  194.             //          fila[i] = 0;
  195.             //          //console.log( fila[fila.indexOf(data.user.username)] + " presente");
  196.             //          console.log( "fila[" + i + "] = " + fila[i] + " zerado");
  197.             //          break;    
  198.             //      }
  199.             // }
  200.             if(presentes.indexOf(data.user.username) == -1)
  201.             {
  202.                 presentes.push(data.user.username);
  203.             }
  204.          }
  205.  
  206.            
  207.         count_downs = bot.getScore();
  208.         count_downs = count_downs.downdubs;
  209.         if(count_downs !== 0 && count_downs != null && ((data.user.username.indexOf("Putinha-Bot") == -1)))
  210.         {
  211.             resp = bot.getQueue();
  212.             count_fila = resp.length;
  213.             //console.log(count_downs + " " + count_fila);
  214.             if(count_fila <= 2 && count_downs >=3)
  215.             {
  216.                 bot.moderateSkip();
  217.                 bot.sendChat( count_fila + " na fila, " + count_downs + " downvotes.");
  218.             }
  219.             else if ((count_downs >= count_fila/2) && count_fila > 2)
  220.             {
  221.                 bot.moderateSkip();
  222.                 bot.sendChat( count_fila + " na fila, " + count_downs + " downvotes.");
  223.             }
  224.         }
  225.  
  226.         //console.log(data.user.username + ': ' + data.message);
  227.     });
  228.  
  229.     connect();
  230.  
  231.  
  232.  
  233.     // while(1)
  234.     // {
  235.     //     resp = bot.getScore();
  236.     //     console.log(resp);
  237.     //     //myPromise.then(console.log(count_downs));
  238.     //     count_downs = resp.downdubs;
  239.     //     console.log(count_downs);
  240.     //     if(count_downs !== 0)
  241.     //     {
  242.     //         resp = bot.getQueue();
  243.     //         count_fila = resp.length;
  244.     //         //console.log(count_downs + " " + count_fila);
  245.     //         if(count_fila <= 2 && count_downs >=3)
  246.     //             bot.moderateSkip();
  247.     //         else if (count_downs >= count_fila/2)
  248.     //             bot.moderateSkip();
  249.     //     }
  250.     // }
  251.  
  252. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement