diff options
author | mat <github@matdoes.dev> | 2022-02-20 21:38:14 -0600 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-02-20 21:38:14 -0600 |
commit | 13e5974114f759bae73f3bfd68c62ce9cfaf785e (patch) | |
tree | 8a196b27b8d4dece1dc2187332422a4e41423dfa /src/lib/profile.ts | |
parent | 582409e7cb1598b65bee6d1023b77620bb3791af (diff) | |
download | skyblock-stats-13e5974114f759bae73f3bfd68c62ce9cfaf785e.tar.gz skyblock-stats-13e5974114f759bae73f3bfd68c62ce9cfaf785e.tar.bz2 skyblock-stats-13e5974114f759bae73f3bfd68c62ce9cfaf785e.zip |
add more stuff to profile and fix bugs
Diffstat (limited to 'src/lib/profile.ts')
-rw-r--r-- | src/lib/profile.ts | 61 |
1 files changed, 32 insertions, 29 deletions
diff --git a/src/lib/profile.ts b/src/lib/profile.ts index 320a5dc..c2c945e 100644 --- a/src/lib/profile.ts +++ b/src/lib/profile.ts @@ -1,3 +1,4 @@ +import type { CleanMemberProfile, StatItem } from './APITypes' import { cleanId, millisecondsToTime } from './utils' /** @@ -10,7 +11,7 @@ export function prettyTimestamp(ms: number) { return timeAsString } -export function generateInfobox(data, opts: { meta: boolean }): string[] { +export function generateInfobox(data: CleanMemberProfile): string[] { const result: string[] = [] result.push(`💾 Last save: ${prettyTimestamp(data.member.last_save * 1000)}`) @@ -22,35 +23,37 @@ export function generateInfobox(data, opts: { meta: boolean }): string[] { if (data.profile.minion_count >= data.profile.maxUniqueMinions) result.push(`🤖 Minion count: ${data.profile.minion_count}`) - let mostSignificantKillsStat = null - let mostSignificantDeathsStat = null - - for (const stat of data.member.stats) { - if ( - stat.category === 'kills' - && stat.rawName != 'kills' - && stat.value >= 200_000 - && stat.value > (mostSignificantKillsStat?.value ?? 0) - ) - mostSignificantKillsStat = stat - if ( - stat.category === 'deaths' - && stat.rawName != 'deaths' - && stat.value > 1_000_000 - && stat.value > (mostSignificantDeathsStat?.value ?? 0) - ) - mostSignificantDeathsStat = stat + if (data.member.stats) { + let mostSignificantKillsStat: StatItem | null = null + let mostSignificantDeathsStat: StatItem | null = null + + for (const stat of data.member.stats) { + if ( + stat.category === 'kills' + && stat.rawName != 'kills' + && stat.value >= 200_000 + && stat.value > (mostSignificantKillsStat?.value ?? 0) + ) + mostSignificantKillsStat = stat + if ( + stat.category === 'deaths' + && stat.rawName != 'deaths' + && stat.value > 1_000_000 + && stat.value > (mostSignificantDeathsStat?.value ?? 0) + ) + mostSignificantDeathsStat = stat + } + + if (mostSignificantKillsStat) + result.push( + `⚔️ ${mostSignificantKillsStat.value.toLocaleString()} ${mostSignificantKillsStat.unit || cleanId(mostSignificantKillsStat.rawName).toLowerCase()}` + ) + + if (mostSignificantDeathsStat) + result.push( + `☠ ${mostSignificantDeathsStat.value.toLocaleString()} ${mostSignificantDeathsStat.unit || cleanId(mostSignificantDeathsStat.rawName).toLowerCase()}` + ) } - if (mostSignificantKillsStat) - result.push( - `⚔️ ${mostSignificantKillsStat.value.toLocaleString()} ${mostSignificantKillsStat.unit || cleanId(mostSignificantKillsStat.rawName).toLowerCase()}` - ) - - if (mostSignificantDeathsStat) - result.push( - `☠ ${mostSignificantDeathsStat.value.toLocaleString()} ${mostSignificantDeathsStat.unit || cleanId(mostSignificantDeathsStat.rawName).toLowerCase()}` - ) - return result }
\ No newline at end of file |