diff options
author | mat <27899617+mat-1@users.noreply.github.com> | 2021-06-29 17:52:00 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-29 17:52:00 -0500 |
commit | c0c534dafb54ebf9f95a5054f576ad99de29f232 (patch) | |
tree | 8a8a81f5bd6fbb372899f769be402f0bec326149 /src/cleaners/skyblock | |
parent | 6c7d2de36be559f62560f00fc2297c7deec3a051 (diff) | |
download | skyblock-api-c0c534dafb54ebf9f95a5054f576ad99de29f232.tar.gz skyblock-api-c0c534dafb54ebf9f95a5054f576ad99de29f232.tar.bz2 skyblock-api-c0c534dafb54ebf9f95a5054f576ad99de29f232.zip |
enable strictNullChecks and fix all related issues (#65)
Diffstat (limited to 'src/cleaners/skyblock')
-rw-r--r-- | src/cleaners/skyblock/collections.ts | 2 | ||||
-rw-r--r-- | src/cleaners/skyblock/inventory.ts | 4 | ||||
-rw-r--r-- | src/cleaners/skyblock/member.ts | 13 | ||||
-rw-r--r-- | src/cleaners/skyblock/minions.ts | 2 | ||||
-rw-r--r-- | src/cleaners/skyblock/profile.ts | 8 | ||||
-rw-r--r-- | src/cleaners/skyblock/profiles.ts | 11 | ||||
-rw-r--r-- | src/cleaners/skyblock/stats.ts | 11 |
7 files changed, 29 insertions, 22 deletions
diff --git a/src/cleaners/skyblock/collections.ts b/src/cleaners/skyblock/collections.ts index 708822b..99fdc27 100644 --- a/src/cleaners/skyblock/collections.ts +++ b/src/cleaners/skyblock/collections.ts @@ -84,7 +84,7 @@ export interface Collection { } // get a category name (farming) from a collection name (wheat) -function getCategory(collectionName): CollectionCategory { +function getCategory(collectionName): CollectionCategory | undefined { for (const categoryName in COLLECTIONS) { const categoryItems = COLLECTIONS[categoryName] if (categoryItems.includes(collectionName)) diff --git a/src/cleaners/skyblock/inventory.ts b/src/cleaners/skyblock/inventory.ts index 890937a..5ad6617 100644 --- a/src/cleaners/skyblock/inventory.ts +++ b/src/cleaners/skyblock/inventory.ts @@ -26,7 +26,7 @@ interface Item { export type Inventory = Item[] -function cleanItem(rawItem): Item { +function cleanItem(rawItem): Item | null { // if the item doesn't have an id, it isn't an item if (rawItem.id === undefined) return null @@ -35,7 +35,7 @@ function cleanItem(rawItem): Item { const damageValue = rawItem.Damage const itemTag = rawItem.tag const extraAttributes = itemTag?.ExtraAttributes ?? {} - let headId: string + let headId: string | undefined if (vanillaId === 397) { const headDataBase64 = itemTag?.SkullOwner?.Properties?.textures?.[0]?.Value diff --git a/src/cleaners/skyblock/member.ts b/src/cleaners/skyblock/member.ts index 4a2f8cc..cee1864 100644 --- a/src/cleaners/skyblock/member.ts +++ b/src/cleaners/skyblock/member.ts @@ -30,7 +30,7 @@ export interface CleanMember extends CleanBasicMember { rawHypixelStats?: { [ key: string ]: number } minions: CleanMinion[] fairy_souls: FairySouls - inventories: Inventories + inventories?: Inventories objectives: Objective[] skills: Skill[] visited_zones: Zone[] @@ -38,8 +38,9 @@ export interface CleanMember extends CleanBasicMember { slayers: SlayerData } -export async function cleanSkyBlockProfileMemberResponseBasic(member: any, included: Included[] = null): Promise<CleanBasicMember> { +export async function cleanSkyBlockProfileMemberResponseBasic(member: any): Promise<CleanBasicMember | null> { const player = await cached.fetchPlayer(member.uuid) + if (!player) return null return { uuid: member.uuid, username: player.username, @@ -50,11 +51,11 @@ export async function cleanSkyBlockProfileMemberResponseBasic(member: any, inclu } /** Cleans up a member (from skyblock/profile) */ -export async function cleanSkyBlockProfileMemberResponse(member, included: Included[] = null): Promise<CleanMember> { +export async function cleanSkyBlockProfileMemberResponse(member, included: Included[] | undefined = undefined): Promise<CleanMember | null> { // profiles.members[] - const inventoriesIncluded = included === null || included.includes('inventories') + const inventoriesIncluded = included === undefined || included.includes('inventories') const player = await cached.fetchPlayer(member.uuid) - if (!player) return + if (!player) return null const fairySouls = cleanFairySouls(member) const { max_fairy_souls: maxFairySouls } = await constants.fetchConstantValues() @@ -109,5 +110,5 @@ export interface CleanMemberProfilePlayer extends CleanPlayer { export interface CleanMemberProfile { member: CleanMemberProfilePlayer profile: CleanFullProfileBasicMembers - customization: AccountCustomization + customization?: AccountCustomization } diff --git a/src/cleaners/skyblock/minions.ts b/src/cleaners/skyblock/minions.ts index 21f7b66..d045a7e 100644 --- a/src/cleaners/skyblock/minions.ts +++ b/src/cleaners/skyblock/minions.ts @@ -80,7 +80,7 @@ export function combineMinionArrays(minions: CleanMinion[][]): CleanMinion[] { // This should never happen, but in case the length of `minion.levels` is longer than // `matchingMinionReference.levels`, then it should be extended to be equal length while (matchingMinionReference.levels.length < minion.levels.length) - matchingMinionReference.levels.push(null) + matchingMinionReference.levels.push(false) for (let i = 0; i < minion.levels.length; i++) { if (minion.levels[i]) diff --git a/src/cleaners/skyblock/profile.ts b/src/cleaners/skyblock/profile.ts index 0453ff3..5bcea4b 100644 --- a/src/cleaners/skyblock/profile.ts +++ b/src/cleaners/skyblock/profile.ts @@ -25,7 +25,7 @@ export interface CleanFullProfileBasicMembers extends CleanProfile { /** Return a `CleanProfile` instead of a `CleanFullProfile`, useful when we need to get members but don't want to waste much ram */ export async function cleanSkyblockProfileResponseLighter(data): Promise<CleanProfile> { // We use Promise.all so it can fetch all the usernames at once instead of waiting for the previous promise to complete - const promises: Promise<CleanBasicMember>[] = [] + const promises: Promise<CleanBasicMember | null>[] = [] for (const memberUUID in data.members) { const memberRaw = data.members[memberUUID] @@ -34,7 +34,7 @@ export async function cleanSkyblockProfileResponseLighter(data): Promise<CleanPr promises.push(cleanSkyBlockProfileMemberResponseBasic(memberRaw)) } - const cleanedMembers: CleanBasicMember[] = await Promise.all(promises) + const cleanedMembers: CleanBasicMember[] = (await Promise.all(promises)).filter(m => m) as CleanBasicMember[] return { uuid: data.profile_id, @@ -48,7 +48,7 @@ export async function cleanSkyblockProfileResponseLighter(data): Promise<CleanPr */ export async function cleanSkyblockProfileResponse(data: any, options?: ApiOptions): Promise<CleanFullProfile|CleanProfile> { // We use Promise.all so it can fetch all the users at once instead of waiting for the previous promise to complete - const promises: Promise<CleanMember>[] = [] + const promises: Promise<CleanMember | null>[] = [] for (const memberUUID in data.members) { const memberRaw = data.members[memberUUID] @@ -62,7 +62,7 @@ export async function cleanSkyblockProfileResponse(data: any, options?: ApiOptio )) } - const cleanedMembers: CleanMember[] = (await Promise.all(promises)).filter(m => m !== null && m !== undefined) + const cleanedMembers: CleanMember[] = (await Promise.all(promises)).filter(m => m !== null && m !== undefined) as CleanMember[] if (options?.basic) { return { diff --git a/src/cleaners/skyblock/profiles.ts b/src/cleaners/skyblock/profiles.ts index f12b5f6..a44fe48 100644 --- a/src/cleaners/skyblock/profiles.ts +++ b/src/cleaners/skyblock/profiles.ts @@ -1,5 +1,10 @@ -import { HypixelPlayerStatsSkyBlockProfiles } from "../../hypixelApi" -import { CleanBasicProfile, CleanProfile, cleanSkyblockProfileResponse, cleanSkyblockProfileResponseLighter } from "./profile" +import { HypixelPlayerStatsSkyBlockProfiles } from '../../hypixelApi' +import { + CleanBasicProfile, + CleanFullProfile, + CleanProfile, + cleanSkyblockProfileResponse +} from './profile' export function cleanPlayerSkyblockProfiles(rawProfiles: HypixelPlayerStatsSkyBlockProfiles): CleanBasicProfile[] { let profiles: CleanBasicProfile[] = [] @@ -14,7 +19,7 @@ export function cleanPlayerSkyblockProfiles(rawProfiles: HypixelPlayerStatsSkyBl /** Convert an array of raw profiles into clean profiles */ export async function cleanSkyblockProfilesResponse(data: any[]): Promise<CleanProfile[]> { - const promises = [] + const promises: Promise<CleanProfile | CleanFullProfile>[] = [] for (const profile of data ?? []) { // let cleanedProfile = await cleanSkyblockProfileResponseLighter(profile) promises.push(cleanSkyblockProfileResponse(profile)) diff --git a/src/cleaners/skyblock/stats.ts b/src/cleaners/skyblock/stats.ts index 31a894c..a91ca74 100644 --- a/src/cleaners/skyblock/stats.ts +++ b/src/cleaners/skyblock/stats.ts @@ -14,8 +14,8 @@ const statCategories: { [ key: string ]: string[] | null } = { // sorted in orde } export interface StatCategory { - category: string, - name: string + category: string | null + name: string | null } export function categorizeStat(statNameRaw: string): StatCategory { @@ -71,11 +71,11 @@ export interface StatItem { rawName: string value: number categorizedName: string - category: string - unit: string + category: string | null + unit: string | null } -export function getStatUnit(name: string): string { +export function getStatUnit(name: string): string | null { for (const [ unitName, statMatchers ] of Object.entries(statUnits)) { for (const statMatch of statMatchers) { let trailingEnd = statMatch[0] === '_' @@ -88,6 +88,7 @@ export function getStatUnit(name: string): string { return unitName } } + return null } |