Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ClientApplication): Approximate guild count and new GET route #9713

Merged
merged 6 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 56 additions & 12 deletions packages/discord.js/src/structures/ClientApplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const PermissionsBitField = require('../util/PermissionsBitField');
*/

/**
* Represents a Client OAuth2 Application.
* Represents a client application.
* @extends {Application}
*/
class ClientApplication extends Application {
Expand Down Expand Up @@ -69,6 +69,42 @@ class ClientApplication extends Application {
this.flags = new ApplicationFlagsBitField(data.flags).freeze();
}

if ('approximate_guild_count' in data) {
/**
* An approximate amount of guilds this application is in.
* @type {?number}
*/
this.approximateGuildCount = data.approximate_guild_count;
} else {
this.approximateGuildCount ??= null;
}

if ('owner' in data) {
this._owner = this.client.users._add(data.owner);
} else {
this._owner ??= null;
}

if ('team' in data) {
/**
* The team that holds this application.
* @type {?Team}
*/
this.team = new Team(this.client, data.team);
} else {
this.team ??= null;
}

if ('guild_id' in data) {
/**
* The id of the guild associated with this application.
* @type {?Snowflake}
*/
this.guildId = data.guild_id;
} else {
this.guildId ??= null;
}

if ('cover_image' in data) {
/**
* The hash of the application's cover image
Expand Down Expand Up @@ -118,16 +154,24 @@ class ClientApplication extends Application {
} else {
this.roleConnectionsVerificationURL ??= null;
}
}

/**
* The owner of this OAuth application
* @type {?(User|Team)}
*/
this.owner = data.team
? new Team(this.client, data.team)
: data.owner
? this.client.users._add(data.owner)
: this.owner ?? null;
/**
* The owner of this application.
* @type {?(User|Team)}
* @readonly
*/
get owner() {
Jiralite marked this conversation as resolved.
Show resolved Hide resolved
return this.team ?? this._owner;
}

/**
* The guild associated with this application.
* @type {?Guild}
* @readonly
*/
get guild() {
return this.client.guilds.cache.get(this.guildId) ?? null;
}

/**
Expand All @@ -144,8 +188,8 @@ class ClientApplication extends Application {
* @returns {Promise<ClientApplication>}
*/
async fetch() {
const app = await this.client.rest.get(Routes.oauth2CurrentApplication());
this._patch(app);
const data = await this.client.rest.get(Routes.currentApplication());
this._patch(data);
return this;
}

Expand Down
7 changes: 6 additions & 1 deletion packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1010,12 +1010,17 @@ export class ClientApplication extends Application {
public botPublic: boolean | null;
public botRequireCodeGrant: boolean | null;
public commands: ApplicationCommandManager;
private _owner: User | null;
public team: Team | null;
public guildId: Snowflake | null;
public get guild(): Guild | null;
public cover: string | null;
public flags: Readonly<ApplicationFlagsBitField>;
public approximateGuildCount: number | null;
public tags: string[];
public installParams: ClientApplicationInstallParams | null;
public customInstallURL: string | null;
public owner: User | Team | null;
public get owner(): User | Team | null;
public get partial(): boolean;
public roleConnectionsVerificationURL: string | null;
public rpcOrigins: string[];
Expand Down