Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require('discord.js');
- const Listing = require('./../modules/Listing');
- const fs = require('fs');
- const settings = require('./../settings.json');
- const owner = settings.owner;
- module.exports.run = async (bot, message, args) => {
- if(message.deletable) await message.delete()
- let snipeChannel = message.guild.channels.find(c => c.name === "scrim-codes");
- let snipeChannel2 = message.guild.channels.find(c => c.name === "scrim-match");
- snipeChannel.send(".count");
- const filter = m => !m.author.bot;
- let game = new Listing();
- //heapsort
- function heapSort(arr){
- var len = arr.length,
- end = len-1
- heapify(arr, len);
- while(end > 0){
- swap(arr,end--, 0);
- siftDown(arr, 0, end);
- }
- return arr;
- }
- function heapify(arr, len){
- // break the array into root + two sides, to create tree (heap)
- var mid = Math.floor((len-2)/2);
- while(mid >= 0){
- siftDown(arr, mid--, len-1);
- }
- }
- function siftDown(arr, start, end){
- var root = start,
- child = root*2 + 1,
- toSwap = root;
- while(child <= end){
- if(arr[toSwap].users.length > arr[child].users.length){
- swap(arr, toSwap, child+1)
- }
- if(toSwap != root){
- swap(arr, root, toSwap);
- root = toSwap;
- }
- else{
- return;
- }
- toSwap = root;
- child = root*2+1
- }
- }
- function swap(arr, i, j){
- var temp = arr[i];
- arr[i] = arr[j];
- arr[j] = temp;
- }
- let raw = fs.readFileSync('./roles.json');
- let allowedRoles = JSON.parse(raw);
- let validation = function(serverRoles, userRoles){
- let val = false;
- serverRoles.forEach((role) => {
- userRoles.forEach((usr) => {
- if (role == usr){
- val = true;
- }
- });
- });
- return val;
- }
- let gamemode = "SOLO";
- if (args.length > 0){
- if (args[0].toUpperCase() === "SOLO" ||
- args[0].toUpperCase() === "DUOS" ||
- args[0].toUpperCase() === "SQUADS"){
- gamemode = args[0];
- }
- }
- let editLast3 = null;
- let startMessage = new Discord.RichEmbed()
- .setTitle("Fortnite Scrims")
- .setDescription("Please write the last 3 codes from you're Server Id")
- .addField("Gamemode", gamemode.toUpperCase())
- .setColor("#030000")
- .setFooter("ReNotify™");
- snipeChannel2.send({embed: startMessage});
- let codeCollect = new Discord.RichEmbed()
- .setTitle("Waiting for Server ID's")
- .setColor("#030000")
- snipeChannel.send({embed: codeCollect});
- let time = 30;
- let editTime = "";
- let timeEmbed = new Discord.RichEmbed()
- .setTitle("Next match in approx...")
- .setDescription(time + " minutes")
- .setColor("#030000");
- setTimeout(async () => {
- editTime = await snipeChannel2.send({embed: timeEmbed}).catch( (err) => {
- console.log("Cant edit deleted message");
- });
- }, 10);
- let timeInterval = setInterval(() => {
- if (time === 1){
- time -= 1;
- timeEmbed.setDescription(time + " minutes");
- clearInterval(timeInterval);
- }else {
- time -= 1;
- timeEmbed.setDescription(time + " minutes");
- }
- editTime.edit({embed: timeEmbed}).catch((err) => {
- console.log("cant edit");
- clearInterval(timeInterval);
- });
- },60000);
- let last3 = new Discord.RichEmbed()
- .setTitle("Waiting for Server ID's")
- .setColor("#030000");
- setTimeout(async () => {
- editLast3 = await snipeChannel2.send({embed: last3});
- snipeChannel.overwritePermissions(message.guild.defaultRole, {
- SEND_MESSAGES: true
- }).catch((err) => {
- console.log(err);
- })
- }, 10);
- const collector = snipeChannel.createMessageCollector(filter, {time: 180000});
- collector.on('collect', async (m) => {
- console.log(`Collected ${m.content} | ${m.author.username}`);
- if (validation(allowedRoles.roles,m.member.roles.array()) || m.member.id === owner){
- if (m.content === ".start" || m.content === ".stop"){
- collector.stop();
- console.log("Collector stoped");
- return;
- }
- }
- if (game.data.length === 0 && m.content.length === 3){
- game.addID(m.content.toUpperCase(), m.author.username);
- }else if (m.content.length === 3){
- if (game.userPresent(m.author.username)){
- game.deleteUserEntry(m.author.username);
- if (game.idPresent(m.content.toUpperCase())){
- game.addUser(m.content.toUpperCase(), m.author.username);
- }else {
- game.addID(m.content.toUpperCase(),m.author.username);
- }
- } else {
- if (game.idPresent(m.content.toUpperCase())){
- game.addUser(m.content.toUpperCase(), m.author.username);
- }else {
- game.addID(m.content.toUpperCase(), m.author.username);
- }
- }
- }
- if(game.data.length >= 3){
- game.data = heapSort(game.data,0,game.data.length);
- }
- // game.sort();
- let str = "";
- let total = 0;
- let max_single = false;
- let max_normal = false;
- last3 = new Discord.RichEmbed()
- .setTitle("Last 3 code")
- .setColor("#030000");
- let single = Array();
- let str_single = "";
- for(var i = 0; i < game.data.length; i++){
- str = "";
- str2 = "none";
- for(var j = 0; j < game.data[i].users.length; j++){
- if(str.length < 900){
- str += game.data[i].users[j] + "\n";
- }else if(!max_normal){
- max_normal = true;
- str += "and more...";
- }
- }
- if(last3.fields.length === 24){
- last3 = new Discord.RichEmbed()
- .setColor("#030000");
- editLast3 = await snipeChannel2.send({embed: last3}).catch((err) => {
- console.log("cant send the new embed with extra entries");
- });
- //modifaction
- }else if(game.data[i].users.length > 1){
- last3.addField(`${game.data[i].id.toUpperCase()} - ${game.data[i].users.length} Players`, str, true);
- total += game.data[i].users.length;
- }else if(game.data[i].users.length === 1){
- single.push(`${game.data[i].id.toUpperCase()}: ${game.data[i].users[0]}`);
- }
- }
- for (var i = 0; i < single.length; i++){
- console.log("LENGTH: " + str_single.length)
- if (str_single.length < 900){
- str_single += single[i] + " | "
- }else if(!max_single){
- str_single += "and more...";
- max_single = true;
- }
- }
- if(single.length > 0){
- last3.addField('Singles:', str_single);
- }
- total += single.length;
- if(total === 0){
- total = 1;
- }
- last3.setFooter(`[Total Players: ${total} | Total Lobbies: ${last3.fields.length -1 + single.length}] | ReNotify
- ™`);
- if(last3.fields.length <= 1){
- setTimeout(() => {
- editLast3.edit({embed: last3}).catch((err) => {
- console.log("Caught an edit error");
- });
- }, 2000);
- }else if(last3.fields.length > 1){
- console.log("FIELDS: " + last3.fields.length);
- editLast3.edit({embed: last3}).catch((err) => {
- console.log("caught an edit error");
- });
- }
- // let playerCount = 0;
- // for (var i = 0; i < game.data.length; i++){
- // playerCount += game.data[i].users.length;
- // }
- // for (var i = 0; i < game.data.length; i++){
- // str = "";
- // for (var j = 0; j < game.data[i].users.length ; j++){
- // str += game.data[i].users[j] + "\n";
- // }
- // last3.addField(`${game.data[i].id.toUpperCase()} - ${game.data[i].users.length} Players`, str, true);
- // last3.setFooter(`${game.data.length} Servers, ${playerCount} Players | ReNotify™ | ${message.guild.name}`)
- // }
- // editLast3.edit({embed: last3}).catch((err) => {
- // console.log("Caught eddit error");
- // });
- if(m.content.substring(0,1) != `.` && m.deletable){
- m.delete().catch((err) => {
- console.log("cant delete!");
- console.log(err);
- })
- }
- });
- collector.on('end', collected => {
- console.log(`Collected ${collected.size} items`);
- let endMsg = new Discord.RichEmbed()
- .setTitle("No more codes accepted at this point")
- .setDescription("Enough time was given! channel :lock:")
- .setColor("#030000");
- snipeChannel.send({embed: endMsg});
- snipeChannel2.send({embed: endMsg});
- snipeChannel.overwritePermissions(message.guild.defaultRole, {
- SEND_MESSAGES: false
- }).catch((err) => {
- console.log(err);
- })
- });
- }
- module.exports.help = {
- name: "start"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement