feat: componentContext#deferUpdate

This commit is contained in:
MARCROCK22 2024-10-21 01:20:39 +00:00
parent cf50543ff4
commit ddb320c428
3 changed files with 21 additions and 7 deletions

View File

@ -5,6 +5,7 @@ import {
type If, type If,
type WatcherPayload, type WatcherPayload,
type WatcherSendToShard, type WatcherSendToShard,
hasIntent,
lazyLoadPackage, lazyLoadPackage,
} from '../common'; } from '../common';
import { EventHandler } from '../events'; import { EventHandler } from '../events';
@ -186,11 +187,13 @@ export class Client<Ready extends boolean = boolean> extends BaseClient {
break; break;
case 'READY': { case 'READY': {
const ids = packet.d.guilds.map(x => x.id); const ids = packet.d.guilds.map(x => x.id);
this.__handleGuilds = this.__handleGuilds?.concat(ids) ?? ids; if (hasIntent(this.gateway.options.intents, 'Guilds')) {
this.__handleGuilds = this.__handleGuilds?.concat(ids) ?? ids;
}
this.botId = packet.d.user.id; this.botId = packet.d.user.id;
this.applicationId = packet.d.application.id; this.applicationId = packet.d.application.id;
this.me = Transformers.ClientUser(this, packet.d.user, packet.d.application) as never; this.me = Transformers.ClientUser(this, packet.d.user, packet.d.application) as never;
if (!this.__handleGuilds.length) { if (!this.__handleGuilds?.length) {
if ([...this.gateway.values()].every(shard => shard.data.session_id)) { if ([...this.gateway.values()].every(shard => shard.data.session_id)) {
await this.events?.runEvent('BOT_READY', this, this.me, -1); await this.events?.runEvent('BOT_READY', this, this.me, -1);
} }

View File

@ -1,7 +1,7 @@
import { type UUID, randomUUID } from 'node:crypto'; import { type UUID, randomUUID } from 'node:crypto';
import { ApiHandler, Logger } from '..'; import { ApiHandler, Logger } from '..';
import { WorkerAdapter } from '../cache'; import { WorkerAdapter } from '../cache';
import { type DeepPartial, LogLevels, type When, lazyLoadPackage } from '../common'; import { type DeepPartial, LogLevels, type When, hasIntent, lazyLoadPackage } from '../common';
import { EventHandler } from '../events'; import { EventHandler } from '../events';
import type { GatewayDispatchPayload, GatewaySendPayload } from '../types'; import type { GatewayDispatchPayload, GatewaySendPayload } from '../types';
import { Shard, type ShardManagerOptions, type WorkerData, properties } from '../websocket'; import { Shard, type ShardManagerOptions, type WorkerData, properties } from '../websocket';
@ -271,9 +271,11 @@ export class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
shardsConnected++; shardsConnected++;
const ids = payload.d.guilds.map(x => x.id); const ids = payload.d.guilds.map(x => x.id);
self.__handleGuildsResharding = self.__handleGuildsResharding?.concat(ids) ?? ids; if (hasIntent(workerData.intents, 'Guilds')) {
self.__handleGuildsResharding = self.__handleGuildsResharding?.concat(ids) ?? ids;
}
if (shardsConnected === workerData.shards.length && !self.__handleGuildsResharding.length) { if (shardsConnected === workerData.shards.length && !self.__handleGuildsResharding?.length) {
delete self.__handleGuildsResharding; delete self.__handleGuildsResharding;
self.postMessage({ self.postMessage({
type: 'WORKER_READY_RESHARDING', type: 'WORKER_READY_RESHARDING',
@ -532,7 +534,9 @@ export class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
case 'READY': case 'READY':
{ {
const ids = packet.d.guilds.map(x => x.id); const ids = packet.d.guilds.map(x => x.id);
this.__handleGuilds = this.__handleGuilds?.concat(ids) ?? ids; if (hasIntent(this.workerData.intents, 'Guilds')) {
this.__handleGuilds = this.__handleGuilds?.concat(ids) ?? ids;
}
this.botId = packet.d.user.id; this.botId = packet.d.user.id;
this.applicationId = packet.d.application.id; this.applicationId = packet.d.application.id;
this.me = Transformers.ClientUser(this, packet.d.user, packet.d.application) as never; this.me = Transformers.ClientUser(this, packet.d.user, packet.d.application) as never;
@ -545,7 +549,7 @@ export class WorkerClient<Ready extends boolean = boolean> extends BaseClient {
} as WorkerShardsConnected); } as WorkerShardsConnected);
await this.events?.runEvent('WORKER_SHARDS_CONNECTED', this, this.me, -1); await this.events?.runEvent('WORKER_SHARDS_CONNECTED', this, this.me, -1);
} }
if (!this.__handleGuilds.length) { if (!this.__handleGuilds!.length) {
if ([...this.shards.values()].every(shard => shard.data.session_id)) { if ([...this.shards.values()].every(shard => shard.data.session_id)) {
this.postMessage({ this.postMessage({
type: 'WORKER_READY', type: 'WORKER_READY',

View File

@ -88,6 +88,13 @@ export class ComponentContext<
return this.interaction.deferReply(ephemeral ? MessageFlags.Ephemeral : undefined); return this.interaction.deferReply(ephemeral ? MessageFlags.Ephemeral : undefined);
} }
/**
* ACK an interaction and edit the original message later; the user does not see a loading state
*/
deferUpdate() {
return this.interaction.deferUpdate();
}
/** /**
* Edits the response of the interaction. * Edits the response of the interaction.
* @param body - The updated body of the response. * @param body - The updated body of the response.