From 4b911a04683ff5b751642c9072c9654bf80650ee Mon Sep 17 00:00:00 2001 From: tnfAngel <57068341+tnfAngel@users.noreply.github.com> Date: Sat, 29 Jun 2024 21:58:24 +0100 Subject: [PATCH 1/3] bun interval type support --- src/Client.ts | 10 +++++----- src/auth/FortniteAuthSession.ts | 2 +- src/auth/FortniteClientCredentialsAuthSession.ts | 2 +- src/auth/LauncherAuthSession.ts | 2 +- src/xmpp/XMPP.ts | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Client.ts b/src/Client.ts index 9d242cf7..4a6578b8 100644 --- a/src/Client.ts +++ b/src/Client.ts @@ -53,13 +53,13 @@ class Client extends EventEmitter { * Timeouts set by {@link Client#setTimeout} that are still active */ // eslint-disable-next-line no-undef - private timeouts: Set; + private timeouts: Set; /** * Intervals set by {@link Client#setInterval} that are still active */ // eslint-disable-next-line no-undef - private intervals: Set; + private intervals: Set; /** * All client configuration options @@ -456,7 +456,7 @@ class Client extends EventEmitter { ): Promise> { return new Promise((res, rej) => { // eslint-disable-next-line no-undef - let rejectionTimeout: NodeJS.Timeout; + let rejectionTimeout: any; const handler = (...data: any) => { if (!filter || filter(...data)) { @@ -497,7 +497,7 @@ class Client extends EventEmitter { * @param timeout Timeout to cancel */ // eslint-disable-next-line no-undef - public clearTimeout(timeout: NodeJS.Timeout) { + public clearTimeout(timeout: any) { clearTimeout(timeout); this.timeouts.delete(timeout); } @@ -520,7 +520,7 @@ class Client extends EventEmitter { * @param interval Interval to cancel */ // eslint-disable-next-line no-undef - public clearInterval(interval: NodeJS.Timeout) { + public clearInterval(interval: any) { clearInterval(interval); this.intervals.delete(interval); } diff --git a/src/auth/FortniteAuthSession.ts b/src/auth/FortniteAuthSession.ts index 009cf456..41f82f76 100644 --- a/src/auth/FortniteAuthSession.ts +++ b/src/auth/FortniteAuthSession.ts @@ -51,7 +51,7 @@ class FortniteAuthSession extends AuthSession { /** * The refresh timeout */ - public refreshTimeout?: NodeJS.Timeout; + public refreshTimeout?: any; constructor(client: Client, data: FortniteAuthData, clientSecret: string) { super(client, data, clientSecret, AuthSessionType.Fortnite); diff --git a/src/auth/FortniteClientCredentialsAuthSession.ts b/src/auth/FortniteClientCredentialsAuthSession.ts index eaf6ac61..933dce17 100644 --- a/src/auth/FortniteClientCredentialsAuthSession.ts +++ b/src/auth/FortniteClientCredentialsAuthSession.ts @@ -9,7 +9,7 @@ class FortniteClientCredentialsAuthSession extends AuthSession { public scope: string[]; public refreshToken: string; public refreshTokenExpiresAt: Date; - public refreshTimeout?: NodeJS.Timeout; + public refreshTimeout?: any; constructor(client: Client, data: LauncherAuthData, clientSecret: string) { super(client, data, clientSecret, AuthSessionType.Launcher); diff --git a/src/xmpp/XMPP.ts b/src/xmpp/XMPP.ts index d8d65121..279b4637 100644 --- a/src/xmpp/XMPP.ts +++ b/src/xmpp/XMPP.ts @@ -688,7 +688,7 @@ class XMPP extends Base { public waitForSentMessage(id: string, timeout = 1000) { return new Promise((res) => { // eslint-disable-next-line no-undef - let messageTimeout: NodeJS.Timeout; + let messageTimeout: any; const listener = (m: Stanzas.Message) => { if (m.id === id) { From 77cbdb197a7746a1b16de1a94a52fdb9c3cfa401 Mon Sep 17 00:00:00 2001 From: tnfAngel <57068341+tnfAngel@users.noreply.github.com> Date: Sat, 29 Jun 2024 22:33:58 +0100 Subject: [PATCH 2/3] add missing constructors --- src/structures/friend/BaseFriendMessage.ts | 17 ++++++++++++-- .../friend/ReceivedFriendMessage.ts | 14 ++++++++++- src/structures/friend/SentFriendMessage.ts | 14 ++++++++++- .../party/ReceivedPartyInvitation.ts | 21 +++++++++++++++-- .../party/ReceivedPartyJoinRequest.ts | 18 +++++++++++++-- src/structures/party/SentPartyInvitation.ts | 21 +++++++++++++++-- src/structures/party/SentPartyJoinRequest.ts | 18 +++++++++++++-- src/structures/stw/STWMeleeWeaponSchematic.ts | 22 +++++++++++++++--- .../stw/STWRangedWeaponSchematic.ts | 22 +++++++++++++++--- src/structures/stw/STWTrapSchematic.ts | 23 ++++++++++++++++--- src/structures/stw/STWWeaponSchematic.ts | 23 ++++++++++++++++--- 11 files changed, 189 insertions(+), 24 deletions(-) diff --git a/src/structures/friend/BaseFriendMessage.ts b/src/structures/friend/BaseFriendMessage.ts index a62aebea..093486dd 100644 --- a/src/structures/friend/BaseFriendMessage.ts +++ b/src/structures/friend/BaseFriendMessage.ts @@ -1,6 +1,8 @@ import BaseMessage from '../BaseMessage'; import type ClientUser from '../user/ClientUser'; import type Friend from './Friend'; +import type Client from '../../Client'; +import type { MessageData } from '../../../resources/structs'; /** * Represents a friend whisper message @@ -9,12 +11,23 @@ class BaseFriendMessage extends BaseMessage { /** * The message's content */ - public override content!: string; + public override content: string; /** * The message's author */ - public override author!: Friend | ClientUser; + public override author: Friend | ClientUser; + + /** + * @param client The main client + * @param data The message's data + */ + constructor(client: Client, data: MessageData & { author: Friend | ClientUser; }) { + super(client, data); + + this.content = data.content; + this.author = data.author; + } /** * Replies to this whisper message diff --git a/src/structures/friend/ReceivedFriendMessage.ts b/src/structures/friend/ReceivedFriendMessage.ts index 9640d2be..e02fcb7b 100644 --- a/src/structures/friend/ReceivedFriendMessage.ts +++ b/src/structures/friend/ReceivedFriendMessage.ts @@ -1,5 +1,7 @@ import BaseFriendMessage from './BaseFriendMessage'; import type Friend from './Friend'; +import type Client from '../../Client'; +import type { MessageData } from '../../../resources/structs'; /** * Represents a received friend whisper message @@ -8,7 +10,17 @@ class ReceivedFriendMessage extends BaseFriendMessage { /** * The message's author */ - public override author!: Friend; + public override author: Friend; + + /** + * @param client The main client + * @param data The message's data + */ + constructor(client: Client, data: MessageData & { author: Friend; }) { + super(client, data); + + this.author = data.author; + } /** * Replies to this whisper message diff --git a/src/structures/friend/SentFriendMessage.ts b/src/structures/friend/SentFriendMessage.ts index 2c69cf4f..785fe509 100644 --- a/src/structures/friend/SentFriendMessage.ts +++ b/src/structures/friend/SentFriendMessage.ts @@ -1,5 +1,7 @@ import BaseFriendMessage from './BaseFriendMessage'; import type ClientUser from '../user/ClientUser'; +import type Client from '../../Client'; +import type { MessageData } from '../../../resources/structs'; /** * Represents a sent friend whisper message @@ -8,7 +10,17 @@ class SentFriendMessage extends BaseFriendMessage { /** * The message's author */ - public override author!: ClientUser; + public override author: ClientUser; + + /** + * @param client The main client + * @param data The message's data + */ + constructor(client: Client, data: MessageData & { author: ClientUser; }) { + super(client, data); + + this.author = data.author; + } } export default SentFriendMessage; diff --git a/src/structures/party/ReceivedPartyInvitation.ts b/src/structures/party/ReceivedPartyInvitation.ts index a4d5a05c..37805a4a 100644 --- a/src/structures/party/ReceivedPartyInvitation.ts +++ b/src/structures/party/ReceivedPartyInvitation.ts @@ -4,13 +4,30 @@ import BasePartyInvitation from './BasePartyInvitation'; import { AuthSessionStoreKey } from '../../../resources/enums'; import type ClientUser from '../user/ClientUser'; import type Friend from '../friend/Friend'; +import type Client from '../../Client'; +import type Party from './Party'; +import type ClientParty from './ClientParty'; /** * Represents a recieved party invitation */ class ReceivedPartyInvitation extends BasePartyInvitation { - public override sender!: Friend; - public override receiver!: ClientUser; + public override sender: Friend; + public override receiver: ClientUser; + + /** + * @param client The main client + * @param party The party this invitation belongs to + * @param sender The friend (or the client user) who sent this invitation + * @param receiver The friend (or the client user) who received this invitation + * @param data The invitation data + */ + constructor(client: Client, party: Party | ClientParty, sender: Friend, receiver: ClientUser, data: any) { + super(client, party, sender, receiver, data); + + this.sender = sender; + this.receiver = receiver; + } /** * Accepts this invitation diff --git a/src/structures/party/ReceivedPartyJoinRequest.ts b/src/structures/party/ReceivedPartyJoinRequest.ts index 91ef91bd..fb588f62 100644 --- a/src/structures/party/ReceivedPartyJoinRequest.ts +++ b/src/structures/party/ReceivedPartyJoinRequest.ts @@ -1,13 +1,27 @@ import BasePartyJoinRequest from './BasePartyJoinRequest'; import type ClientUser from '../user/ClientUser'; import type Friend from '../friend/Friend'; +import type Client from '../../Client'; /** * Represents an incoming party join request */ class ReceivedPartyJoinRequest extends BasePartyJoinRequest { - public override receiver!: ClientUser; - public override sender!: Friend; + public override receiver: ClientUser; + public override sender: Friend; + + /** + * @param client The main client + * @param sender The user who requested to join the party + * @param receiver The user who received the join request + * @param data The party confirmation data + */ + constructor(client: Client, sender: Friend, receiver: ClientUser, data: any) { + super(client, sender, receiver, data); + + this.sender = sender; + this.receiver = receiver; + } /** * Accepts the join request. If it expired, a normal invite will be sent diff --git a/src/structures/party/SentPartyInvitation.ts b/src/structures/party/SentPartyInvitation.ts index aca0d1c8..a520470e 100644 --- a/src/structures/party/SentPartyInvitation.ts +++ b/src/structures/party/SentPartyInvitation.ts @@ -4,13 +4,30 @@ import BasePartyInvitation from './BasePartyInvitation'; import { AuthSessionStoreKey } from '../../../resources/enums'; import type ClientUser from '../user/ClientUser'; import type Friend from '../friend/Friend'; +import type Client from '../../Client'; +import type Party from './Party'; +import type ClientParty from './ClientParty'; /** * Represents a sent party invitation */ class SentPartyInvitation extends BasePartyInvitation { - public override sender!: ClientUser; - public override receiver!: Friend; + public override sender: ClientUser; + public override receiver: Friend; + + /** + * @param client The main client + * @param party The party this invitation belongs to + * @param sender The friend (or the client user) who sent this invitation + * @param receiver The friend (or the client user) who received this invitation + * @param data The invitation data + */ + constructor(client: Client, party: Party | ClientParty, sender: ClientUser, receiver: Friend, data: any) { + super(client, party, sender, receiver, data); + + this.sender = sender; + this.receiver = receiver; + } /** * Declines this invitation diff --git a/src/structures/party/SentPartyJoinRequest.ts b/src/structures/party/SentPartyJoinRequest.ts index 223c6b6c..c958327d 100644 --- a/src/structures/party/SentPartyJoinRequest.ts +++ b/src/structures/party/SentPartyJoinRequest.ts @@ -1,13 +1,27 @@ import BasePartyJoinRequest from './BasePartyJoinRequest'; import type ClientUser from '../user/ClientUser'; import type Friend from '../friend/Friend'; +import type Client from '../../Client'; /** * Represents an outgoing party join request */ class SentPartyJoinRequest extends BasePartyJoinRequest { - public override receiver!: Friend; - public override sender!: ClientUser; + public override receiver: Friend; + public override sender: ClientUser; + + /** + * @param client The main client + * @param sender The user who requested to join the party + * @param receiver The user who received the join request + * @param data The party confirmation data + */ + constructor(client: Client, sender: ClientUser, receiver: Friend, data: any) { + super(client, sender, receiver, data); + + this.sender = sender; + this.receiver = receiver; + } } export default SentPartyJoinRequest; diff --git a/src/structures/stw/STWMeleeWeaponSchematic.ts b/src/structures/stw/STWMeleeWeaponSchematic.ts index 23800581..69169365 100644 --- a/src/structures/stw/STWMeleeWeaponSchematic.ts +++ b/src/structures/stw/STWMeleeWeaponSchematic.ts @@ -1,9 +1,25 @@ import STWWeaponSchematic from './STWWeaponSchematic'; -import type { STWSchematicMeleeSubType } from '../../../resources/structs'; +import { parseSTWSchematicTemplateId } from '../../util/Util'; +import type { STWSchematicEvoType, STWSchematicMeleeSubType } from '../../../resources/structs'; +import type { STWProfileSchematicData } from '../../../resources/httpResponses'; +import type Client from '../../Client'; class STWMeleeWeaponSchematic extends STWWeaponSchematic { - public override type!: 'melee'; - public override subType!: STWSchematicMeleeSubType; + public override type: 'melee'; + public override subType: STWSchematicMeleeSubType; + + constructor(client: Client, id: string, data: STWProfileSchematicData & { + type: 'melee'; + subType: STWSchematicMeleeSubType; + evoType: STWSchematicEvoType; + }) { + super(client, id, data); + + const parsedSchematic = parseSTWSchematicTemplateId(data.templateId); + + this.type = parsedSchematic.type as | 'melee'; + this.subType = parsedSchematic.subType as STWSchematicMeleeSubType; + } } export default STWMeleeWeaponSchematic; diff --git a/src/structures/stw/STWRangedWeaponSchematic.ts b/src/structures/stw/STWRangedWeaponSchematic.ts index 0983e01a..bcdaf1f4 100644 --- a/src/structures/stw/STWRangedWeaponSchematic.ts +++ b/src/structures/stw/STWRangedWeaponSchematic.ts @@ -1,9 +1,25 @@ import STWWeaponSchematic from './STWWeaponSchematic'; -import type { STWSchematicRangedSubType } from '../../../resources/structs'; +import { parseSTWSchematicTemplateId } from '../../util/Util'; +import type { STWSchematicEvoType, STWSchematicRangedSubType } from '../../../resources/structs'; +import type { STWProfileSchematicData } from '../../../resources/httpResponses'; +import type Client from '../../Client'; class STWRangedWeaponSchematic extends STWWeaponSchematic { - public override type!: 'ranged'; - public override subType!: STWSchematicRangedSubType; + public override type: 'ranged'; + public override subType: STWSchematicRangedSubType; + + constructor(client: Client, id: string, data: STWProfileSchematicData & { + type: 'ranged'; + subType: STWSchematicRangedSubType + evoType: STWSchematicEvoType; + }) { + super(client, id, data); + + const parsedSchematic = parseSTWSchematicTemplateId(data.templateId); + + this.type = parsedSchematic.type as 'ranged'; + this.subType = parsedSchematic.subType as STWSchematicRangedSubType; + } } export default STWRangedWeaponSchematic; diff --git a/src/structures/stw/STWTrapSchematic.ts b/src/structures/stw/STWTrapSchematic.ts index ad94755f..0fd08a49 100644 --- a/src/structures/stw/STWTrapSchematic.ts +++ b/src/structures/stw/STWTrapSchematic.ts @@ -1,10 +1,27 @@ import STWSchematic from './STWSchematic'; +import { parseSTWSchematicTemplateId } from '../../util/Util'; import type { STWSchematicTrapSubType } from '../../../resources/structs'; +import type Client from '../../Client'; +import type { STWProfileSchematicData } from '../../../resources/httpResponses'; class STWTrapSchematic extends STWSchematic { - public override type!: 'trap'; - public override subType!: STWSchematicTrapSubType; - public override evoType!: never; + public override type: 'trap'; + public override subType: STWSchematicTrapSubType; + public override evoType: never; + + constructor(client: Client, id: string, data: STWProfileSchematicData & { + type: 'trap'; + subType: STWSchematicTrapSubType + evoType: never; + }) { + super(client, id, data); + + const parsedSchematic = parseSTWSchematicTemplateId(data.templateId); + + this.type = parsedSchematic.type as 'trap'; + this.subType = parsedSchematic.subType as STWSchematicTrapSubType; + this.evoType = parsedSchematic.evoType as never; + } } export default STWTrapSchematic; diff --git a/src/structures/stw/STWWeaponSchematic.ts b/src/structures/stw/STWWeaponSchematic.ts index 919dccba..2d9a6fdd 100644 --- a/src/structures/stw/STWWeaponSchematic.ts +++ b/src/structures/stw/STWWeaponSchematic.ts @@ -1,10 +1,27 @@ +import { parseSTWSchematicTemplateId } from '../../util/Util'; import STWSchematic from './STWSchematic'; +import type Client from '../../Client'; +import type { STWProfileSchematicData } from '../../../resources/httpResponses'; import type { STWSchematicEvoType, STWSchematicMeleeSubType, STWSchematicRangedSubType } from '../../../resources/structs'; class STWWeaponSchematic extends STWSchematic { - public override type!: 'ranged' | 'melee'; - public override subType!: STWSchematicRangedSubType | STWSchematicMeleeSubType; - public override evoType!: STWSchematicEvoType; + public override type: 'ranged' | 'melee'; + public override subType: STWSchematicRangedSubType | STWSchematicMeleeSubType; + public override evoType: STWSchematicEvoType; + + constructor(client: Client, id: string, data: STWProfileSchematicData & { + type: 'ranged' | 'melee'; + subType: STWSchematicRangedSubType | STWSchematicMeleeSubType; + evoType: STWSchematicEvoType; + }) { + super(client, id, data); + + const parsedSchematic = parseSTWSchematicTemplateId(data.templateId); + + this.type = parsedSchematic.type as 'ranged' | 'melee'; + this.subType = parsedSchematic.subType as STWSchematicRangedSubType | STWSchematicMeleeSubType; + this.evoType = parsedSchematic.evoType as STWSchematicEvoType; + } } export default STWWeaponSchematic; From 6ecfa84b16655735ae31e2c5c9e83ad98d8324cd Mon Sep 17 00:00:00 2001 From: tnfAngel <57068341+tnfAngel@users.noreply.github.com> Date: Sat, 29 Jun 2024 22:36:31 +0100 Subject: [PATCH 3/3] fix stw profile types --- src/structures/stw/STWProfile.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/structures/stw/STWProfile.ts b/src/structures/stw/STWProfile.ts index 93140945..da6169d0 100644 --- a/src/structures/stw/STWProfile.ts +++ b/src/structures/stw/STWProfile.ts @@ -19,6 +19,10 @@ import User from '../user/User'; import type Client from '../../Client'; import type { STWFORTStats, + STWSchematicEvoType, + STWSchematicMeleeSubType, + STWSchematicRangedSubType, + STWSchematicTrapSubType, STWSurvivorSquads, UserData, } from '../../../resources/structs'; @@ -122,13 +126,25 @@ class STWProfile extends User { case 'Schematic': switch (parseSTWSchematicTemplateId(item.templateId).type) { case 'melee': - this.items.push(new STWMeleeWeaponSchematic(this.client, itemId, item as STWProfileSchematicData)); + this.items.push(new STWMeleeWeaponSchematic(this.client, itemId, item as STWProfileSchematicData & { + type: 'melee'; + subType: STWSchematicMeleeSubType; + evoType: STWSchematicEvoType; + })); break; case 'ranged': - this.items.push(new STWRangedWeaponSchematic(this.client, itemId, item as STWProfileSchematicData)); + this.items.push(new STWRangedWeaponSchematic(this.client, itemId, item as STWProfileSchematicData & { + type: 'ranged'; + subType: STWSchematicRangedSubType + evoType: STWSchematicEvoType; + })); break; case 'trap': - this.items.push(new STWTrapSchematic(this.client, itemId, item as STWProfileSchematicData)); + this.items.push(new STWTrapSchematic(this.client, itemId, item as STWProfileSchematicData & { + type: 'trap'; + subType: STWSchematicTrapSubType + evoType: never; + })); break; default: this.items.push(new STWSchematic(this.client, itemId, item as STWProfileSchematicData));