mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 20:43:30 +01:00
refactor: remove lastMessage properties from User and GuildMember (#6046)
This commit is contained in:
@@ -13,17 +13,7 @@ class MessageCreateAction extends Action {
|
|||||||
const existing = channel.messages.cache.get(data.id);
|
const existing = channel.messages.cache.get(data.id);
|
||||||
if (existing) return { message: existing };
|
if (existing) return { message: existing };
|
||||||
const message = channel.messages.add(data);
|
const message = channel.messages.add(data);
|
||||||
const user = message.author;
|
|
||||||
const member = message.member;
|
|
||||||
channel.lastMessageId = data.id;
|
channel.lastMessageId = data.id;
|
||||||
if (user) {
|
|
||||||
user.lastMessageId = data.id;
|
|
||||||
user.lastMessageChannelId = channel.id;
|
|
||||||
}
|
|
||||||
if (member) {
|
|
||||||
member.lastMessageId = data.id;
|
|
||||||
member.lastMessageChannelId = channel.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Emitted whenever a message is created.
|
* Emitted whenever a message is created.
|
||||||
|
|||||||
@@ -34,18 +34,6 @@ class GuildMember extends Base {
|
|||||||
*/
|
*/
|
||||||
this.joinedTimestamp = null;
|
this.joinedTimestamp = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* The member's last message id, if one was sent
|
|
||||||
* @type {?Snowflake}
|
|
||||||
*/
|
|
||||||
this.lastMessageId = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The id of the channel for the last message sent by the member in their guild, if one was sent
|
|
||||||
* @type {?Snowflake}
|
|
||||||
*/
|
|
||||||
this.lastMessageChannelId = null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The timestamp of when the member used their Nitro boost on the guild, if it was used
|
* The timestamp of when the member used their Nitro boost on the guild, if it was used
|
||||||
* @type {?number}
|
* @type {?number}
|
||||||
@@ -116,15 +104,6 @@ class GuildMember extends Base {
|
|||||||
return new GuildMemberRoleManager(this);
|
return new GuildMemberRoleManager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The Message object of the last message sent by the member in their guild, if one was sent
|
|
||||||
* @type {?Message}
|
|
||||||
* @readonly
|
|
||||||
*/
|
|
||||||
get lastMessage() {
|
|
||||||
return this.guild.channels.resolve(this.lastMessageChannelId)?.messages.resolve(this.lastMessageId) ?? null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The voice state of this member
|
* The voice state of this member
|
||||||
* @type {VoiceState}
|
* @type {VoiceState}
|
||||||
@@ -352,8 +331,6 @@ class GuildMember extends Base {
|
|||||||
this.partial === member.partial &&
|
this.partial === member.partial &&
|
||||||
this.guild.id === member.guild.id &&
|
this.guild.id === member.guild.id &&
|
||||||
this.joinedTimestamp === member.joinedTimestamp &&
|
this.joinedTimestamp === member.joinedTimestamp &&
|
||||||
this.lastMessageId === member.lastMessageId &&
|
|
||||||
this.lastMessageChannelId === member.lastMessageChannelId &&
|
|
||||||
this.nickname === member.nickname &&
|
this.nickname === member.nickname &&
|
||||||
this.pending === member.pending &&
|
this.pending === member.pending &&
|
||||||
(this._roles === member._roles ||
|
(this._roles === member._roles ||
|
||||||
@@ -377,8 +354,6 @@ class GuildMember extends Base {
|
|||||||
guild: 'guildId',
|
guild: 'guildId',
|
||||||
user: 'userId',
|
user: 'userId',
|
||||||
displayName: true,
|
displayName: true,
|
||||||
lastMessage: false,
|
|
||||||
lastMessageId: false,
|
|
||||||
roles: true,
|
roles: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,18 +32,6 @@ class User extends Base {
|
|||||||
|
|
||||||
this.flags = null;
|
this.flags = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* The user's last message id, if one was sent
|
|
||||||
* @type {?Snowflake}
|
|
||||||
*/
|
|
||||||
this.lastMessageId = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The channel in which the last message was sent by the user, if one was sent
|
|
||||||
* @type {?Snowflake}
|
|
||||||
*/
|
|
||||||
this.lastMessageChannelId = null;
|
|
||||||
|
|
||||||
this._patch(data);
|
this._patch(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,15 +122,6 @@ class User extends Base {
|
|||||||
return new Date(this.createdTimestamp);
|
return new Date(this.createdTimestamp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* The Message object of the last message sent by the user, if one was sent
|
|
||||||
* @type {?Message}
|
|
||||||
* @readonly
|
|
||||||
*/
|
|
||||||
get lastMessage() {
|
|
||||||
return this.client.channels.resolve(this.lastMessageChannelId)?.messages.resolve(this.lastMessageId) ?? null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The presence of this user
|
* The presence of this user
|
||||||
* @type {Presence}
|
* @type {Presence}
|
||||||
@@ -316,8 +295,6 @@ class User extends Base {
|
|||||||
createdTimestamp: true,
|
createdTimestamp: true,
|
||||||
defaultAvatarURL: true,
|
defaultAvatarURL: true,
|
||||||
tag: true,
|
tag: true,
|
||||||
lastMessage: false,
|
|
||||||
lastMessageId: false,
|
|
||||||
},
|
},
|
||||||
...props,
|
...props,
|
||||||
);
|
);
|
||||||
|
|||||||
6
typings/index.d.ts
vendored
6
typings/index.d.ts
vendored
@@ -681,7 +681,6 @@ export class GuildMember extends PartialTextBasedChannel(Base) {
|
|||||||
public readonly joinedAt: Date | null;
|
public readonly joinedAt: Date | null;
|
||||||
public joinedTimestamp: number | null;
|
public joinedTimestamp: number | null;
|
||||||
public readonly kickable: boolean;
|
public readonly kickable: boolean;
|
||||||
public lastMessageChannelId: Snowflake | null;
|
|
||||||
public readonly manageable: boolean;
|
public readonly manageable: boolean;
|
||||||
public nickname: string | null;
|
public nickname: string | null;
|
||||||
public readonly partial: false;
|
public readonly partial: false;
|
||||||
@@ -1646,7 +1645,6 @@ export class User extends PartialTextBasedChannel(Base) {
|
|||||||
public readonly dmChannel: DMChannel | null;
|
public readonly dmChannel: DMChannel | null;
|
||||||
public flags: Readonly<UserFlags> | null;
|
public flags: Readonly<UserFlags> | null;
|
||||||
public id: Snowflake;
|
public id: Snowflake;
|
||||||
public lastMessageId: Snowflake | null;
|
|
||||||
public readonly partial: false;
|
public readonly partial: false;
|
||||||
public readonly presence: Presence;
|
public readonly presence: Presence;
|
||||||
public system: boolean;
|
public system: boolean;
|
||||||
@@ -2531,13 +2529,13 @@ export function TextBasedChannel<T, I extends keyof TextBasedChannelFields = nev
|
|||||||
): Constructable<T & Omit<TextBasedChannelFields, I>>;
|
): Constructable<T & Omit<TextBasedChannelFields, I>>;
|
||||||
|
|
||||||
export interface PartialTextBasedChannelFields {
|
export interface PartialTextBasedChannelFields {
|
||||||
lastMessageId: Snowflake | null;
|
|
||||||
readonly lastMessage: Message | null;
|
|
||||||
send(options: string | MessagePayload | MessageOptions): Promise<Message>;
|
send(options: string | MessagePayload | MessageOptions): Promise<Message>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TextBasedChannelFields extends PartialTextBasedChannelFields {
|
export interface TextBasedChannelFields extends PartialTextBasedChannelFields {
|
||||||
_typing: Map<string, TypingData>;
|
_typing: Map<string, TypingData>;
|
||||||
|
lastMessageId: Snowflake | null;
|
||||||
|
readonly lastMessage: Message | null;
|
||||||
lastPinTimestamp: number | null;
|
lastPinTimestamp: number | null;
|
||||||
readonly lastPinAt: Date | null;
|
readonly lastPinAt: Date | null;
|
||||||
typing: boolean;
|
typing: boolean;
|
||||||
|
|||||||
@@ -1,17 +1,25 @@
|
|||||||
import {
|
import {
|
||||||
Client,
|
Client,
|
||||||
Collection,
|
Collection,
|
||||||
|
DMChannel,
|
||||||
|
GuildMember,
|
||||||
Intents,
|
Intents,
|
||||||
Message,
|
Message,
|
||||||
MessageActionRow,
|
MessageActionRow,
|
||||||
MessageAttachment,
|
MessageAttachment,
|
||||||
MessageButton,
|
MessageButton,
|
||||||
MessageEmbed,
|
MessageEmbed,
|
||||||
|
NewsChannel,
|
||||||
Options,
|
Options,
|
||||||
|
PartialTextBasedChannelFields,
|
||||||
Permissions,
|
Permissions,
|
||||||
Serialized,
|
Serialized,
|
||||||
ShardClientUtil,
|
ShardClientUtil,
|
||||||
ShardingManager,
|
ShardingManager,
|
||||||
|
TextBasedChannelFields,
|
||||||
|
TextChannel,
|
||||||
|
ThreadChannel,
|
||||||
|
User,
|
||||||
} from '..';
|
} from '..';
|
||||||
|
|
||||||
const client: Client = new Client({
|
const client: Client = new Client({
|
||||||
@@ -455,3 +463,27 @@ assertType<Promise<number[]>>(shardingManager.broadcastEval(() => 1));
|
|||||||
assertType<Promise<number[]>>(shardClientUtil.broadcastEval(() => 1));
|
assertType<Promise<number[]>>(shardClientUtil.broadcastEval(() => 1));
|
||||||
assertType<Promise<number[]>>(shardingManager.broadcastEval(async () => 1));
|
assertType<Promise<number[]>>(shardingManager.broadcastEval(async () => 1));
|
||||||
assertType<Promise<number[]>>(shardClientUtil.broadcastEval(async () => 1));
|
assertType<Promise<number[]>>(shardClientUtil.broadcastEval(async () => 1));
|
||||||
|
|
||||||
|
declare const dmChannel: DMChannel;
|
||||||
|
declare const threadChannel: ThreadChannel;
|
||||||
|
declare const newsChannel: NewsChannel;
|
||||||
|
declare const textChannel: TextChannel;
|
||||||
|
declare const user: User;
|
||||||
|
declare const guildMember: GuildMember;
|
||||||
|
|
||||||
|
// Test whether the structures implement send
|
||||||
|
assertType<TextBasedChannelFields['send']>(dmChannel.send);
|
||||||
|
assertType<TextBasedChannelFields>(threadChannel);
|
||||||
|
assertType<TextBasedChannelFields>(newsChannel);
|
||||||
|
assertType<TextBasedChannelFields>(textChannel);
|
||||||
|
assertType<PartialTextBasedChannelFields>(user);
|
||||||
|
assertType<PartialTextBasedChannelFields>(guildMember);
|
||||||
|
|
||||||
|
assertType<Message | null>(dmChannel.lastMessage);
|
||||||
|
assertType<Message | null>(threadChannel.lastMessage);
|
||||||
|
assertType<Message | null>(newsChannel.lastMessage);
|
||||||
|
assertType<Message | null>(textChannel.lastMessage);
|
||||||
|
// @ts-expect-error
|
||||||
|
assertType<never>(user.lastMessage);
|
||||||
|
// @ts-expect-error
|
||||||
|
assertType<never>(guildMember.lastMessage);
|
||||||
|
|||||||
Reference in New Issue
Block a user