refactor: new node features (#5132)

Co-authored-by: Antonio Román <kyradiscord@gmail.com>
This commit is contained in:
Sugden
2021-06-30 21:40:33 +01:00
committed by GitHub
parent f108746c15
commit 1e8f01253e
68 changed files with 305 additions and 360 deletions

View File

@@ -212,11 +212,11 @@ class Collector extends EventEmitter {
resetTimer({ time, idle } = {}) {
if (this._timeout) {
this.client.clearTimeout(this._timeout);
this._timeout = this.client.setTimeout(() => this.stop('time'), time || this.options.time);
this._timeout = this.client.setTimeout(() => this.stop('time'), time ?? this.options.time);
}
if (this._idletimeout) {
this.client.clearTimeout(this._idletimeout);
this._idletimeout = this.client.setTimeout(() => this.stop('idle'), idle || this.options.idle);
this._idletimeout = this.client.setTimeout(() => this.stop('idle'), idle ?? this.options.idle);
}
}

View File

@@ -39,7 +39,7 @@ class TextBasedChannel {
* @readonly
*/
get lastMessage() {
return this.messages.cache.get(this.lastMessageID) || null;
return this.messages.resolve(this.lastMessageID);
}
/**
@@ -185,7 +185,7 @@ class TextBasedChannel {
if (typeof count !== 'undefined' && count < 1) throw new RangeError('TYPING_COUNT');
if (this.client.user._typing.has(this.id)) {
const entry = this.client.user._typing.get(this.id);
entry.count = count || entry.count + 1;
entry.count = count ?? entry.count + 1;
return entry.promise;
}
@@ -193,7 +193,7 @@ class TextBasedChannel {
entry.promise = new Promise((resolve, reject) => {
const endpoint = this.client.api.channels[this.id].typing;
Object.assign(entry, {
count: count || 1,
count: count ?? 1,
interval: this.client.setInterval(() => {
endpoint.post().catch(error => {
this.client.clearInterval(entry.interval);
@@ -252,8 +252,7 @@ class TextBasedChannel {
* @readonly
*/
get typingCount() {
if (this.client.user._typing.has(this.id)) return this.client.user._typing.get(this.id).count;
return 0;
return this.client.user._typing.get(this.id)?.count ?? 0;
}
/**
@@ -294,7 +293,7 @@ class TextBasedChannel {
return new Promise((resolve, reject) => {
const collector = this.createMessageCollector(options);
collector.once('end', (collection, reason) => {
if (options.errors && options.errors.includes(reason)) {
if (options.errors?.includes(reason)) {
reject(collection);
} else {
resolve(collection);
@@ -355,7 +354,7 @@ class TextBasedChannel {
*/
async bulkDelete(messages, filterOld = false) {
if (Array.isArray(messages) || messages instanceof Collection) {
let messageIDs = messages instanceof Collection ? messages.keyArray() : messages.map(m => m.id || m);
let messageIDs = messages instanceof Collection ? messages.keyArray() : messages.map(m => m.id ?? m);
if (filterOld) {
messageIDs = messageIDs.filter(id => Date.now() - SnowflakeUtil.deconstruct(id).timestamp < 1209600000);
}