feat: message forwarding (#10464)

* feat: message forwarding

* fix: redundant usage

* feat: add additional snapshot fields

* refactor: use collection to store snapshots

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
TÆMBØ
2024-09-29 04:35:40 -07:00
committed by Jiralite
parent 0873f9a4c3
commit c12217829b
3 changed files with 53 additions and 0 deletions

View File

@@ -364,6 +364,7 @@ class Message extends Base {
* @property {Snowflake} channelId The channel id that was referenced
* @property {Snowflake|undefined} guildId The guild id that was referenced
* @property {Snowflake|undefined} messageId The message id that was referenced
* @property {MessageReferenceType} type The type of message reference
*/
if ('message_reference' in data) {
@@ -375,6 +376,7 @@ class Message extends Base {
channelId: data.message_reference.channel_id,
guildId: data.message_reference.guild_id,
messageId: data.message_reference.message_id,
type: data.message_reference.type,
};
} else {
this.reference ??= null;
@@ -448,6 +450,29 @@ class Message extends Base {
this.poll ??= null;
}
if (data.message_snapshots) {
/**
* The message associated with the message reference
* @type {Collection<Snowflake, Message>}
*/
this.messageSnapshots = data.message_snapshots.reduce((coll, snapshot) => {
const channel = this.client.channels.resolve(this.reference.channelId);
const snapshotData = {
...snapshot.message,
id: this.reference.messageId,
channel_id: this.reference.channelId,
guild_id: this.reference.guildId,
};
return coll.set(
this.reference.messageId,
channel ? channel.messages._add(snapshotData) : new this.constructor(this.client, snapshotData),
);
}, new Collection());
} else {
this.messageSnapshots ??= new Collection();
}
/**
* A call associated with a message
* @typedef {Object} MessageCall

View File

@@ -455,6 +455,11 @@
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/MessageActivityType}
*/
/**
* @external MessageReferenceType
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/MessageReferenceType}
*/
/**
* @external MessageType
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/enum/MessageType}

View File

@@ -185,6 +185,7 @@ import {
InviteType,
ReactionType,
APIAuthorizingIntegrationOwnersMap,
MessageReferenceType,
} from 'discord-api-types/v10';
import { ChildProcess } from 'node:child_process';
import { EventEmitter } from 'node:events';
@@ -2185,6 +2186,7 @@ export class Message<InGuild extends boolean = boolean> extends Base {
public webhookId: Snowflake | null;
public flags: Readonly<MessageFlagsBitField>;
public reference: MessageReference | null;
public messageSnapshots: Collection<Snowflake, MessageSnapshot>;
public awaitMessageComponent<ComponentType extends MessageComponentType>(
options?: AwaitMessageCollectorOptionsParams<ComponentType, InGuild>,
): Promise<MappedInteractionTypes<InGuild>[ComponentType]>;
@@ -6442,6 +6444,26 @@ export interface MessageMentionOptions {
export type MessageMentionTypes = 'roles' | 'users' | 'everyone';
export interface MessageSnapshot
extends Partialize<
Message,
null,
Exclude<
keyof Message,
| 'attachments'
| 'client'
| 'components'
| 'content'
| 'createdTimestamp'
| 'editedTimestamp'
| 'embeds'
| 'flags'
| 'mentions'
| 'stickers'
| 'type'
>
> {}
export interface BaseMessageOptions {
content?: string;
embeds?: readonly (JSONEncodable<APIEmbed> | APIEmbed)[];
@@ -6497,6 +6519,7 @@ export interface MessageReference {
channelId: Snowflake;
guildId: Snowflake | undefined;
messageId: Snowflake | undefined;
type: MessageReferenceType;
}
export type MessageResolvable = Message | Snowflake;