Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
options: ClusterManagerOptions = {},
) {
super();
this.file = file;
if (!options.isAbsolute) {
if (require.main) {
this.file = path.join(path.dirname(require.main.filename), this.file);
}
}
if (!token) {
throw new Error('Token is required for this library to work.');
}
this.token = token;
this.respawn = (options.respawn || options.respawn === undefined);
this.rest = new DetritusRestClient(token, {authType: AuthTypes.BOT});
this.shardCount = +(options.shardCount || this.shardCount);
if (Array.isArray(options.shards)) {
if (options.shards.length !== 2) {
throw new Error('Shards need to be in the format of [shardStart, shardEnd]');
}
const [shardStart, shardEnd] = options.shards;
this.shardEnd = +shardEnd;
this.shardStart = +shardStart;
}
this.shardsPerCluster = +(options.shardsPerCluster || this.shardsPerCluster);
Object.defineProperties(this, {
ran: {configurable: true, writable: false},
rest: {enumerable: false, writable: false},
token: {enumerable: false, writable: false},
shards: {enumerable: true, value: new Map()}
});
if (Array.isArray(options.shards)) {
if (options.shards.length !== 2) {
throw new Error('Shards need to be in the format of [shardStart, shardEnd]');
}
this.setShardStart(options.shards.shift());
this.setShardEnd(options.shards.shift());
}
options.isBot = true;
options.rest = Object.assign({}, options.rest, {authType: 'bot'});
Object.defineProperties(this, {
rest: {value: new RestClient(token, options.rest, this)}
});
options.rest.globalBucket = this.rest.global;
options.pass = Object.assign({}, options.pass, {cluster: this});
options.gateway = Object.assign({}, options.gateway);
Object.defineProperties(this, {
token: {value: token},
clientOptions: {value: options},
ran: {configurable: true, value: false}
});
}