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

@@ -34,14 +34,7 @@ class Client extends BaseClient {
constructor(options) {
super(Object.assign({ _tokenType: 'Bot' }, options));
// Obtain shard details from environment or if present, worker threads
let data = process.env;
try {
// Test if worker threads module is present and used
data = require('worker_threads').workerData || data;
} catch {
// Do nothing
}
const data = require('worker_threads').workerData ?? process.env;
if (this.options.shards === DefaultOptions.shards) {
if ('SHARDS' in data) {
@@ -188,7 +181,7 @@ class Client extends BaseClient {
* @readonly
*/
get readyTimestamp() {
return this.readyAt ? this.readyAt.getTime() : null;
return this.readyAt?.getTime() ?? null;
}
/**
@@ -341,7 +334,7 @@ class Client extends BaseClient {
channels++;
messages += channel.messages.cache.sweep(
message => now - (message.editedTimestamp || message.createdTimestamp) > lifetimeMs,
message => now - (message.editedTimestamp ?? message.createdTimestamp) > lifetimeMs,
);
}