mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
chore: some more type work
This commit is contained in:
@@ -123,9 +123,15 @@ declare class ActionsManager {
|
|||||||
dtsLines.push(` ${fileName}: Action<[import('discord-api-types/v10').GatewayMessagePollVoteDispatchData]>;`);
|
dtsLines.push(` ${fileName}: Action<[import('discord-api-types/v10').GatewayMessagePollVoteDispatchData]>;`);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'ChannelCreate': {
|
||||||
|
dtsLines.push(
|
||||||
|
` ${fileName}: Action<[import('discord-api-types/v10').GatewayChannelCreateDispatchData], { channel?: BaseChannel | null }>;`,
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case 'ChannelUpdate': {
|
case 'ChannelUpdate': {
|
||||||
dtsLines.push(
|
dtsLines.push(
|
||||||
` ${fileName}: Action<[import('discord-api-types/v10').GatewayChannelUpdateDispatchData], { old?: BaseChannel; updated?: BaseChannel; }>;`,
|
` ${fileName}: Action<[import('discord-api-types/v10').GatewayChannelUpdateDispatchData], { old?: BaseChannel | null; updated?: BaseChannel; }>;`,
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @import Client from '../Client';
|
* @import Client from '../Client';
|
||||||
|
* @import CachedManager from '../../managers/CachedManager';
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const Partials = require('../../util/Partials');
|
const Partials = require('../../util/Partials');
|
||||||
@@ -21,6 +22,7 @@ that WebSocket events don't clash with REST methods.
|
|||||||
/**
|
/**
|
||||||
* @template {any[]} Arguments
|
* @template {any[]} Arguments
|
||||||
* @template {any} [ReturnType=void]
|
* @template {any} [ReturnType=void]
|
||||||
|
* @ignore
|
||||||
*/
|
*/
|
||||||
class GenericAction {
|
class GenericAction {
|
||||||
/**
|
/**
|
||||||
@@ -35,6 +37,7 @@ class GenericAction {
|
|||||||
/**
|
/**
|
||||||
* @param {Arguments} _args Arguments passed to the handler
|
* @param {Arguments} _args Arguments passed to the handler
|
||||||
* @returns {ReturnType}
|
* @returns {ReturnType}
|
||||||
|
* @ignore
|
||||||
*/
|
*/
|
||||||
handle(..._args) {
|
handle(..._args) {
|
||||||
/** @type {any} */
|
/** @type {any} */
|
||||||
@@ -42,6 +45,14 @@ class GenericAction {
|
|||||||
return casted;
|
return casted;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {unknown} data The data to add
|
||||||
|
* @param {CachedManager} manager The manager the data is for
|
||||||
|
* @param {string} id The id of the entry
|
||||||
|
* @param {Partials} partialType If a partial structure is supported, the type of partial
|
||||||
|
* @param {boolean} cache Whether the added data should be cached
|
||||||
|
* @returns {unknown}
|
||||||
|
*/
|
||||||
getPayload(data, manager, id, partialType, cache) {
|
getPayload(data, manager, id, partialType, cache) {
|
||||||
return this.client.options.partials.includes(partialType) ? manager._add(data, cache) : manager.cache.get(id);
|
return this.client.options.partials.includes(partialType) ? manager._add(data, cache) : manager.cache.get(id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,11 +25,14 @@ declare class ActionsManager {
|
|||||||
AutoModerationRuleCreate: Action<[import('discord-api-types/v10').GatewayAutoModerationRuleCreateDispatchData]>;
|
AutoModerationRuleCreate: Action<[import('discord-api-types/v10').GatewayAutoModerationRuleCreateDispatchData]>;
|
||||||
AutoModerationRuleDelete: Action<[import('discord-api-types/v10').GatewayAutoModerationRuleDeleteDispatchData]>;
|
AutoModerationRuleDelete: Action<[import('discord-api-types/v10').GatewayAutoModerationRuleDeleteDispatchData]>;
|
||||||
AutoModerationRuleUpdate: Action<[import('discord-api-types/v10').GatewayAutoModerationRuleUpdateDispatchData]>;
|
AutoModerationRuleUpdate: Action<[import('discord-api-types/v10').GatewayAutoModerationRuleUpdateDispatchData]>;
|
||||||
ChannelCreate: Action<[import('discord-api-types/v10').GatewayChannelCreateDispatchData]>;
|
ChannelCreate: Action<
|
||||||
|
[import('discord-api-types/v10').GatewayChannelCreateDispatchData],
|
||||||
|
{ channel?: BaseChannel | null }
|
||||||
|
>;
|
||||||
ChannelDelete: Action<[import('discord-api-types/v10').GatewayChannelDeleteDispatchData]>;
|
ChannelDelete: Action<[import('discord-api-types/v10').GatewayChannelDeleteDispatchData]>;
|
||||||
ChannelUpdate: Action<
|
ChannelUpdate: Action<
|
||||||
[import('discord-api-types/v10').GatewayChannelUpdateDispatchData],
|
[import('discord-api-types/v10').GatewayChannelUpdateDispatchData],
|
||||||
{ old?: BaseChannel; updated?: BaseChannel }
|
{ old?: BaseChannel | null; updated?: BaseChannel }
|
||||||
>;
|
>;
|
||||||
EntitlementCreate: Action<[import('discord-api-types/v10').GatewayEntitlementCreateDispatchData]>;
|
EntitlementCreate: Action<[import('discord-api-types/v10').GatewayEntitlementCreateDispatchData]>;
|
||||||
EntitlementDelete: Action<[import('discord-api-types/v10').GatewayEntitlementDeleteDispatchData]>;
|
EntitlementDelete: Action<[import('discord-api-types/v10').GatewayEntitlementDeleteDispatchData]>;
|
||||||
|
|||||||
@@ -12,7 +12,16 @@ const Events = require('../../util/Events');
|
|||||||
* @property {ApplicationCommandPermissions[]} permissions The updated permissions
|
* @property {ApplicationCommandPermissions[]} permissions The updated permissions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends {Action<[import('discord-api-types/v10').GatewayApplicationCommandPermissionsUpdateDispatchData]>}
|
||||||
|
* @private
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
class ApplicationCommandPermissionsUpdateAction extends Action {
|
class ApplicationCommandPermissionsUpdateAction extends Action {
|
||||||
|
/**
|
||||||
|
* @override
|
||||||
|
* @param {import('discord-api-types/v10').GatewayApplicationCommandPermissionsUpdateDispatchData} data
|
||||||
|
*/
|
||||||
handle(data) {
|
handle(data) {
|
||||||
const client = this.client;
|
const client = this.client;
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,7 +4,16 @@ const Action = require('./Action');
|
|||||||
const AutoModerationActionExecution = require('../../structures/AutoModerationActionExecution');
|
const AutoModerationActionExecution = require('../../structures/AutoModerationActionExecution');
|
||||||
const Events = require('../../util/Events');
|
const Events = require('../../util/Events');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends {Action<[import('discord-api-types/v10').GatewayAutoModerationActionExecutionDispatchData]>}
|
||||||
|
* @private
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
class AutoModerationActionExecutionAction extends Action {
|
class AutoModerationActionExecutionAction extends Action {
|
||||||
|
/**
|
||||||
|
* @override
|
||||||
|
* @param {import('discord-api-types/v10').GatewayAutoModerationActionExecutionDispatchData} data
|
||||||
|
*/
|
||||||
handle(data) {
|
handle(data) {
|
||||||
const { client } = this;
|
const { client } = this;
|
||||||
const guild = client.guilds.cache.get(data.guild_id);
|
const guild = client.guilds.cache.get(data.guild_id);
|
||||||
|
|||||||
@@ -3,7 +3,16 @@
|
|||||||
const Action = require('./Action');
|
const Action = require('./Action');
|
||||||
const Events = require('../../util/Events');
|
const Events = require('../../util/Events');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends {Action<[import('discord-api-types/v10').GatewayAutoModerationRuleCreateDispatchData]>}
|
||||||
|
* @private
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
class AutoModerationRuleCreateAction extends Action {
|
class AutoModerationRuleCreateAction extends Action {
|
||||||
|
/**
|
||||||
|
* @override
|
||||||
|
* @param {import('discord-api-types/v10').GatewayAutoModerationRuleCreateDispatchData} data
|
||||||
|
*/
|
||||||
handle(data) {
|
handle(data) {
|
||||||
const { client } = this;
|
const { client } = this;
|
||||||
const guild = client.guilds.cache.get(data.guild_id);
|
const guild = client.guilds.cache.get(data.guild_id);
|
||||||
|
|||||||
@@ -3,7 +3,16 @@
|
|||||||
const Action = require('./Action');
|
const Action = require('./Action');
|
||||||
const Events = require('../../util/Events');
|
const Events = require('../../util/Events');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends {Action<[import('discord-api-types/v10').GatewayAutoModerationRuleDeleteDispatchData]>}
|
||||||
|
* @private
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
class AutoModerationRuleDeleteAction extends Action {
|
class AutoModerationRuleDeleteAction extends Action {
|
||||||
|
/**
|
||||||
|
* @override
|
||||||
|
* @param {import('discord-api-types/v10').GatewayAutoModerationRuleDeleteDispatchData} data
|
||||||
|
*/
|
||||||
handle(data) {
|
handle(data) {
|
||||||
const { client } = this;
|
const { client } = this;
|
||||||
const guild = client.guilds.cache.get(data.guild_id);
|
const guild = client.guilds.cache.get(data.guild_id);
|
||||||
|
|||||||
@@ -3,7 +3,16 @@
|
|||||||
const Action = require('./Action');
|
const Action = require('./Action');
|
||||||
const Events = require('../../util/Events');
|
const Events = require('../../util/Events');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends {Action<[import('discord-api-types/v10').GatewayAutoModerationRuleDeleteDispatchData]>}
|
||||||
|
* @private
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
class AutoModerationRuleUpdateAction extends Action {
|
class AutoModerationRuleUpdateAction extends Action {
|
||||||
|
/**
|
||||||
|
* @override
|
||||||
|
* @param {import('discord-api-types/v10').GatewayAutoModerationRuleDeleteDispatchData} data
|
||||||
|
*/
|
||||||
handle(data) {
|
handle(data) {
|
||||||
const { client } = this;
|
const { client } = this;
|
||||||
const guild = client.guilds.cache.get(data.guild_id);
|
const guild = client.guilds.cache.get(data.guild_id);
|
||||||
|
|||||||
@@ -1,13 +1,27 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @import { BaseChannel } from '../../structures/BaseChannel';
|
||||||
|
*/
|
||||||
|
|
||||||
const Action = require('./Action');
|
const Action = require('./Action');
|
||||||
const Events = require('../../util/Events');
|
const Events = require('../../util/Events');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends {Action<[import('discord-api-types/v10').GatewayChannelCreateDispatchData], { channel?: BaseChannel | null }>}
|
||||||
|
* @private
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
class ChannelCreateAction extends Action {
|
class ChannelCreateAction extends Action {
|
||||||
|
/**
|
||||||
|
* @override
|
||||||
|
* @param {import('discord-api-types/v10').GatewayChannelCreateDispatchData} data
|
||||||
|
*/
|
||||||
handle(data) {
|
handle(data) {
|
||||||
const client = this.client;
|
const client = this.client;
|
||||||
const existing = client.channels.cache.has(data.id);
|
const existing = client.channels.cache.has(data.id);
|
||||||
const channel = client.channels._add(data);
|
const channel = client.channels._add(data);
|
||||||
|
|
||||||
if (!existing && channel) {
|
if (!existing && channel) {
|
||||||
/**
|
/**
|
||||||
* Emitted whenever a guild channel is created.
|
* Emitted whenever a guild channel is created.
|
||||||
@@ -16,6 +30,7 @@ class ChannelCreateAction extends Action {
|
|||||||
*/
|
*/
|
||||||
client.emit(Events.ChannelCreate, channel);
|
client.emit(Events.ChannelCreate, channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
return { channel };
|
return { channel };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
8
packages/discord.js/src/managers/BaseManager.d.ts
vendored
Normal file
8
packages/discord.js/src/managers/BaseManager.d.ts
vendored
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import Client from '../client/Client';
|
||||||
|
|
||||||
|
declare class BaseManager {
|
||||||
|
readonly client: Client;
|
||||||
|
constructor(client: Client);
|
||||||
|
}
|
||||||
|
|
||||||
|
export = BaseManager;
|
||||||
@@ -1,5 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @import { Guild } from '../structures/Guild';
|
||||||
|
* @import Client from '../client/Client';
|
||||||
|
*/
|
||||||
|
|
||||||
const process = require('node:process');
|
const process = require('node:process');
|
||||||
const { Routes } = require('discord-api-types/v10');
|
const { Routes } = require('discord-api-types/v10');
|
||||||
const CachedManager = require('./CachedManager');
|
const CachedManager = require('./CachedManager');
|
||||||
@@ -15,12 +20,19 @@ let cacheWarningEmitted = false;
|
|||||||
* @extends {CachedManager}
|
* @extends {CachedManager}
|
||||||
*/
|
*/
|
||||||
class ChannelManager extends CachedManager {
|
class ChannelManager extends CachedManager {
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
* @param {Client} client The client
|
||||||
|
* @param {unknown[]} iterable existing channels
|
||||||
|
*/
|
||||||
constructor(client, iterable) {
|
constructor(client, iterable) {
|
||||||
super(client, BaseChannel, iterable);
|
super(client, BaseChannel, iterable);
|
||||||
|
|
||||||
const defaultCaching =
|
const defaultCaching =
|
||||||
this._cache.constructor.name === 'Collection' ||
|
this._cache.constructor.name === 'Collection' ||
|
||||||
this._cache.maxSize === undefined ||
|
this._cache.maxSize === undefined ||
|
||||||
this._cache.maxSize === Infinity;
|
this._cache.maxSize === Infinity;
|
||||||
|
|
||||||
if (!cacheWarningEmitted && !defaultCaching) {
|
if (!cacheWarningEmitted && !defaultCaching) {
|
||||||
cacheWarningEmitted = true;
|
cacheWarningEmitted = true;
|
||||||
process.emitWarning(
|
process.emitWarning(
|
||||||
@@ -36,6 +48,15 @@ class ChannelManager extends CachedManager {
|
|||||||
* @name ChannelManager#cache
|
* @name ChannelManager#cache
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// eslint-disable-next-line valid-jsdoc
|
||||||
|
/**
|
||||||
|
* @ignore
|
||||||
|
* @param {import('discord-api-types/v10').APIChannel} data
|
||||||
|
* @param {Guild} [guild]
|
||||||
|
* @param {{ cache?: boolean; allowUnknownGuild?: boolean; }} [options]
|
||||||
|
* @returns {?BaseChannel}
|
||||||
|
* @override
|
||||||
|
*/
|
||||||
_add(data, guild, { cache = true, allowUnknownGuild = false } = {}) {
|
_add(data, guild, { cache = true, allowUnknownGuild = false } = {}) {
|
||||||
const existing = this.cache.get(data.id);
|
const existing = this.cache.get(data.id);
|
||||||
if (existing) {
|
if (existing) {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ const getMediaChannel = lazy(() => require('../structures/MediaChannel'));
|
|||||||
/**
|
/**
|
||||||
* Extra options for creating a channel.
|
* Extra options for creating a channel.
|
||||||
* @typedef {Object} CreateChannelOptions
|
* @typedef {Object} CreateChannelOptions
|
||||||
* @property {boolean} [allowFromUnknownGuild] Whether to allow creating a channel from an unknown guild
|
* @property {boolean} [allowUnknownGuild] Whether to allow creating a channel from an unknown guild
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user