Advertisement
Guest User

Untitled

a guest
Feb 18th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.85 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.  
  9. if(message.deletable) await message.delete()
  10.  
  11. let snipeChannel = message.guild.channels.find(c => c.name === "scrim-codes");
  12. let snipeChannel2 = message.guild.channels.find(c => c.name === "scrim-match");
  13.  
  14. snipeChannel.send(".count");
  15.  
  16. const filter = m => !m.author.bot;
  17. let game = new Listing();
  18.  
  19. //heapsort
  20. function heapSort(arr){
  21. var len = arr.length,
  22. end = len-1
  23.  
  24. heapify(arr, len);
  25.  
  26. while(end > 0){
  27. swap(arr,end--, 0);
  28. siftDown(arr, 0, end);
  29. }
  30. return arr;
  31. }
  32. function heapify(arr, len){
  33. // break the array into root + two sides, to create tree (heap)
  34. var mid = Math.floor((len-2)/2);
  35. while(mid >= 0){
  36. siftDown(arr, mid--, len-1);
  37. }
  38. }
  39. function siftDown(arr, start, end){
  40. var root = start,
  41. child = root*2 + 1,
  42. toSwap = root;
  43. while(child <= end){
  44. if(arr[toSwap].users.length > arr[child].users.length){
  45. swap(arr, toSwap, child+1)
  46. }
  47. if(toSwap != root){
  48. swap(arr, root, toSwap);
  49. root = toSwap;
  50. }
  51. else{
  52. return;
  53. }
  54. toSwap = root;
  55. child = root*2+1
  56. }
  57. }
  58. function swap(arr, i, j){
  59. var temp = arr[i];
  60. arr[i] = arr[j];
  61. arr[j] = temp;
  62. }
  63.  
  64.  
  65. let raw = fs.readFileSync('./roles.json');
  66. let allowedRoles = JSON.parse(raw);
  67.  
  68. let validation = function(serverRoles, userRoles){
  69. let val = false;
  70. serverRoles.forEach((role) => {
  71. userRoles.forEach((usr) => {
  72. if (role == usr){
  73. val = true;
  74. }
  75. });
  76. });
  77. return val;
  78. }
  79.  
  80. let gamemode = "SOLO";
  81.  
  82. if (args.length > 0){
  83. if (args[0].toUpperCase() === "SOLO" ||
  84. args[0].toUpperCase() === "DUOS" ||
  85. args[0].toUpperCase() === "SQUADS"){
  86. gamemode = args[0];
  87. }
  88. }
  89.  
  90. let editLast3 = null;
  91.  
  92. let startMessage = new Discord.RichEmbed()
  93. .setTitle("Fortnite Scrims")
  94. .setDescription("Please write the last 3 codes from you're Server Id")
  95. .addField("Gamemode", gamemode.toUpperCase())
  96. .setColor("#030000")
  97. .setFooter("ReNotify™");
  98. snipeChannel2.send({embed: startMessage});
  99. let codeCollect = new Discord.RichEmbed()
  100. .setTitle("Waiting for Server ID's")
  101. .setColor("#030000")
  102. snipeChannel.send({embed: codeCollect});
  103.  
  104. let time = 30;
  105. let editTime = "";
  106.  
  107. let timeEmbed = new Discord.RichEmbed()
  108. .setTitle("Next match in approx...")
  109. .setDescription(time + " minutes")
  110. .setColor("#030000");
  111.  
  112. setTimeout(async () => {
  113. editTime = await snipeChannel2.send({embed: timeEmbed}).catch( (err) => {
  114. console.log("Cant edit deleted message");
  115. });
  116. }, 10);
  117.  
  118. let timeInterval = setInterval(() => {
  119. if (time === 1){
  120. time -= 1;
  121. timeEmbed.setDescription(time + " minutes");
  122. clearInterval(timeInterval);
  123. }else {
  124. time -= 1;
  125. timeEmbed.setDescription(time + " minutes");
  126. }
  127.  
  128. editTime.edit({embed: timeEmbed}).catch((err) => {
  129. console.log("cant edit");
  130. clearInterval(timeInterval);
  131. });
  132.  
  133. },60000);
  134.  
  135. let last3 = new Discord.RichEmbed()
  136. .setTitle("Waiting for Server ID's")
  137. .setColor("#030000");
  138.  
  139. setTimeout(async () => {
  140. editLast3 = await snipeChannel2.send({embed: last3});
  141.  
  142. snipeChannel.overwritePermissions(message.guild.defaultRole, {
  143. SEND_MESSAGES: true
  144. }).catch((err) => {
  145. console.log(err);
  146. })
  147. }, 10);
  148.  
  149. const collector = snipeChannel.createMessageCollector(filter, {time: 180000});
  150.  
  151. collector.on('collect', async (m) => {
  152.  
  153. console.log(`Collected ${m.content} | ${m.author.username}`);
  154.  
  155. if (validation(allowedRoles.roles,m.member.roles.array()) || m.member.id === owner){
  156. if (m.content === ".start" || m.content === ".stop"){
  157. collector.stop();
  158. console.log("Collector stoped");
  159. return;
  160. }
  161. }
  162.  
  163. if (game.data.length === 0 && m.content.length === 3){
  164. game.addID(m.content.toUpperCase(), m.author.username);
  165. }else if (m.content.length === 3){
  166. if (game.userPresent(m.author.username)){
  167. game.deleteUserEntry(m.author.username);
  168. if (game.idPresent(m.content.toUpperCase())){
  169. game.addUser(m.content.toUpperCase(), m.author.username);
  170. }else {
  171. game.addID(m.content.toUpperCase(),m.author.username);
  172. }
  173. } else {
  174. if (game.idPresent(m.content.toUpperCase())){
  175. game.addUser(m.content.toUpperCase(), m.author.username);
  176. }else {
  177. game.addID(m.content.toUpperCase(), m.author.username);
  178. }
  179. }
  180. }
  181. if(game.data.length >= 3){
  182. game.data = heapSort(game.data,0,game.data.length);
  183. }
  184.  
  185. // game.sort();
  186.  
  187. let str = "";
  188. let total = 0;
  189. let max_single = false;
  190. let max_normal = false;
  191. last3 = new Discord.RichEmbed()
  192. .setTitle("Last 3 code")
  193. .setColor("#030000");
  194.  
  195. let single = Array();
  196. let str_single = "";
  197. for(var i = 0; i < game.data.length; i++){
  198. str = "";
  199. str2 = "none";
  200. for(var j = 0; j < game.data[i].users.length; j++){
  201. if(str.length < 900){
  202. str += game.data[i].users[j] + "\n";
  203. }else if(!max_normal){
  204. max_normal = true;
  205. str += "and more...";
  206. }
  207. }
  208. if(last3.fields.length === 24){
  209. last3 = new Discord.RichEmbed()
  210. .setColor("#030000");
  211. editLast3 = await snipeChannel2.send({embed: last3}).catch((err) => {
  212. console.log("cant send the new embed with extra entries");
  213. });
  214. //modifaction
  215. }else if(game.data[i].users.length > 1){
  216. last3.addField(`${game.data[i].id.toUpperCase()} - ${game.data[i].users.length} Players`, str, true);
  217. total += game.data[i].users.length;
  218. }else if(game.data[i].users.length === 1){
  219. single.push(`${game.data[i].id.toUpperCase()}: ${game.data[i].users[0]}`);
  220. }
  221. }
  222. for (var i = 0; i < single.length; i++){
  223. console.log("LENGTH: " + str_single.length)
  224. if (str_single.length < 900){
  225. str_single += single[i] + " | "
  226. }else if(!max_single){
  227. str_single += "and more...";
  228. max_single = true;
  229. }
  230. }
  231. if(single.length > 0){
  232. last3.addField('Singles:', str_single);
  233. }
  234. total += single.length;
  235. if(total === 0){
  236. total = 1;
  237. }
  238. last3.setFooter(`[Total Players: ${total} | Total Lobbies: ${last3.fields.length -1 + single.length}] | ReNotify
  239.  
  240. ™`);
  241.  
  242. if(last3.fields.length <= 1){
  243. setTimeout(() => {
  244. editLast3.edit({embed: last3}).catch((err) => {
  245. console.log("Caught an edit error");
  246. });
  247. }, 2000);
  248. }else if(last3.fields.length > 1){
  249. console.log("FIELDS: " + last3.fields.length);
  250. editLast3.edit({embed: last3}).catch((err) => {
  251. console.log("caught an edit error");
  252. });
  253. }
  254.  
  255.  
  256.  
  257. // let playerCount = 0;
  258. // for (var i = 0; i < game.data.length; i++){
  259. // playerCount += game.data[i].users.length;
  260. // }
  261. // for (var i = 0; i < game.data.length; i++){
  262. // str = "";
  263. // for (var j = 0; j < game.data[i].users.length ; j++){
  264. // str += game.data[i].users[j] + "\n";
  265. // }
  266. // last3.addField(`${game.data[i].id.toUpperCase()} - ${game.data[i].users.length} Players`, str, true);
  267. // last3.setFooter(`${game.data.length} Servers, ${playerCount} Players | ReNotify™ | ${message.guild.name}`)
  268. // }
  269. // editLast3.edit({embed: last3}).catch((err) => {
  270. // console.log("Caught eddit error");
  271. // });
  272.  
  273. if(m.content.substring(0,1) != `.` && m.deletable){
  274. m.delete().catch((err) => {
  275. console.log("cant delete!");
  276. console.log(err);
  277. })
  278. }
  279.  
  280. });
  281.  
  282. collector.on('end', collected => {
  283. console.log(`Collected ${collected.size} items`);
  284.  
  285. let endMsg = new Discord.RichEmbed()
  286. .setTitle("No more codes accepted at this point")
  287. .setDescription("Enough time was given! channel :lock:")
  288. .setColor("#030000");
  289.  
  290. snipeChannel.send({embed: endMsg});
  291. snipeChannel2.send({embed: endMsg});
  292.  
  293. snipeChannel.overwritePermissions(message.guild.defaultRole, {
  294. SEND_MESSAGES: false
  295. }).catch((err) => {
  296. console.log(err);
  297. })
  298.  
  299. });
  300.  
  301.  
  302. }
  303.  
  304.  
  305.  
  306. module.exports.help = {
  307. name: "start"
  308. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement