diff options
author | sowgro <tpoke.ferrari@gmail.com> | 2023-09-02 19:12:47 -0400 |
---|---|---|
committer | sowgro <tpoke.ferrari@gmail.com> | 2023-09-02 19:12:47 -0400 |
commit | e4450c8417624b71d779cb4f41692538f9165e10 (patch) | |
tree | b70826542223ecdf8a7a259f61b0a1abb8a217d8 /node_modules/discord.js/src/client/BaseClient.js | |
download | sowbot3-e4450c8417624b71d779cb4f41692538f9165e10.tar.gz sowbot3-e4450c8417624b71d779cb4f41692538f9165e10.tar.bz2 sowbot3-e4450c8417624b71d779cb4f41692538f9165e10.zip |
first commit
Diffstat (limited to 'node_modules/discord.js/src/client/BaseClient.js')
-rw-r--r-- | node_modules/discord.js/src/client/BaseClient.js | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/node_modules/discord.js/src/client/BaseClient.js b/node_modules/discord.js/src/client/BaseClient.js new file mode 100644 index 0000000..631748c --- /dev/null +++ b/node_modules/discord.js/src/client/BaseClient.js @@ -0,0 +1,83 @@ +'use strict'; + +const EventEmitter = require('node:events'); +const { REST } = require('@discordjs/rest'); +const { DiscordjsTypeError, ErrorCodes } = require('../errors'); +const Options = require('../util/Options'); +const { mergeDefault, flatten } = require('../util/Util'); + +/** + * The base class for all clients. + * @extends {EventEmitter} + */ +class BaseClient extends EventEmitter { + constructor(options = {}) { + super({ captureRejections: true }); + + if (typeof options !== 'object' || options === null) { + throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options', 'object', true); + } + + /** + * The options the client was instantiated with + * @type {ClientOptions} + */ + this.options = mergeDefault(Options.createDefault(), { + ...options, + rest: { + ...options.rest, + userAgentAppendix: options.rest?.userAgentAppendix + ? `${Options.userAgentAppendix} ${options.rest.userAgentAppendix}` + : undefined, + }, + }); + + /** + * The REST manager of the client + * @type {REST} + */ + this.rest = new REST(this.options.rest); + } + + /** + * Destroys all assets used by the base client. + * @returns {void} + */ + destroy() { + this.rest.clearHashSweeper(); + this.rest.clearHandlerSweeper(); + } + + /** + * 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 flatten(this, ...props); + } +} + +module.exports = BaseClient; + +/** + * @external REST + * @see {@link https://discord.js.org/docs/packages/rest/stable/REST:Class} + */ |