mirror of
https://github.com/danbulant/discord.js
synced 2026-06-09 17:52:55 +00:00
feat(TextBasedChannel): add lastPinTimestamp and lastPinAt (#2813)
* add lastPinTimestamp * typings * use or instead of ternary
This commit is contained in:
parent
b068abb5de
commit
e96a60361a
6 changed files with 45 additions and 1 deletions
|
|
@ -16,7 +16,12 @@ class ChannelPinsUpdate extends AbstractHandler {
|
||||||
const data = packet.d;
|
const data = packet.d;
|
||||||
const channel = client.channels.get(data.channel_id);
|
const channel = client.channels.get(data.channel_id);
|
||||||
const time = new Date(data.last_pin_timestamp);
|
const time = new Date(data.last_pin_timestamp);
|
||||||
if (channel && time) client.emit(Events.CHANNEL_PINS_UPDATE, channel, time);
|
if (channel && time) {
|
||||||
|
// Discord sends null for last_pin_timestamp if the last pinned message was removed
|
||||||
|
channel.lastPinTimestamp = time.getTime() || null;
|
||||||
|
|
||||||
|
client.emit(Events.CHANNEL_PINS_UPDATE, channel, time);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,12 @@ class DMChannel extends Channel {
|
||||||
* @type {?Snowflake}
|
* @type {?Snowflake}
|
||||||
*/
|
*/
|
||||||
this.lastMessageID = data.last_message_id;
|
this.lastMessageID = data.last_message_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The timestamp when the last pinned message was pinned, if there was one
|
||||||
|
* @type {?number}
|
||||||
|
*/
|
||||||
|
this.lastPinTimestamp = data.last_pin_timestamp ? new Date(data.last_pin_timestamp).getTime() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -49,6 +55,7 @@ class DMChannel extends Channel {
|
||||||
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
||||||
/* eslint-disable no-empty-function */
|
/* eslint-disable no-empty-function */
|
||||||
get lastMessage() {}
|
get lastMessage() {}
|
||||||
|
get lastPinAt() {}
|
||||||
send() {}
|
send() {}
|
||||||
search() {}
|
search() {}
|
||||||
startTyping() {}
|
startTyping() {}
|
||||||
|
|
|
||||||
|
|
@ -103,6 +103,12 @@ class GroupDMChannel extends Channel {
|
||||||
* @type {?Snowflake}
|
* @type {?Snowflake}
|
||||||
*/
|
*/
|
||||||
this.lastMessageID = data.last_message_id;
|
this.lastMessageID = data.last_message_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The timestamp when the last pinned message was pinned, if there was one
|
||||||
|
* @type {?number}
|
||||||
|
*/
|
||||||
|
this.lastPinTimestamp = data.last_pin_timestamp ? new Date(data.last_pin_timestamp).getTime() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -219,6 +225,7 @@ class GroupDMChannel extends Channel {
|
||||||
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
||||||
/* eslint-disable no-empty-function */
|
/* eslint-disable no-empty-function */
|
||||||
get lastMessage() {}
|
get lastMessage() {}
|
||||||
|
get lastPinAt() {}
|
||||||
send() {}
|
send() {}
|
||||||
search() {}
|
search() {}
|
||||||
startTyping() {}
|
startTyping() {}
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,12 @@ class TextChannel extends GuildChannel {
|
||||||
*/
|
*/
|
||||||
this.lastMessageID = data.last_message_id;
|
this.lastMessageID = data.last_message_id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The timestamp when the last pinned message was pinned, if there was one
|
||||||
|
* @type {?number}
|
||||||
|
*/
|
||||||
|
this.lastPinTimestamp = data.last_pin_timestamp ? new Date(data.last_pin_timestamp).getTime() : null;
|
||||||
|
|
||||||
if (data.messages) for (const message of data.messages) this.messages.add(message);
|
if (data.messages) for (const message of data.messages) this.messages.add(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,6 +107,7 @@ class TextChannel extends GuildChannel {
|
||||||
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
||||||
/* eslint-disable no-empty-function */
|
/* eslint-disable no-empty-function */
|
||||||
get lastMessage() {}
|
get lastMessage() {}
|
||||||
|
get lastPinAt() {}
|
||||||
send() {}
|
send() {}
|
||||||
search() {}
|
search() {}
|
||||||
startTyping() {}
|
startTyping() {}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,12 @@ class TextBasedChannel {
|
||||||
* @type {?Snowflake}
|
* @type {?Snowflake}
|
||||||
*/
|
*/
|
||||||
this.lastMessageID = null;
|
this.lastMessageID = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The timestamp when the last pinned message was pinned, if there was one
|
||||||
|
* @type {?number}
|
||||||
|
*/
|
||||||
|
this.lastPinTimestamp = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -32,6 +38,15 @@ class TextBasedChannel {
|
||||||
return this.messages.get(this.lastMessageID) || null;
|
return this.messages.get(this.lastMessageID) || null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The date when the last pinned message was pinned, if there was one
|
||||||
|
* @type {?Date}
|
||||||
|
* @readonly
|
||||||
|
*/
|
||||||
|
get lastPinAt() {
|
||||||
|
return this.lastPinTimestamp ? new Date(this.lastPinTimestamp) : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Options provided when sending or editing a message.
|
* Options provided when sending or editing a message.
|
||||||
* @typedef {Object} MessageOptions
|
* @typedef {Object} MessageOptions
|
||||||
|
|
@ -322,6 +337,7 @@ class TextBasedChannel {
|
||||||
if (full) {
|
if (full) {
|
||||||
props.push(
|
props.push(
|
||||||
'lastMessage',
|
'lastMessage',
|
||||||
|
'lastPinAt',
|
||||||
'bulkDelete',
|
'bulkDelete',
|
||||||
'startTyping',
|
'startTyping',
|
||||||
'stopTyping',
|
'stopTyping',
|
||||||
|
|
|
||||||
2
typings/index.d.ts
vendored
2
typings/index.d.ts
vendored
|
|
@ -1390,6 +1390,8 @@ declare module 'discord.js' {
|
||||||
lastMessageID: Snowflake;
|
lastMessageID: Snowflake;
|
||||||
lastMessageChannelID: Snowflake;
|
lastMessageChannelID: Snowflake;
|
||||||
readonly lastMessage: Message;
|
readonly lastMessage: Message;
|
||||||
|
lastPinTimestamp: number;
|
||||||
|
readonly lastPinAt: Date;
|
||||||
send(content?: StringResolvable, options?: MessageOptions | MessageAdditions): Promise<Message | Message[]>;
|
send(content?: StringResolvable, options?: MessageOptions | MessageAdditions): Promise<Message | Message[]>;
|
||||||
send(options?: MessageOptions | MessageAdditions): Promise<Message | Message[]>;
|
send(options?: MessageOptions | MessageAdditions): Promise<Message | Message[]>;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue