· 5 years ago · Jul 09, 2020, 11:14 PM
1const BaseCommand = require('../../utils/structures/BaseCommand');
2const config = require("../../../config.json");
3const ApexTab = require("apexlegendsjs");
4const Discord = require('discord.js');
5const registry = require('../../utils/registry');
6
7
8module.exports = class ApexstatsCommand extends BaseCommand {
9 constructor() {
10 super('apexstats', 'stats', []);
11 }
12
13 run(client, message, args, data) {
14 if(!config.trackergg || config.trackergg.length === ""){
15 return message.channel.send("Unable to find command");
16 }
17
18 //Create a new ApexTab using the API key
19 let apexStats = new ApexTab(config.trackergg);
20
21 //Get the platform the user entered
22 let platform = args[0] ? args[0].toUpperCase() : "PC";
23
24 //If the platform isn't the following then return error message
25 if((platform != "PC" && platform != "XBOX" && platform != "PSN")){
26 return message.channel.send("Please mention a valid platform (PC, XBOX or PSN)");
27 }
28
29 //Get the username
30 let user = args.slice(1).join(" ");
31 //If there isn't a username return error
32 if(!user){
33 return message.channel.send("Please mention a valid username");
34 }
35
36
37 //Get the users data using the username and platform
38 apexStats.getDetailedPlayer(user, platform)
39 .then((dataPulled)=>{
40 let level = dataPulled.metadata.level;
41 let rankName = dataPulled.metadata.rankName;
42 let rankImage = dataPulled.metadata.rankImage;
43 let playerImage = dataPulled.metadata.avatarUrl;
44
45 // Add the userdata to an embed
46 let embed = new Discord.MessageEmbed()
47 .setAuthor(`Apex data for ${dataPulled.metadata.platformUserHandle} on ${platform}`, playerImage)
48 .setThumbnail(rankImage)
49 .addFields(
50 { name: `Rank`, value: rankName},
51 { name: `Level`, value: level}
52 )
53
54 let i = 0;
55 let arrSize = dataPulled.stats;
56
57 for (i = 0; i < arrSize.length; i++) {
58 if(dataPulled.stats[i].value <= 0){
59
60 }else if(dataPulled.stats[i].value >= 1){
61
62 embed.addFields({ name: dataPulled.stats[i].metadata.name, value: dataPulled.stats[i].value})
63 }
64 }
65 embed.setColor(config.color)
66 .setFooter(config.footer);
67 //send the embed
68 return message.channel.send(embed);
69
70
71 })
72 .catch((err)=>{
73 console.log(err)
74 return message.channel.send("ERROR! Unable to find this user. Please try again")
75 })
76 }
77}