import { Command, CommandoMessage, CommandoClient } from 'discord.js-commando'; import { MessageEmbed } from 'discord.js'; //@ts-ignore to types import emoji from 'emoji-random' import axios from 'axios' import config from '../../config.json' const platforms = ['pc', 'xbl', 'psn'] module.exports = class FortniteStatsUtility extends Command { constructor(client: CommandoClient) { super(client, { name: 'fortnitestats', aliases: [ 'fortnite-stats', 'fortnitestatistics', 'fortnite-statistics', 'fnstats', 'fn-stats', 'fnstatistics', 'fn-statistics', 'fns', 'fn-s', 'fortnite' ], group: 'utility', memberName: 'fortnitestats', description: 'Grabs a specified player\'s Fortnite statistics.', details: 'Available platforms are `pc` (PC), `xbp` (Xbox Live) and `psn` (Playstation Network).', examples: [ 'uwu!fortnitestats Frozen', 'uwu!fns Sin' ], userPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'], clientPermissions: ['SEND_MESSAGES', 'READ_MESSAGE_HISTORY'], throttling: { usages: 5, duration: 30 }, args: [ { key: 'pPlatform', prompt: 'What platform would you like to search on.', type: 'string', parse: (platform: string) => platform.toLowerCase(), oneOf: platforms }, { key: 'pUsername', prompt: 'What user would you like to look up?', type: 'string' } ] }); } //TODO: //@ts-ignore this is not async async run(msg: CommandoMessage, { pPlatform, pUsername }: any) { try { const stats = ( await axios .get(`https://api.fortnitetracker.com/v1/profile/${pPlatform}/${pUsername}`, { headers: { 'TRN-Api-Key': config.fortniteTrackerNetworkToken } }) .catch(err => { console.error(err) return msg.reply('Woops, There was an error with the (https://api.fortnitetracker.com) API. ' + emoji.random()) }) //@ts-ignore yes it does exist lmao ).data if (stats.error === 'Player Not Found') { return msg.reply('Specified player was not found on that platform. ' + emoji.random()) } console.debug(`Result for ${pUsername} on ${pPlatform}:`, stats) let emb = new MessageEmbed() .setTitle(stats.epicUserHandle) .setURL(`https://fortnitetracker.com/profile/${pPlatform}/${encodeURIComponent(pUsername)}`) .setColor(0xFFCC4D) .setFooter('Information providied by The Tracker Network.',) if (stats.lifeTimeStats[8] && stats.lifeTimeStats[9]) { emb.addField("🏆 Wins", `${stats.lifeTimeStats[8].value} wins (${stats.lifeTimeStats[9].value})`) } if (stats.lifeTimeStats[10] && stats.lifeTimeStats[11]) { emb.addField( "💀 Kills", `${stats.lifeTimeStats[10].value} kills. ${stats.lifeTimeStats[11].value} K/D ratio.` ); } if (stats.lifeTimeStats[7]) { emb.addField("🎮 Matches Played", stats.lifeTimeStats[7].value.toString()); } if (stats.lifeTimeStats[6]) { emb.addField("🔢 Score", stats.lifeTimeStats[6].value.toString()); } return msg.replyEmbed(emb); } finally { return msg.channel.stopTyping() } } };