SHARE
TWEET

Untitled

a guest Feb 17th, 2019 100 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require('discord.js');
  2. const Listing =  require('./../modules/Listing');
  3. const fs = require('fs');
  4.  
  5. module.exports.run = async(bot, message, args) => {
  6.     let snipeChannel = message.channel;
  7.     const filter = m => !m.author.bot;
  8.     let game = new Listing();
  9.  
  10.     let raw = fs.readFileSync('./roles.json');
  11.     let allowedRoles = JSON.parse(raw);
  12.  
  13.     let validation = function(serverRoles,userRoles){
  14.         let val = false;
  15.         serverRoles.forEach((role) => {
  16.             userRoles.forEach((usr) =>{
  17.                 if(role === usr){
  18.                     val = true;
  19.             }
  20.         });
  21.     });
  22.     return val;
  23. }
  24.  
  25.     let editLast3 = null;
  26.  
  27.     let startMessage = new Discord.RichEmbed()
  28.         .setTitle("GGOLT Fortnite Scrims")
  29.         .setDescription("Please write the last 3 codes from your server ID")
  30.         .setColor("#8600b3")
  31.         .setFooter("FortniteScrimBot Made by SlaeGod");
  32.     message.channel.send({embed: startMessage});
  33.  
  34.     let time =  25;
  35.     let editTime = "";
  36.  
  37.     let timeEmbed = new Discord.RichEmbed()
  38.         .setTitle("Next match in approximately...")
  39.         .setDescription(time + " minutes")
  40.         .setColor("#8600b3");
  41.  
  42.     setTimeout(async() => {
  43.         editTime = await message.channel.send({embed: timeEmbed}).catch( (err) => {
  44.             console.log("Cannot edit deleted message");
  45.         });
  46.     }, 10);
  47.  
  48.     let timeInterval = setInterval(() => {
  49.         if(time === 1){
  50.             time -= 1;
  51.             timeEmbed.setDescription(time + " minutes");
  52.             clearInterval(timeInterval);
  53.         } else{
  54.             time -= 1;
  55.             timeEmbed.setDescription(time + " minutes");
  56.         }
  57.  
  58.         editTime.edit({embed: timeEmbed}).catch((err) => {
  59.             console.log("Cannot edit");
  60.             clearInterval(timeInterval);
  61.         });
  62.     },60000);
  63.  
  64.     let last3 = new Discord.RichEmbed()
  65.         .setTitle("Last 3 code")
  66.         .setColor("#8600b3");
  67.  
  68.     setTimeout( async() => {
  69.         editLast3 = await message.channel.send({embed: last3})
  70.     }, 10);
  71.  
  72.     const collector = snipeChannel.createMessageCollector(filter, {max: 200, maxMatches: 200, time: 180000});
  73.  
  74.     collector.on('collect', m => {
  75.        
  76.         console.log(`Collected ${m.content} | ${m.author.username}`);
  77.  
  78.         if(validation(allowedRoles.roles, m.member.roles.array())){
  79.             if(m.content ==="!start"){
  80.                 collector.stop();
  81.                 console.log("Collector stopped");
  82.                 return;
  83.             }
  84.         }
  85.         if(game.data.length === 0 && m.content.length === 3){
  86.             game.addID(m.content.toUpperCase(), m.author.username);
  87.         }else if (m.content.length === 3){
  88.             if (game.userPresent(m.author.username)){
  89.                 game.deleteUserEntry(m.author.username);
  90.  
  91.                 if (game.idPresent(m.content.toUpperCase())){
  92.                     game.addUser(m.content.toUpperCase(), m.author.username);
  93.                 }else{
  94.                     game.addID(m.content.toUpperCase(), m.author.username);
  95.                 }
  96.             }else{
  97.                 if(game.idPresent(m.content.toUpperCase())){
  98.                     game.addUser(m.content.toUpperCase(), m.author.username);
  99.                 }else{
  100.                     game.addID(m.content.toUpperCase(), m.author.username);
  101.                 }
  102.             }
  103.         }
  104.  
  105.         game.sort();
  106.  
  107.         let str = "";
  108.         last3 = new Discord.RichEmbed()
  109.             .setTitle("Last 3 code")
  110.             .setColor("#8600b3");
  111.        
  112.         for(var i =0; i < game.data.length; i++){
  113.             str = "";
  114.             for(var j = 0; j < game.data[i].users.length; j++){
  115.                 str += game.data[i].users[j] + "\n";
  116.             }
  117.             last3.addField(`${game.data[i].id.toUpperCase()} - ${game.data[i].users.length} PLAYERS`, str, true);
  118.         }
  119.  
  120.         editLast3.edit({embed: last3}).catch((err) => {
  121.             console.log("Caught edit error");
  122.         });
  123.  
  124.         if(m.deleteable){
  125.             m.delete().catch((err) => {
  126.                 console.log("Cannot delete");
  127.                 console.log(err);
  128.             });
  129.         }
  130.     });
  131.  
  132.  
  133.     collector.on('end', collected => {
  134.         console.log(`Collected ${collected.size} items`);
  135.     });
  136.  
  137. }
  138.  
  139. module.exports.help = {
  140.     name: "start"
  141. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top