2022-03-19 10:37:45 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const EventEmitter = require('node:events');
|
|
|
|
const RESTManager = require('../rest/RESTManager');
|
|
|
|
const Options = require('../util/Options');
|
|
|
|
const Util = require('../util/Util');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base class for all clients.
|
|
|
|
* @extends {EventEmitter}
|
|
|
|
*/
|
|
|
|
class BaseClient extends EventEmitter {
|
|
|
|
constructor(options = {}) {
|
2022-03-24 10:55:32 +00:00
|
|
|
super();
|
2022-03-19 10:37:45 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The options the client was instantiated with
|
|
|
|
* @type {ClientOptions}
|
|
|
|
*/
|
|
|
|
this.options = Util.mergeDefault(Options.createDefault(), options);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The REST manager of the client
|
2022-03-24 10:55:32 +00:00
|
|
|
* @type {RESTManager}
|
|
|
|
* @private
|
2022-03-19 10:37:45 +00:00
|
|
|
*/
|
|
|
|
this.rest = new RESTManager(this);
|
|
|
|
}
|
|
|
|
|
2022-03-24 10:55:32 +00:00
|
|
|
/**
|
|
|
|
* API shortcut
|
|
|
|
* @type {Object}
|
|
|
|
* @readonly
|
|
|
|
* @private
|
|
|
|
*/
|
2022-03-19 10:37:45 +00:00
|
|
|
get api() {
|
|
|
|
return this.rest.api;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys all assets used by the base client.
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
destroy() {
|
2022-03-24 10:55:32 +00:00
|
|
|
if (this.rest.sweepInterval) clearInterval(this.rest.sweepInterval);
|
2022-03-19 10:37:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Increments max listeners by one, if they are not zero.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
incrementMaxListeners() {
|
|
|
|
const maxListeners = this.getMaxListeners();
|
|
|
|
if (maxListeners !== 0) {
|
|
|
|
this.setMaxListeners(maxListeners + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decrements max listeners by one, if they are not zero.
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
decrementMaxListeners() {
|
|
|
|
const maxListeners = this.getMaxListeners();
|
|
|
|
if (maxListeners !== 0) {
|
|
|
|
this.setMaxListeners(maxListeners - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
toJSON(...props) {
|
|
|
|
return Util.flatten(this, { domain: false }, ...props);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = BaseClient;
|
|
|
|
|
|
|
|
/**
|
2022-03-24 10:55:32 +00:00
|
|
|
* Emitted for general debugging information.
|
|
|
|
* @event BaseClient#debug
|
|
|
|
* @param {string} info The debug information
|
2022-03-19 10:37:45 +00:00
|
|
|
*/
|