blob: 52644b5ef1aa7c16de2a3484ec0fbca9c63d5b8e (
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
|
import typedHypixelApi from 'typed-hypixel-api'
import { CleanPlayer } from '../player'
import * as cached from '../../hypixelCached.js'
export interface CoopInvitation {
invitedTimestamp: number
invitedBy: CleanPlayer | null
accepted: boolean
acceptedTimestamp: number | null
}
export async function cleanCoopInvitation(data: typedHypixelApi.SkyBlockProfileMember, uuid: string): Promise<CoopInvitation | null> {
if (!data.coop_invitation)
return null
let invitedTimestamp = data.coop_invitation.timestamp
let acceptedTimestamp = data.coop_invitation.confirmed_timestamp ?? null
// the accepted timestamp should always be greater, otherwise swap
if (acceptedTimestamp !== null && invitedTimestamp > acceptedTimestamp) {
let temp = invitedTimestamp
invitedTimestamp = acceptedTimestamp
acceptedTimestamp = temp
}
return {
invitedTimestamp,
invitedBy: await cached.fetchBasicPlayer(data.coop_invitation.invited_by),
accepted: data.coop_invitation.confirmed,
acceptedTimestamp
}
}
|