Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
3,068
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.23 KB | None | 0 0
  1. const Discord = require('discord.js'); // This is making sure that node has the package 'discord.js' installed
  2. const config = require("../config.json");
  3. const moment = require('moment');
  4. const Enmap = require("enmap");
  5. const ms = require("ms");
  6. const https = require("https");
  7. exports.run = (client, message, args) => {
  8. if(message.channel.name == undefined) return message.author.send(`can't use commands in dms`)
  9. let name = args.join(" ")
  10. channel = message.channel;
  11. name.trim()
  12. var spicupper = name.toUpperCase();
  13. var spiclower = name.toLowerCase();
  14. var epiclower = name.toLowerCase();
  15. var epicupper = name.toUpperCase();
  16. var clown = client.emojis.find("name", "clown");
  17. var dancing = client.emojis.find("name", "ClownDancing");
  18. var lite = client.emojis.find("name", "Lite");
  19. const NotAllowedWords = {
  20. "color": 10038562,
  21. "description": `${name} has not allowed words ${lite} in it's name.`,
  22. "thumbnail": {
  23. "url": ''
  24. },
  25. "author": {
  26. "name": `You have banned words in ${name} ${clown}.`,
  27. "url": '',
  28. "icon_url": message.author.avatarURL
  29. },
  30. "footer": {
  31. "icon_url": client.user.avatarURL,
  32. "text": client.user.tag
  33. },
  34. "fields": [{
  35. "name": `Your Account does exist${dancing}?`,
  36. "value": `Go on [fortnitetracker.com](https://fortnitetracker.com/profile/search?q=) and try to search your Account.\n This is using the fortnite tracker api so sometimes it won't work.`
  37. }]
  38. };
  39. if (epiclower.includes('epic') && name.toLowerCase() == "epic")
  40. {
  41. return message.channel.send({ embed: NotAllowedWords }) //corection is that the code will still go if it doesn't stop there
  42. }
  43. if (epicupper.includes('EPIC') && name.toUpperCase() == "EPIC")
  44. {
  45. return message.channel.send({ embed: NotAllowedWords })
  46. }
  47. if (spicupper.includes('SPIC') && name.toUpperCase() == "SPIC")
  48. {
  49. return message.channel.send({ embed: NotAllowedWords })
  50. }
  51. if (spiclower.includes('spic') && name.toLowerCase() == "spic")
  52. {
  53. return message.channel.send({ embed: NotAllowedWords })
  54. }
  55. const tolong = {
  56. "color": 12320855,
  57. "description": `${name} has to many characters${dancing}. ${clown}`,
  58. "thumbnail": {
  59. "url": ''
  60. },
  61. "author": {
  62. "name": `You have a lot of characters in ${name}.`,
  63. "url": '',
  64. "icon_url": message.author.avatarURL
  65. },
  66. "footer": {
  67. "icon_url": client.user.avatarURL,
  68. "text": client.user.tag
  69. },
  70. "fields": [{
  71. "name": `Your Account does exist${clown}?`,
  72. "value": `Go on [fortnitetracker.com](https://fortnitetracker.com/profile/search?q=) and try to search your Account.\n This is using the fortnite tracker api so sometimes it won't work.`
  73. }]
  74. };
  75. const lesscharacters = {
  76. "color": 12745742,
  77. "description": `${name} more characters needed. ${clown}`,
  78. "thumbnail": {
  79. "url": ''
  80. },
  81. "author": {
  82. "name": `You put only below 3 ${dancing} characters, please add more.`,
  83. "url": '',
  84. "icon_url": message.author.avatarURL
  85. },
  86. "footer": {
  87. "icon_url": client.user.avatarURL,
  88. "text": client.user.tag
  89. },
  90. "fields": [{
  91. "name": "Your Account does exist?",
  92. "value": `Go on [fortnitetracker.com](https://fortnitetracker.com/profile/search?q=) and try to search your Account.\n This is using the fortnite tracker api so sometimes it won't work.`
  93. }]
  94. };
  95. const notallowed = {
  96. "color": 15844367,
  97. "description": `**${name}** has characters ${dancing} that aren't allowed. ${clown}`,
  98. "thumbnail": {
  99. "url": ''
  100. },
  101. "author": {
  102. "name": 'The characters you put are not allowed in a epic Display name.',
  103. "url": '',
  104. "icon_url": message.author.avatarURL
  105. },
  106. "footer": {
  107. "icon_url": client.user.avatarURL,
  108. "text": client.user.tag
  109. },
  110. "fields": [{
  111. "name": "Your Account does exist?",
  112. "value": `Go on [fortnitetracker.com](https://fortnitetracker.com/profile/search?q=) and try to search your Account.\n This is using the fortnite tracker api so sometimes it won't work.`
  113. }]
  114. };
  115. var notallowedcharacters = ['/', '|', '{', '}', '[', ']', `'`, ";", ':', '"', '.', ',', '?', '>', '<', '~', '`', '-', '+', '=']
  116. if (name.length > 16) {
  117. return message.channel.send({ embed: tolong })
  118. }
  119. if (name.length < 3) {
  120. return message.channel.send({ embed: lesscharacters })
  121. }
  122. if(!name) return message.channel.send('Please mention a player name.')
  123. var PCoptions = {
  124. host: 'api.fortnitetracker.com',
  125. path: '/v1/profile/pc/' + encodeURIComponent(name),
  126. port: 443, // isnt this used for mail?
  127. method: 'GET',
  128. headers: { 'TRN-Api-Key': "" }
  129. };
  130. var req = https.request(PCoptions, function(res){
  131. var body = "";
  132. res.on('data', function(data){
  133. body += data;
  134. });
  135. res.on('end', end => {
  136. body = JSON.parse(body)
  137.  
  138. var ControllerSettings = {
  139. host: 'api.fortnitetracker.com',
  140. path: '/v1/profile/psn/' + encodeURIComponent(name),
  141. port: 443, // isnt this used for mail?
  142. method: 'GET',
  143. headers: { 'TRN-Api-Key': "" }
  144. };
  145. var ControllerReq = https.request(ControllerSettings, function(ControllerRes){
  146. var ControllerBody = "";
  147. ControllerRes.on('data', function(data){
  148. ControllerBody += data;
  149. });
  150. ControllerRes.on('end', end => {
  151. ControllerBody = JSON.parse(ControllerBody)
  152. const Canceled = {
  153. "color": 2605136,
  154. "description": `The Selection was successfully aborted. ${dancing}`,
  155. "thumbnail": {
  156. "url": ''
  157. },
  158. "author": {
  159. "name": 'Selection aborted',
  160. "url": '',
  161. "icon_url": message.author.avatarURL
  162. },
  163. "footer": {
  164. "icon_url": client.user.avatarURL,
  165. "text": client.user.tag
  166. },
  167. };
  168.  
  169. const TookToLong = {
  170. "color": 16777215,
  171. "description": `The Selection was aborted after 20 seconds ${dancing}.`,
  172. "thumbnail": {
  173. "url": ''
  174. },
  175. "author": {
  176. "name": 'Selection aborted',
  177. "url": '',
  178. "icon_url": message.author.avatarURL
  179. },
  180. "footer": {
  181. "icon_url": client.user.avatarURL,
  182. "text": client.user.tag
  183. },
  184. };
  185. const CONTROLLERNOTFOUND = {
  186. "color": 13182319,
  187. "description": `A player account with the name **${name}** on playstation ${dancing} does not exist. ${clown}`,
  188. "thumbnail": {
  189. "url": ''
  190. },
  191. "author": {
  192. "name": 'Account not found on playstation.',
  193. "url": '',
  194. "icon_url": message.author.avatarURL
  195. },
  196. "footer": {
  197. "icon_url": client.user.avatarURL,
  198. "text": client.user.tag
  199. },
  200. "fields": [{
  201. "name": "Your Account wasn't found?",
  202. "value": `Go on [fortnitetracker.com](https://fortnitetracker.com/profile/search?q=) and try to search your Account.\n This is using the fortnite tracker api so sometimes it won't work.`
  203. }]
  204. };
  205. const PCACCOUNTNOTFOUND = {
  206. "color": 10694957,
  207. "description": `A player account with the name **${name}** on pc ${lite} does not exist. ${clown}`,
  208. "thumbnail": {
  209. "url": ''
  210. },
  211. "author": {
  212. "name": 'Account not found on pc.',
  213. "url": '',
  214. "icon_url": message.author.avatarURL
  215. },
  216. "footer": {
  217. "icon_url": client.user.avatarURL,
  218. "text": client.user.tag
  219. },
  220. "fields": [{
  221. "name": "Your Account wasn't found?",
  222. "value": `Go on [fortnitetracker.com](https://fortnitetracker.com/profile/search?q=) and try to search your Account.\n This is using the fortnite tracker api so sometimes it won't work.`
  223. }]
  224. };
  225.  
  226. // player not found
  227.  
  228. var loading = client.emojis.find(emoji => emoji.name === "Loading")
  229. var PC = client.emojis.find(emoji => emoji.name === "PC")
  230. var Controller = client.emojis.find(emoji => emoji.name === "Controller")
  231. var Touch = client.emojis.find(emoji => emoji.name === "Touch")
  232. var Cancel = client.emojis.find(emoji => emoji.name === "Cancel")
  233. const embed = {
  234. "color": 65280,
  235. "title": `Fetching Stats ${loading}`,
  236. };
  237. const Pick = {
  238. "color": 15844367,
  239. "description": "Please select the input type you want stats from.\n\n " + dancing + " Update: ``Touch is now removed because it's not supported.``\n\n" + `${PC} - Keyboard And Mouse \n${Controller} - PlayStation\n\n use ${Cancel} to cancel`,
  240. "thumbnail": {
  241. "url": ''
  242. },
  243. "author": {
  244. "name": 'Select the input type!',
  245. "url": client.user.avatarURL,
  246. "icon_url": ''
  247. },
  248. "footer": {
  249. "icon_url": client.user.avatarURL,
  250. "text": 'chingchon'
  251. },
  252. };
  253. var emoji = client.emojis.find(emoji => emoji.name === "for8349680231204859k9443")
  254. const reactionFilter = (reaction, user) => reaction.emoji.name === 'for8349680231204859k9443';
  255. message.channel.send(clown.name).then(msg => msg.delete(10))
  256. const sentmessage = message.channel.send(`${clown} ${lite} ${clown} ${lite} ${clown} ${lite} ${clown} ${lite} ${clown} ${lite} ${clown} ${lite} ${clown} ${lite} ${clown} ${lite} ${clown} ${lite} ${clown} ${lite} ${clown} ${lite} ${clown} ${lite} ${clown} ${lite} ${clown} ${lite} ${clown} ${lite} ${clown} ${lite} ${clown} ${lite} ${clown} ${lite} ${clown} ${lite} ${clown}`)
  257.  
  258. .then(msg => msg.edit({ embed: embed })).then(msg => msg.edit({ embed: Pick }))
  259. .then(message2 => {
  260.  
  261. message2.react(Cancel)
  262. .then(() => message2.react(PC))
  263. .then(() => message2.react(Controller))
  264. .catch(() => console.error('One of the emojis failed to react.'));
  265.  
  266. const filter = (reaction, user) => reaction.emoji.name === PC.name && user.id === message.author.id;
  267. const Controllerfilter = (reaction, user) => reaction.emoji.name === Controller.name && user.id === message.author.id;
  268. const Cancelfilter = (reaction, user) => reaction.emoji.name === Cancel.name && user.id === message.author.id;
  269.  
  270. message2.awaitReactions(Cancelfilter, { max: 1, time: 20000, errors: ['time'] })
  271. .then(collected => {
  272. const reaction = collected.first();
  273. let user = message.author;
  274. if (!user.bot) {
  275.  
  276. if (reaction.emoji.name === Cancel.name) {
  277. return message2.edit({ embed: Canceled }),
  278. message2.reactions.array().forEach(r => {
  279. r.remove();
  280. });
  281. req.end(),
  282. ControllerReq.end();
  283. }
  284. }
  285. })
  286. .catch(collected => {
  287. message2.edit({ embed: TookToLong })
  288. message2.reactions.array().forEach(r => {
  289. r.remove();
  290. });
  291. });
  292.  
  293.  
  294. message2.awaitReactions(Controllerfilter, { max: 1, time: 20000, errors: ['time'] })
  295. .then(collected => {
  296. const reaction = collected.first();
  297. let user = message.author;
  298. if (!user.bot) {
  299.  
  300. if (reaction.emoji.name === Controller.name) {
  301. if(ControllerBody.error){
  302. message2.edit({ embed: CONTROLLERNOTFOUND })
  303. message2.reactions.array().forEach(r => {
  304. r.remove();
  305. });
  306. return;
  307. }
  308.  
  309. // player found
  310. var epicName = ControllerBody["epicUserHandle"];
  311. var platform = ControllerBody["platformName"];
  312. var score = ControllerBody.lifeTimeStats[6]["value"];
  313. var matchesPlayed = ControllerBody.lifeTimeStats[7]["value"];
  314. var wins = ControllerBody.lifeTimeStats[8]["value"];
  315. //var timePlayed = body.lifeTimeStats[13]["value"]; // removed from API?
  316. var wr = ControllerBody.lifeTimeStats[9]["value"];
  317. var kills = ControllerBody.lifeTimeStats[10]["value"];
  318. var kd = ControllerBody.lifeTimeStats[11]["value"];
  319. //var killsPerMin = body.lifeTimeStats[12]["value"];
  320. var ControllerURL = "https://fortnitetracker.com/profile/psn/"
  321. + encodeURIComponent(name);
  322. const newEmbed = {
  323. "color": 5301186,
  324. "timestamp": new Date(),
  325. "thumbnail": {
  326. "url": message.author.avatarURL
  327. },
  328. "author": {
  329. "name": epicName + ', Controller Stats',
  330. "url": ControllerURL,
  331. "icon_url": message.author.avatarURL
  332. },
  333. "footer": {
  334. "icon_url": client.user.avatarURL,
  335. "text": client.user.tag
  336. },
  337. "fields": [{
  338. "name": "Wins",
  339. "value": wins
  340. },
  341. {
  342. "name": "Matches Played",
  343. "value": matchesPlayed
  344. },
  345. {
  346. "name": "Kills",
  347. "value": kills
  348. },
  349. {
  350. "name": "Score/Match",
  351. "value": score
  352. },
  353. {
  354. "name": "Win Rate",
  355. "value": wr
  356. },
  357. {
  358. "name": "Platform",
  359. "value": platform
  360. },
  361. {
  362. "name": "Kills/Match",
  363. "value": kd
  364. },
  365. {
  366. "name": "Link",
  367. "value": ControllerURL
  368. },
  369. {
  370. "name": "API",
  371. "value": 'The api used to make this is the fortnite tracker api.' + `${clown}`
  372. }]
  373. };
  374.  
  375. message2.edit({ embed: newEmbed });
  376. message2.reactions.array().forEach(r => {
  377. r.remove();
  378. });
  379. }
  380. }
  381. })
  382. .catch(collected => {
  383. message2.edit({ embed: TookToLong })
  384. message2.reactions.array().forEach(r => {
  385. r.remove();
  386. });
  387. });
  388.  
  389. message2.awaitReactions(filter, { max: 1, time: 20000, errors: ['time'] })
  390. .then(collected => {
  391. const reaction = collected.first();
  392. let user = message.author;
  393. if (!user.bot) {
  394.  
  395. if (reaction.emoji.name === PC.name) {
  396.  
  397. if(body.error){
  398. message2.edit({ embed: PCACCOUNTNOTFOUND })
  399. message2.reactions.array().forEach(r => {
  400. r.remove();
  401. });
  402. return;
  403. }
  404.  
  405. // player found
  406. var epicName = body["epicUserHandle"];
  407. var platform = body["platformName"];
  408. var score = body.lifeTimeStats[6]["value"];
  409. var matchesPlayed = body.lifeTimeStats[7]["value"];
  410. var wins = body.lifeTimeStats[8]["value"];
  411. //var timePlayed = body.lifeTimeStats[13]["value"]; // removed from API?
  412. var wr = body.lifeTimeStats[9]["value"];
  413. var kills = body.lifeTimeStats[10]["value"];
  414. var kd = body.lifeTimeStats[11]["value"];
  415. //var killsPerMin = body.lifeTimeStats[12]["value"];
  416. var url = "https://fortnitetracker.com/profile/pc/"
  417. + encodeURIComponent(name);
  418.  
  419. var msg = "";
  420. msg += "\nwins: " + wins;
  421. msg += "\ngames: " + matchesPlayed;
  422. msg += "\nwinrate: " + wr;
  423. msg += "\n\nkills: " + kills /* + " (" + killsPerMin + "/min)"*/ ;
  424. msg += "\nkd: " + kd;
  425. //msg += "\n\nplaytime: " + 0h; // disabled for a long time
  426. const newEmbed = {
  427. "color": 5301186,
  428. "timestamp": new Date(),
  429. "thumbnail": {
  430. "url": message.author.avatarURL
  431. },
  432. "author": {
  433. "name": epicName,
  434. "url": url,
  435. "icon_url": message.author.avatarURL
  436. },
  437. "footer": {
  438. "icon_url": client.user.avatarURL,
  439. "text": client.user.tag
  440. },
  441. "fields": [{
  442. "name": "Wins",
  443. "value": wins
  444. },
  445. {
  446. "name": "Matches Played",
  447. "value": matchesPlayed
  448. },
  449. {
  450. "name": "Kills",
  451. "value": kills
  452. },
  453. {
  454. "name": "Score/Match",
  455. "value": score
  456. },
  457. {
  458. "name": "Win Rate",
  459. "value": wr
  460. },
  461. {
  462. "name": "Platform",
  463. "value": platform
  464. },
  465. {
  466. "name": "Kills/Match",
  467. "value": kd
  468. },
  469. {
  470. "name": "Link",
  471. "value": url
  472. },
  473. {
  474. "name": "API",
  475. "value": 'The api used to make this is the fortnite tracker api.' + `${clown}`
  476. }]
  477. };
  478.  
  479. message2.edit({ embed: newEmbed });
  480. message2.reactions.array().forEach(r => {
  481. r.remove();
  482. });
  483. }
  484. }
  485. })
  486. .catch(collected => {
  487. message2.edit({ embed: TookToLong })
  488. message2.reactions.array().forEach(r => {
  489. r.remove();
  490. });
  491. });
  492. })
  493. });
  494. });
  495. ControllerReq.end();
  496. });
  497. });
  498. req.end();
  499.  
  500. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement