aboutsummaryrefslogtreecommitdiff
path: root/src/cleaners/skyblock/member.ts
blob: cfa9a7197b1a4b7a195b11a033d7de93b76d88ec (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import { cleanCollections, Collection } from './collections'
import { cleanInventories, Inventories } from './inventory'
import { cleanFairySouls, FairySouls } from './fairysouls'
import { cleanObjectives, Objective } from './objectives'
import { CleanFullProfileBasicMembers } from './profile'
import { cleanProfileStats, StatItem } from './stats'
import { CleanMinion, cleanMinions } from './minions'
import { cleanSlayers, SlayerData } from './slayers'
import { cleanVisitedZones, Zone } from './zones'
import { cleanSkills, Skill } from './skills'
import * as cached from '../../hypixelCached'
import { Included } from '../../hypixel'
import { CleanPlayer } from '../player'
import { CleanRank } from '../rank'
import { Bank } from './bank'

export interface CleanBasicMember {
	uuid: string
	username: string
	last_save: number
	first_join: number
	rank: CleanRank
}

export interface CleanMember extends CleanBasicMember {
	purse: number
	stats: StatItem[]
	rawHypixelStats?: { [ key: string ]: number }
	minions: CleanMinion[]
	fairy_souls: FairySouls
	inventories: Inventories
	objectives: Objective[]
	skills: Skill[]
	visited_zones: Zone[]
	collections: Collection[]
	slayers: SlayerData
}

export async function cleanSkyBlockProfileMemberResponseBasic(member: any, included: Included[] = null): Promise<CleanBasicMember> {
	const player = await cached.fetchPlayer(member.uuid)
	return {
		uuid: member.uuid,
		username: player.username,
		last_save: member.last_save / 1000,
		first_join: member.first_join / 1000,
		rank: player.rank
	}
}

/** Cleans up a member (from skyblock/profile) */
export async function cleanSkyBlockProfileMemberResponse(member, included: Included[] = null): Promise<CleanMember> {
	// profiles.members[]
	const inventoriesIncluded = included === null || included.includes('inventories')
	const player = await cached.fetchPlayer(member.uuid)
	if (!player) return
	return {
		uuid: member.uuid,
		username: player.username,
		last_save: member.last_save / 1000,
		first_join: member.first_join / 1000,
		rank: player.rank,

		purse: member.coin_purse,

		stats: cleanProfileStats(member),

		// this is used for leaderboards
		rawHypixelStats: member.stats ?? {},

		minions: await cleanMinions(member),
		fairy_souls: cleanFairySouls(member),
		inventories: inventoriesIncluded ? await cleanInventories(member) : undefined,
		objectives: cleanObjectives(member),
		skills: cleanSkills(member),
		visited_zones: cleanVisitedZones(member),
		collections: cleanCollections(member),
		slayers: cleanSlayers(member)
	}
}


export interface CleanMemberProfilePlayer extends CleanPlayer {
	// The profile name may be different for each player, so we put it here
	profileName: string
	first_join: number
	last_save: number
	bank?: Bank
	purse?: number
	stats?: StatItem[]
	rawHypixelStats?: { [ key: string ]: number }
	minions?: CleanMinion[]
	fairy_souls?: FairySouls
	inventories?: Inventories
	objectives?: Objective[]
	skills?: Skill[]
	visited_zones?: Zone[]
	collections?: Collection[]
	slayers?: SlayerData
}

export interface CleanMemberProfile {
	member: CleanMemberProfilePlayer
	profile: CleanFullProfileBasicMembers
}