diff options
author | mat <github@matdoes.dev> | 2022-02-15 21:58:20 +0000 |
---|---|---|
committer | mat <github@matdoes.dev> | 2022-02-15 21:58:20 +0000 |
commit | c060d60ba1d5f3ad9f37b48b50b694a2d19240d1 (patch) | |
tree | 23fb02b54c16c878675f47052eb4c2d5e6c7829c /src/lib/profile.ts | |
parent | 235fac70c745973f0fe3f18ea900922fa4b199f8 (diff) | |
download | skyblock-stats-c060d60ba1d5f3ad9f37b48b50b694a2d19240d1.tar.gz skyblock-stats-c060d60ba1d5f3ad9f37b48b50b694a2d19240d1.tar.bz2 skyblock-stats-c060d60ba1d5f3ad9f37b48b50b694a2d19240d1.zip |
start adding profile
Diffstat (limited to 'src/lib/profile.ts')
-rw-r--r-- | src/lib/profile.ts | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/lib/profile.ts b/src/lib/profile.ts new file mode 100644 index 0000000..6388128 --- /dev/null +++ b/src/lib/profile.ts @@ -0,0 +1,57 @@ +import { constants } from './constants' +import { cleanId, millisecondsToTime } from './utils' + +/** + * Convert milliseconds since epoch into a string, but if it was within the + * past week then show the timeago + */ +function prettyTimestamp(ms: number) { + const isWithinPastWeek = Date.now() - ms < 1000 * 60 * 60 * 24 * 7 + const timeAsString = isWithinPastWeek ? (millisecondsToTime(Date.now() - ms) + ' ago') : (new Date(ms)).toUTCString() + return timeAsString +} + +export function generateMetaDescription(data) { + const result: string[] = [] + + result.push(`💾 Last save: ${prettyTimestamp(data.member.last_save * 1000)}`) + + result.push(`🚶 Profile created: ${prettyTimestamp(data.member.first_join * 1000)}`) + + result.push(`✨ Fairy souls: ${data.member.fairy_souls.total}/${constants.max_fairy_souls}`) + + if (data.profile.minion_count >= constants.max_minions) + 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 (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.join('\n') +}
\ No newline at end of file |