Advertisement
Guest User

rwejrkl;k

a guest
Feb 17th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.67 KB | None | 0 0
  1. const Discord = require('discord.js');
  2. const Listing = require('./../modules/Listing')
  3. const fs = require('fs');
  4. const settings = require('./../settings.json');
  5. const owner = settings.owner;
  6.  
  7. module.exports.run = async(bot, message, args) => {
  8. let snipeChannel = message.channel;
  9. const filter = m => !m.author.bot;
  10. let game = new Listing();
  11.  
  12. let raw = fs.readFileSync('./roles.json');
  13. let allowedRoles = JSON.parse(raw);
  14.  
  15. let validation = function(serverRoles, userRoles){
  16. let val = false;
  17. serverRoles.forEach((role) => {
  18. userRoles.forEach((usr) => {
  19. if (role === usr){
  20. val = true;
  21. }
  22. });
  23. });
  24. return val;
  25. }
  26.  
  27. let editLast3 = null;
  28.  
  29. let startMessage = new Discord.RichEmbed()
  30. .setTitle("Fortnite Scrims")
  31. .setDescription("Please put your last 3 codes from your server ID")
  32. .setColor("#1dbbf9")
  33. .setFooter("Bas is cute");
  34.  
  35. message.channel.send({embed: startMessage});
  36.  
  37. let time = 25;
  38. let editTime = "";
  39.  
  40. let timeEmbed = new Discord.RichEmbed()
  41. .setTitle("Next match in aprox...")
  42. .setDescription(time + " minutes")
  43. .setColor("#1dbbf9");
  44.  
  45. setTimeout(async () => {
  46. editTime = await message.channel.send({embed: timeEmbed}).catch( (err) => {
  47. console.log("Cant edit deleted message.")
  48. });
  49. }, 10);
  50.  
  51. let timeInterval = setInterval(() => {
  52. if (time === 1){
  53. time -= 1;
  54. timeEmbed.setDescription(time + " minutes");
  55. clearInterval(timeInterval);
  56. } else {
  57. time -= 1;
  58. timeEmbed.setDescription(time + " minutes")
  59. }
  60.  
  61. editTime.edit({embed: timeEmbed}).catch((err) => {
  62. console.log("cant edit")
  63. clearInterval(timeInterval);
  64. });
  65.  
  66. },60000);
  67.  
  68. let last3 = new Discord.RichEmbed()
  69. .setTitle("Last 3 code")
  70. .setColor("#1dbbf9");
  71.  
  72. setTimeout(async () => {
  73. editLast3 = await message.channel.send({embed: last3});
  74.  
  75. }, 10);
  76.  
  77. const collector = snipeChannel.createMessageCollector(filter, {max: 200, maxMatches: 200, time: 180000});
  78.  
  79. collector.on('collect', m => {
  80. console.log(`Collected ${m.content} | ${m.author.username}`);
  81.  
  82.  
  83. if (validation(allowedRoles.roles,m.member.roles.array()) | m.member.id === owner){
  84. if (m.content === "!start" || m.content === "!stop"){
  85. collector.stop();
  86. console.log("Collector stopped");
  87. }
  88. }
  89. if (game.data.length === 0 && m.length === 3){
  90. game.addID(m.content.toUpperCase(), m.author.username);
  91. }else if (m.content.length === 3){
  92. if (game.userPresent(m.author.username)){
  93. game.deleteUserEntry(m.author.username);
  94. if (game.idPresent(m.content.toUpperCase())){
  95. game.addUser(m.content.toUpperCase(), m.author.username);
  96. }else{
  97. game.addID(m.content.toUpperCase(), m.author.username);
  98. }
  99. } else {
  100. if (game.idPresent(m.content.toUpperCase())){
  101. game.addUser(m.content.toUpperCase(), m.author.username);
  102. }else {
  103. game.addID(m.content.toUpperCase(), m.author.username);
  104. }
  105. }
  106. }
  107.  
  108.  
  109. game.sort();
  110.  
  111. let str = "";
  112. last3 = new Discord.RichEmbed()
  113. .setTitle ("Last 3 code")
  114. .setColor("#1dbbf9");
  115.  
  116. for (var i = 0; i < game.data.length; i++){
  117. str = "";
  118. for(var j = 0; j < game.data[i] .users.length ; j++){
  119. str += game.data[i].users[j] + "\n";
  120.  
  121. }
  122. last3.addField(`${game.data[i].id.toUpperCase()} - ${game.data[i].users.length} PLAYERS`, str, true);
  123. }
  124.  
  125. editLast3.edit({embed: last3}).catch((err) => {
  126. console.log("Caught a edit error.");
  127. });
  128.  
  129. if (m.deletable){
  130. m.delete().catch((err) => {
  131. console.log("Cant delete")
  132. console.log(err);
  133. });
  134. }
  135. });
  136.  
  137. collector.on('end', collected => {
  138. console.log(`Collected ${collected.size} items`);
  139.  
  140. let endMessage = new Discord.RichEmbed()
  141. .setTitle("No more codes accepted at this point")
  142. .setDescription("Good luck and have fun in your game!")
  143. .setColor("#ff0000");
  144.  
  145. message.channel.send({embed: endMessage});
  146.  
  147. });
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154. }
  155.  
  156.  
  157.  
  158. module.exports.help = {
  159. name: "start"
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement