aboutsummaryrefslogtreecommitdiff
path: root/src/lib/profile.ts
blob: 320a5dc4c5f26b32cebe27f036918715745257a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { cleanId, millisecondsToTime } from './utils'

/**
 * Convert milliseconds since epoch into a string, but if it was within the
 * past week then show the timeago
 */
export 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 generateInfobox(data, opts: { meta: boolean }): string[] {
    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}/${data.member.fairy_souls.max}`)

    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 (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
}