From 64241febaebf230a71220b36984477530ffcc727 Mon Sep 17 00:00:00 2001 From: tresabhi Date: Sat, 22 Apr 2023 01:51:23 +0000 Subject: [PATCH] feat: actual stats --- src/behaviors/guildMemberAdd.ts | 4 +- src/commands/stats.ts | 141 +++++++++++++++++++------------- 2 files changed, 84 insertions(+), 61 deletions(-) diff --git a/src/behaviors/guildMemberAdd.ts b/src/behaviors/guildMemberAdd.ts index 6846abfe2..c3ad772b3 100644 --- a/src/behaviors/guildMemberAdd.ts +++ b/src/behaviors/guildMemberAdd.ts @@ -9,6 +9,7 @@ export default async function (member: GuildMember) { await ( member.guild.channels.cache.get(discord.verify_channel) as TextChannel ).send({ + content: member.toString(), embeds: [ new EmbedBuilder() .setColor(SKILLED_COLOR) @@ -22,7 +23,4 @@ export default async function (member: GuildMember) { ), ], }); - await ( - member.guild.channels.cache.get(discord.verify_channel) as TextChannel - ).send(member.toString()); } diff --git a/src/commands/stats.ts b/src/commands/stats.ts index df219ff29..ca8fa0546 100644 --- a/src/commands/stats.ts +++ b/src/commands/stats.ts @@ -5,7 +5,7 @@ import { SlashCommandBuilder, } from 'discord.js'; import fetch from 'node-fetch'; -import { SKILLED_COLOR } from '../constants/colors.js'; +import { NEGATIVE_COLOR, SKILLED_COLOR } from '../constants/colors.js'; import { SERVERS } from '../constants/servers.js'; import { PlayerStatistics } from '../types/statistics.js'; import getBlitzAccount from '../utilities/getBlitzAccount.js'; @@ -23,65 +23,90 @@ export async function execute( | 'career'; getBlitzAccount(interaction, ign, server, async (account) => { - const data = (await ( - await fetch( - `https://www.blitzstars.com/api/top/player/${account.account_id}`, - ) - ).json()) as PlayerStatistics; - const stats = - period === 'career' ? data.statistics : data[`period${period}d`]; + fetch(`https://www.blitzstars.com/api/top/player/${account.account_id}`) + .then(async (response) => { + const data = (await response.json()) as PlayerStatistics; + const stats = + period === 'career' ? data.statistics : data[`period${period}d`]; - interaction.reply({ - embeds: [ - new EmbedBuilder() - .setColor(SKILLED_COLOR) - .setTitle( - `${data.nickname}'s ${ - period === 'career' ? period : `${period} day` - } stats`, - ) - .setDescription( - `${[ - ['Winrate', `${stats.special.winrate.toFixed(2)}%`], - ['Survival', `${stats.special.survivalRate.toFixed(2)}%`], - [ - 'Accuracy', - `${((stats.all.hits / stats.all.shots) * 100).toFixed(2)}%`, - ], - ['WN8', stats.wn8.toFixed(0)], - ['WN7', stats.wn7.toFixed(0)], - [], - ['Battles', stats.all.battles], - ['Wins', stats.all.wins], - ['Losses', stats.all.losses], - ['Average tier', stats.avg_tier.toFixed(2)], - [], - ['Hits per battle', stats.special.hpb.toFixed(0)], - ['Damage per battle', stats.special.dpb.toFixed(0)], - ['Kills per battle', stats.special.kpb.toFixed(2)], - ['Spots per battle', stats.special.spb.toFixed(2)], - [ - 'Shots per battle', - (stats.all.shots / stats.all.battles).toFixed(2), - ], - [ - 'Hits per battle', - (stats.all.hits / stats.all.battles).toFixed(2), - ], - ['XP per battle', (stats.all.xp / stats.all.battles).toFixed(2)], - [], - ['Damage ratio', stats.special.damageRatio.toFixed(2)], - ['Kills to death ratio', stats.special.kdr.toFixed(2)], - ] - .map((array) => - array.length === 0 ? '' : `**${array[0]}**: ${array[1]}`, + interaction.reply({ + content: 'ass', + embeds: [ + new EmbedBuilder() + .setColor(SKILLED_COLOR) + .setTitle( + `${data.nickname}'s ${ + period === 'career' ? period : `${period} day` + } stats`, ) - .join( - '\n', - )}\n\nPowered by [BlitzStars](https://www.blitzstars.com/)`, - ), - ], - }); + .setDescription( + `${[ + ['Winrate', `${stats.special.winrate.toFixed(2)}%`], + ['Survival', `${stats.special.survivalRate.toFixed(2)}%`], + [ + 'Accuracy', + `${((stats.all.hits / stats.all.shots) * 100).toFixed(2)}%`, + ], + ['WN8', stats.wn8.toFixed(0)], + ['WN7', stats.wn7.toFixed(0)], + [], + ['Battles', stats.all.battles], + ['Wins', stats.all.wins], + ['Losses', stats.all.losses], + ['Average tier', stats.avg_tier.toFixed(2)], + [], + ['Hits per battle', stats.special.hpb.toFixed(0)], + ['Damage per battle', stats.special.dpb.toFixed(0)], + ['Kills per battle', stats.special.kpb.toFixed(2)], + ['Spots per battle', stats.special.spb.toFixed(2)], + [ + 'Shots per battle', + (stats.all.shots / stats.all.battles).toFixed(2), + ], + [ + 'Hits per battle', + (stats.all.hits / stats.all.battles).toFixed(2), + ], + [ + 'XP per battle', + (stats.all.xp / stats.all.battles).toFixed(2), + ], + [], + ['Damage ratio', stats.special.damageRatio.toFixed(2)], + ['Kills to death ratio', stats.special.kdr.toFixed(2)], + ] + .map((array) => + array.length === 0 ? '' : `**${array[0]}**: ${array[1]}`, + ) + .join( + '\n', + )}\n\n[View full stats](https://www.blitzstars.com/player/${ + data.region + }/${ + data.nickname + }) • [Support BlitzStars](https://www.blitzstars.com/supporters)`, + ) + .setTimestamp() + .setFooter({ + text: 'Powered by BlitzStars', + iconURL: + 'https://www.blitzstars.com/assets/images/TankyMcPewpew.png', + }), + ], + }); + + console.log(`Showing ${data.nickname}'s ${period} stats`); + }) + .catch(() => { + interaction.reply({ + embeds: [ + new EmbedBuilder() + .setTitle('No data to display') + .setDescription(`${ign} is not tracked by BlitzStars.`) + .setColor(NEGATIVE_COLOR), + ], + }); + }); }); }