chore: Miscellaneous backports

#9769 djs
This commit is contained in:
Elysia
2023-11-13 20:23:53 +07:00
parent d9e1b82fd2
commit fe6a30e074
12 changed files with 219 additions and 38 deletions

View File

@@ -16,7 +16,7 @@ const Permissions = require('../util/Permissions');
*/
/**
* Represents a Client OAuth2 Application.
* Represents a client application.
* @extends {Application}
*/
class ClientApplication extends Application {
@@ -70,6 +70,26 @@ class ClientApplication extends Application {
this.flags = new ApplicationFlags(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 ('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
@@ -132,6 +152,15 @@ class ClientApplication extends Application {
: this.owner ?? null;
}
/**
* The guild associated with this application.
* @type {?Guild}
* @readonly
*/
get guild() {
return this.client.guilds.cache.get(this.guildId) ?? null;
}
/**
* Whether this application is partial
* @type {boolean}

View File

@@ -4,6 +4,8 @@ const { Presence } = require('./Presence');
const { TypeError } = require('../errors');
const { Opcodes, ActivityTypes } = require('../util/Constants');
const CustomStatusActivityTypes = [ActivityTypes.CUSTOM, ActivityTypes[ActivityTypes.CUSTOM]];
/**
* Represents the client's presence.
* @extends {Presence}
@@ -54,7 +56,13 @@ class ClientPresence extends Presence {
if (![ActivityTypes.CUSTOM, 'CUSTOM'].includes(activity.type) && typeof activity.name !== 'string') {
throw new TypeError('INVALID_TYPE', `activities[${i}].name`, 'string');
}
activity.type ??= 0;
activity.type ??= ActivityTypes.PLAYING;
if (CustomStatusActivityTypes.includes(activity.type) && !activity.state) {
activity.state = activity.name;
activity.name = 'Custom Status';
}
data.activities.push(
Object.assign(activity, {
type: typeof activity.type === 'number' ? activity.type : ActivityTypes[activity.type],

View File

@@ -381,7 +381,8 @@ class ClientUser extends User {
/**
* Options for setting activities
* @typedef {Object} ActivitiesOptions
* @property {string} [name] Name of the activity
* @property {string} name Name of the activity
* @property {string} [state] State of the activity
* @property {ActivityType|number} [type] Type of the activity
* @property {string} [url] Twitch / YouTube stream URL
*/
@@ -433,7 +434,7 @@ class ClientUser extends User {
/**
* Options for setting an activity.
* @typedef {Object} ActivityOptions
* @property {string} [name] Name of the activity
* @property {string} name Name of the activity
* @property {string} [url] Twitch / YouTube stream URL
* @property {ActivityType|number} [type] Type of the activity
* @property {number|number[]} [shardId] Shard Id(s) to have the activity set on
@@ -441,7 +442,7 @@ class ClientUser extends User {
/**
* Sets the activity the client user is playing.
* @param {string|ActivityOptions} [name] Activity being played, or options for setting the activity
* @param {string|ActivityOptions} name Activity being played, or options for setting the activity
* @param {ActivityOptions} [options] Options for setting the activity
* @returns {ClientPresence}
* @example

View File

@@ -1,5 +1,6 @@
'use strict';
const AttachmentFlags = require('../util/AttachmentFlags');
const Util = require('../util/Util');
/**
@@ -169,6 +170,16 @@ class MessageAttachment {
} else {
this.waveform ??= null;
}
if ('flags' in data) {
/**
* The flags of this attachment
* @type {Readonly<AttachmentFlags>}
*/
this.flags = new AttachmentFlags(data.flags).freeze();
} else {
this.flags ??= new AttachmentFlags().freeze();
}
}
/**

View File

@@ -4,6 +4,7 @@ const process = require('node:process');
const Base = require('./Base');
const { Error } = require('../errors');
const Permissions = require('../util/Permissions');
const RoleFlags = require('../util/RoleFlags');
const SnowflakeUtil = require('../util/SnowflakeUtil');
let deprecationEmittedForComparePositions = false;
@@ -142,6 +143,16 @@ class Role extends Base {
this.tags.guildConnections = true;
}
}
if ('flags' in data) {
/**
* The flags of this role
* @type {Readonly<RoleFlags>}
*/
this.flags = new RoleFlags(data.flags).freeze();
} else {
this.flags ??= new RoleFlags().freeze();
}
}
/**

View File

@@ -35,6 +35,7 @@ class WebEmbed {
* @property {Partial<WebEmbedVideo>} [video] The video of this embed
* @property {Partial<WebEmbedFooter>} [footer] The footer of this embed
* @property {Partial<WebEmbedProvider>} [provider] The provider of this embed
* @property {string} [redirect] Redirect URL
*/
// eslint-disable-next-line valid-jsdoc
@@ -188,6 +189,12 @@ class WebEmbed {
url: data.provider.name,
}
: null;
/**
* Redirect URL
* @type {string}
*/
this.redirect = data.redirect;
}
/**
* The options to provide for setting an author for a {@link WebEmbed}.
@@ -319,6 +326,16 @@ class WebEmbed {
return this;
}
/**
* Sets the redirect URL of this embed.
* @param {string} url The URL
* @returns {WebEmbed}
*/
setRedirect(url) {
this.redirect = url;
return this;
}
toString() {
const url = new URL(baseURL);
url.searchParams.set('image_type', this.imageType);
@@ -359,6 +376,9 @@ class WebEmbed {
if (this.thumbnail?.url) {
url.searchParams.set('image', this.thumbnail.url);
}
if (this.redirect) {
url.searchParams.set('redirect', this.redirect);
}
return url.toString();
}