refactor: ES2021 features (#6540)

Co-authored-by: Antonio Román <kyradiscord@gmail.com>
Co-authored-by: Voltrex <mohammadkeyvanzade94@gmail.com>
This commit is contained in:
Rodry
2021-09-03 12:58:01 +01:00
committed by GitHub
parent d81590d566
commit 00bd92a451
35 changed files with 145 additions and 156 deletions

View File

@@ -79,7 +79,7 @@ class LimitedCollection extends Collection {
if (sweepFn === null) return;
if (typeof sweepFn !== 'function') throw new TypeError('SWEEP_FILTER_RETURN');
this.sweep(sweepFn);
}, sweepInterval * 1000).unref()
}, sweepInterval * 1_000).unref()
: null;
}
@@ -129,7 +129,7 @@ class LimitedCollection extends Collection {
}
return () => {
if (lifetime <= 0) return null;
const lifetimeMs = lifetime * 1000;
const lifetimeMs = lifetime * 1_000;
const now = Date.now();
return (entry, key, coll) => {
if (excludeFromSweep(entry, key, coll)) {

View File

@@ -115,8 +115,8 @@ class Options extends null {
messageSweepInterval: 0,
invalidRequestWarningInterval: 0,
partials: [],
restWsBridgeTimeout: 5000,
restRequestTimeout: 15000,
restWsBridgeTimeout: 5_000,
restRequestTimeout: 15_000,
restGlobalRateLimit: 0,
retryLimit: 1,
restTimeOffset: 500,

View File

@@ -3,7 +3,7 @@
const Util = require('./Util');
// Discord epoch (2015-01-01T00:00:00.000Z)
const EPOCH = 1420070400000;
const EPOCH = 1_420_070_400_000;
let INCREMENT = 0;
/**

View File

@@ -69,7 +69,7 @@ class Util extends null {
* @param {SplitOptions} [options] Options controlling the behavior of the split
* @returns {string[]}
*/
static splitMessage(text, { maxLength = 2000, char = '\n', prepend = '', append = '' } = {}) {
static splitMessage(text, { maxLength = 2_000, char = '\n', prepend = '', append = '' } = {}) {
text = Util.verifyString(text);
if (text.length <= maxLength) return [text];
let splitText = [text];
@@ -181,7 +181,7 @@ class Util extends null {
* @returns {string}
*/
static escapeCodeBlock(text) {
return text.replace(/```/g, '\\`\\`\\`');
return text.replaceAll('```', '\\`\\`\\`');
}
/**
@@ -243,7 +243,7 @@ class Util extends null {
* @returns {string}
*/
static escapeStrikethrough(text) {
return text.replace(/~~/g, '\\~\\~');
return text.replaceAll('~~', '\\~\\~');
}
/**
@@ -252,7 +252,7 @@ class Util extends null {
* @returns {string}
*/
static escapeSpoiler(text) {
return text.replace(/\|\|/g, '\\|\\|');
return text.replaceAll('||', '\\|\\|');
}
/**
@@ -267,7 +267,7 @@ class Util extends null {
* @param {FetchRecommendedShardsOptions} [options] Options for fetching the recommended shard count
* @returns {Promise<number>} The recommended number of shards
*/
static async fetchRecommendedShards(token, { guildsPerShard = 1000, multipleOf = 1 } = {}) {
static async fetchRecommendedShards(token, { guildsPerShard = 1_000, multipleOf = 1 } = {}) {
if (!token) throw new DiscordError('TOKEN_MISSING');
const defaults = Options.createDefault();
const response = await fetch(`${defaults.http.api}/v${defaults.http.version}${Endpoints.botGateway}`, {
@@ -279,7 +279,7 @@ class Util extends null {
throw response;
}
const { shards } = await response.json();
return Math.ceil((shards * (1000 / guildsPerShard)) / multipleOf) * multipleOf;
return Math.ceil((shards * (1_000 / guildsPerShard)) / multipleOf) * multipleOf;
}
/**
@@ -534,7 +534,7 @@ class Util extends null {
bin = String(low & 1) + bin;
low = Math.floor(low / 2);
if (high > 0) {
low += 5000000000 * (high % 2);
low += 5_000_000_000 * (high % 2);
high = Math.floor(high / 2);
}
}
@@ -577,7 +577,7 @@ class Util extends null {
* @returns {string}
*/
static removeMentions(str) {
return str.replace(/@/g, '@\u200b');
return str.replaceAll('@', '@\u200b');
}
/**
@@ -621,7 +621,7 @@ class Util extends null {
* @returns {string}
*/
static cleanCodeBlockContent(text) {
return text.replace(/```/g, '`\u200b``');
return text.replaceAll('```', '`\u200b``');
}
/**