mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 04:23:31 +01:00
refactor(Message): remove stored edit history (#5155)
This commit is contained in:
committed by
GitHub
parent
6a77453532
commit
8c2e6b70b8
@@ -459,13 +459,6 @@ class Client extends BaseClient {
|
|||||||
if (typeof options.messageSweepInterval !== 'number' || isNaN(options.messageSweepInterval)) {
|
if (typeof options.messageSweepInterval !== 'number' || isNaN(options.messageSweepInterval)) {
|
||||||
throw new TypeError('CLIENT_INVALID_OPTION', 'messageSweepInterval', 'a number');
|
throw new TypeError('CLIENT_INVALID_OPTION', 'messageSweepInterval', 'a number');
|
||||||
}
|
}
|
||||||
if (
|
|
||||||
typeof options.messageEditHistoryMaxSize !== 'number' ||
|
|
||||||
isNaN(options.messageEditHistoryMaxSize) ||
|
|
||||||
options.messageEditHistoryMaxSize < -1
|
|
||||||
) {
|
|
||||||
throw new TypeError('CLIENT_INVALID_OPTION', 'messageEditHistoryMaxSize', 'a number greater than or equal to -1');
|
|
||||||
}
|
|
||||||
if (typeof options.fetchAllMembers !== 'boolean') {
|
if (typeof options.fetchAllMembers !== 'boolean') {
|
||||||
throw new TypeError('CLIENT_INVALID_OPTION', 'fetchAllMembers', 'a boolean');
|
throw new TypeError('CLIENT_INVALID_OPTION', 'fetchAllMembers', 'a boolean');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -185,13 +185,6 @@ class Message extends Base {
|
|||||||
}
|
}
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
/**
|
|
||||||
* The previous versions of the message, sorted with the most recent first
|
|
||||||
* @type {Message[]}
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
this._edits = [];
|
|
||||||
|
|
||||||
if (this.member && data.member) {
|
if (this.member && data.member) {
|
||||||
this.member._patch(data.member);
|
this.member._patch(data.member);
|
||||||
} else if (data.member && this.guild && this.author) {
|
} else if (data.member && this.guild && this.author) {
|
||||||
@@ -246,11 +239,6 @@ class Message extends Base {
|
|||||||
*/
|
*/
|
||||||
patch(data) {
|
patch(data) {
|
||||||
const clone = this._clone();
|
const clone = this._clone();
|
||||||
const { messageEditHistoryMaxSize } = this.client.options;
|
|
||||||
if (messageEditHistoryMaxSize !== 0) {
|
|
||||||
const editsLimit = messageEditHistoryMaxSize === -1 ? Infinity : messageEditHistoryMaxSize;
|
|
||||||
if (this._edits.unshift(clone) > editsLimit) this._edits.pop();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('edited_timestamp' in data) this.editedTimestamp = new Date(data.edited_timestamp).getTime();
|
if ('edited_timestamp' in data) this.editedTimestamp = new Date(data.edited_timestamp).getTime();
|
||||||
if ('content' in data) this.content = data.content;
|
if ('content' in data) this.content = data.content;
|
||||||
@@ -383,18 +371,6 @@ class Message extends Base {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* An array of cached versions of the message, including the current version
|
|
||||||
* Sorted from latest (first) to oldest (last)
|
|
||||||
* @type {Message[]}
|
|
||||||
* @readonly
|
|
||||||
*/
|
|
||||||
get edits() {
|
|
||||||
const copy = this._edits.slice();
|
|
||||||
copy.unshift(this);
|
|
||||||
return copy;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether the message is editable by the client user
|
* Whether the message is editable by the client user
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
|
|||||||
@@ -18,8 +18,6 @@ const { Error, RangeError } = require('../errors');
|
|||||||
* sweepable (in seconds, 0 for forever)
|
* sweepable (in seconds, 0 for forever)
|
||||||
* @property {number} [messageSweepInterval=0] How frequently to remove messages from the cache that are older than
|
* @property {number} [messageSweepInterval=0] How frequently to remove messages from the cache that are older than
|
||||||
* the message cache lifetime (in seconds, 0 for never)
|
* the message cache lifetime (in seconds, 0 for never)
|
||||||
* @property {number} [messageEditHistoryMaxSize=-1] Maximum number of previous versions to hold for an edited message
|
|
||||||
* (-1 or Infinity for unlimited - don't do this without sweeping, otherwise memory usage may climb indefinitely.)
|
|
||||||
* @property {boolean} [fetchAllMembers=false] Whether to cache all guild members and users upon startup, as well as
|
* @property {boolean} [fetchAllMembers=false] Whether to cache all guild members and users upon startup, as well as
|
||||||
* upon joining a guild (should be avoided whenever possible)
|
* upon joining a guild (should be avoided whenever possible)
|
||||||
* @property {MessageMentionOptions} [allowedMentions] Default value for {@link MessageOptions#allowedMentions}
|
* @property {MessageMentionOptions} [allowedMentions] Default value for {@link MessageOptions#allowedMentions}
|
||||||
@@ -43,7 +41,6 @@ exports.DefaultOptions = {
|
|||||||
messageCacheMaxSize: 200,
|
messageCacheMaxSize: 200,
|
||||||
messageCacheLifetime: 0,
|
messageCacheLifetime: 0,
|
||||||
messageSweepInterval: 0,
|
messageSweepInterval: 0,
|
||||||
messageEditHistoryMaxSize: -1,
|
|
||||||
fetchAllMembers: false,
|
fetchAllMembers: false,
|
||||||
partials: [],
|
partials: [],
|
||||||
restWsBridgeTimeout: 5000,
|
restWsBridgeTimeout: 5000,
|
||||||
|
|||||||
5
typings/index.d.ts
vendored
5
typings/index.d.ts
vendored
@@ -951,7 +951,6 @@ declare module 'discord.js' {
|
|||||||
|
|
||||||
export class Message extends Base {
|
export class Message extends Base {
|
||||||
constructor(client: Client, data: object, channel: TextChannel | DMChannel | NewsChannel);
|
constructor(client: Client, data: object, channel: TextChannel | DMChannel | NewsChannel);
|
||||||
private _edits: Message[];
|
|
||||||
private patch(data: object): Message;
|
private patch(data: object): Message;
|
||||||
|
|
||||||
public activity: MessageActivity | null;
|
public activity: MessageActivity | null;
|
||||||
@@ -968,7 +967,6 @@ declare module 'discord.js' {
|
|||||||
public readonly editable: boolean;
|
public readonly editable: boolean;
|
||||||
public readonly editedAt: Date | null;
|
public readonly editedAt: Date | null;
|
||||||
public editedTimestamp: number | null;
|
public editedTimestamp: number | null;
|
||||||
public readonly edits: Message[];
|
|
||||||
public embeds: MessageEmbed[];
|
public embeds: MessageEmbed[];
|
||||||
public readonly guild: Guild | null;
|
public readonly guild: Guild | null;
|
||||||
public id: Snowflake;
|
public id: Snowflake;
|
||||||
@@ -2332,7 +2330,6 @@ declare module 'discord.js' {
|
|||||||
messageCacheMaxSize?: number;
|
messageCacheMaxSize?: number;
|
||||||
messageCacheLifetime?: number;
|
messageCacheLifetime?: number;
|
||||||
messageSweepInterval?: number;
|
messageSweepInterval?: number;
|
||||||
messageEditHistoryMaxSize?: number;
|
|
||||||
fetchAllMembers?: boolean;
|
fetchAllMembers?: boolean;
|
||||||
allowedMentions?: MessageMentionOptions;
|
allowedMentions?: MessageMentionOptions;
|
||||||
partials?: PartialTypes[];
|
partials?: PartialTypes[];
|
||||||
@@ -3042,7 +3039,6 @@ declare module 'discord.js' {
|
|||||||
| 'pinnable'
|
| 'pinnable'
|
||||||
| 'url'
|
| 'url'
|
||||||
| 'flags'
|
| 'flags'
|
||||||
| 'edits'
|
|
||||||
| 'embeds'
|
| 'embeds'
|
||||||
> {
|
> {
|
||||||
attachments: Message['attachments'];
|
attachments: Message['attachments'];
|
||||||
@@ -3050,7 +3046,6 @@ declare module 'discord.js' {
|
|||||||
readonly deletable: boolean;
|
readonly deletable: boolean;
|
||||||
readonly crosspostable: boolean;
|
readonly crosspostable: boolean;
|
||||||
readonly editable: boolean;
|
readonly editable: boolean;
|
||||||
readonly edits: Message['edits'];
|
|
||||||
embeds: Message['embeds'];
|
embeds: Message['embeds'];
|
||||||
flags: Message['flags'];
|
flags: Message['flags'];
|
||||||
mentions: Message['mentions'];
|
mentions: Message['mentions'];
|
||||||
|
|||||||
Reference in New Issue
Block a user