Skip to content

Commit

Permalink
feat(GuildChannel): createInvite target options (#5514)
Browse files Browse the repository at this point in the history
Co-authored-by: Antonio Román <kyradiscord@gmail.com>
Co-authored-by: Advaith <advaithj1@gmail.com>
  • Loading branch information
3 people committed May 11, 2021
1 parent ff2f737 commit f831872
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/structures/ClientApplication.js
Expand Up @@ -30,7 +30,7 @@ class ClientApplication extends Application {
this.flags = 'flags' in data ? new ApplicationFlags(data.flags) : this.flags;

/**
* The app's cover image
* The hash of the application's cover image
* @type {?string}
*/
this.cover = data.cover_image ?? this.cover ?? null;
Expand Down
27 changes: 26 additions & 1 deletion src/structures/GuildChannel.js
Expand Up @@ -483,6 +483,14 @@ class GuildChannel extends Channel {
});
}

/**
* Data that can be resolved to an Application. This can be:
* * An Application
* * An Activity with associated Application
* * A Snowflake
* @typedef {Application|Snowflake} ApplicationResolvable
*/

/**
* Creates an invite to this guild channel.
* @param {Object} [options={}] Options for the invite
Expand All @@ -491,6 +499,11 @@ class GuildChannel extends Channel {
* @param {number} [options.maxAge=86400] How long the invite should last (in seconds, 0 for forever)
* @param {number} [options.maxUses=0] Maximum number of uses
* @param {boolean} [options.unique=false] Create a unique invite, or use an existing one with similar settings
* @param {UserResolvable} [options.targetUser] The user whose stream to display for this invite,
* required if `targetType` is 1, the user must be streaming in the channel
* @param {ApplicationResolvable} [options.targetApplication] The embedded application to open for this invite,
* required if `targetType` is 2, the application must have the `EMBEDDED` flag
* @param {InviteTargetType} [options.targetType] The type of the target for this voice channel invite
* @param {string} [options.reason] Reason for creating this
* @returns {Promise<Invite>}
* @example
Expand All @@ -499,7 +512,16 @@ class GuildChannel extends Channel {
* .then(invite => console.log(`Created an invite with a code of ${invite.code}`))
* .catch(console.error);
*/
createInvite({ temporary = false, maxAge = 86400, maxUses = 0, unique, reason } = {}) {
createInvite({
temporary = false,
maxAge = 86400,
maxUses = 0,
unique,
targetUser,
targetApplication,
targetType,
reason,
} = {}) {
return this.client.api
.channels(this.id)
.invites.post({
Expand All @@ -508,6 +530,9 @@ class GuildChannel extends Channel {
max_age: maxAge,
max_uses: maxUses,
unique,
target_user_id: this.client.users.resolveID(targetUser),
target_application_id: targetApplication?.id ?? targetApplication?.applicationID ?? targetApplication,
target_type: targetType,
},
reason,
})
Expand Down
42 changes: 42 additions & 0 deletions src/structures/IntegrationApplication.js
Expand Up @@ -15,6 +15,48 @@ class IntegrationApplication extends Application {
* @type {?User}
*/
this.bot = data.bot ? this.client.users.add(data.bot) : this.bot ?? null;

/**
* The url of the app's terms of service
* @type {?string}
*/
this.termsOfServiceURL = data.terms_of_service_url ?? this.termsOfServiceURL ?? null;

/**
* The url of the app's privacy policy
* @type {?string}
*/
this.privacyPolicyURL = data.privacy_policy_url ?? this.privacyPolicyURL ?? null;

/**
* The Array of RPC origin urls
* @type {string[]}
*/
this.rpcOrigins = data.rpc_origins ?? this.rpcOrigins ?? [];

/**
* The application summary
* @type {?string}
*/
this.summary = data.summary ?? this.summary ?? null;

/**
* Whether the application can be default hooked by the client
* @type {?boolean}
*/
this.hook = data.hook ?? this.hook ?? null;

/**
* The hash of the application's cover image
* @type {?string}
*/
this.cover = data.cover_image ?? this.cover ?? null;

/**
* The hex-encoded key for verification in interactions and the GameSDK's GetTicket
* @type {?string}
*/
this.verifyKey = data.verify_key ?? this.verifyKey ?? null;
}
}

Expand Down
22 changes: 16 additions & 6 deletions src/structures/Invite.js
@@ -1,6 +1,7 @@
'use strict';

const Base = require('./Base');
const IntegrationApplication = require('./IntegrationApplication');
const { Endpoints } = require('../util/Constants');
const Permissions = require('../util/Permissions');

Expand Down Expand Up @@ -71,22 +72,31 @@ class Invite extends Base {
this.inviter = data.inviter ? this.client.users.add(data.inviter) : null;

/**
* The target user for this invite
* The user whose stream to display for this voice channel stream invite
* @type {?User}
*/
this.targetUser = data.target_user ? this.client.users.add(data.target_user) : null;

/**
* The type of the target user:
* The embedded application to open for this voice channel embedded application invite
* @type {?IntegrationApplication}
*/
this.targetApplication = data.target_application
? new IntegrationApplication(this.client, data.target_application)
: null;

/**
* The type of the invite target:
* * 1: STREAM
* @typedef {number} TargetUser
* * 2: EMBEDDED_APPLICATION
* @typedef {number} TargetType
*/

/**
* The target user type
* @type {?TargetUser}
* The target type
* @type {?TargetType}
*/
this.targetUserType = typeof data.target_user_type === 'number' ? data.target_user_type : null;
this.targetType = typeof data.target_type === 'number' ? data.target_type : null;

/**
* The channel the invite is for
Expand Down
2 changes: 1 addition & 1 deletion src/structures/interfaces/Application.js
Expand Up @@ -75,7 +75,7 @@ class Application extends Base {
* @param {ImageURLOptions} [options={}] Options for the Image URL
* @returns {?string} URL to the cover image
*/
coverImage({ format, size } = {}) {
coverURL({ format, size } = {}) {
if (!this.cover) return null;
return Endpoints.CDN(this.client.options.http.cdn).AppIcon(this.id, this.cover, { format, size });
}
Expand Down
24 changes: 20 additions & 4 deletions typings/index.d.ts
Expand Up @@ -32,6 +32,11 @@ declare enum InteractionTypes {
APPLICATION_COMMAND = 2,
}

declare enum InviteTargetType {
STREAM = 1,
EMBEDDED_APPLICATION = 2,
}

declare enum OverwriteTypes {
role = 0,
member = 1,
Expand Down Expand Up @@ -153,7 +158,7 @@ declare module 'discord.js' {
public icon: string | null;
public id: Snowflake;
public name: string | null;
public coverImage(options?: ImageURLOptions): string | null;
public coverURL(options?: ImageURLOptions): string | null;
public fetchAssets(): Promise<ApplicationAsset[]>;
public iconURL(options?: ImageURLOptions): string | null;
public toJSON(): object;
Expand All @@ -178,6 +183,8 @@ declare module 'discord.js' {
private static transformOption(option: ApplicationCommandOptionData, received?: boolean): object;
}

type ApplicationResolvable = Application | Activity | Snowflake;

export class ApplicationFlags extends BitField<ApplicationFlagsString> {
public static FLAGS: Record<ApplicationFlagsString, number>;
public static resolve(bit?: BitFieldResolvable<ApplicationFlagsString, number>): number;
Expand Down Expand Up @@ -1034,6 +1041,13 @@ declare module 'discord.js' {

export class IntegrationApplication extends Application {
public bot: User | null;
public termsOfServiceURL: string | null;
public privacyPolicyURL: string | null;
public rpcOrigins: string[];
public summary: string | null;
public hook: boolean | null;
public cover: string | null;
public verifyKey: string | null;
}

export class Intents extends BitField<IntentsString> {
Expand Down Expand Up @@ -1077,8 +1091,9 @@ declare module 'discord.js' {
public maxUses: number | null;
public memberCount: number;
public presenceCount: number;
public targetApplication: IntegrationApplication | null;
public targetUser: User | null;
public targetUserType: TargetUser | null;
public targetType: InviteTargetType | null;
public temporary: boolean | null;
public readonly url: string;
public uses: number | null;
Expand Down Expand Up @@ -3093,6 +3108,9 @@ declare module 'discord.js' {
maxUses?: number;
unique?: boolean;
reason?: string;
targetApplication?: ApplicationResolvable;
targetUser?: UserResolvable;
targetType?: InviteTargetType;
}

type InviteResolvable = string;
Expand Down Expand Up @@ -3576,8 +3594,6 @@ declare module 'discord.js' {

type SystemMessageType = Exclude<MessageType, 'DEFAULT' | 'REPLY' | 'APPLICATION_COMMAND'>;

type TargetUser = number;

interface TypingData {
user: User | PartialUser;
since: Date;
Expand Down

0 comments on commit f831872

Please sign in to comment.