mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 17:43:30 +01:00
Switch config back to camelCase
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -29,12 +29,12 @@ class Client extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
this.options = mergeDefault(Constants.DefaultOptions, options);
|
this.options = mergeDefault(Constants.DefaultOptions, options);
|
||||||
|
|
||||||
if (!this.options.shard_id && 'SHARD_ID' in process.env) {
|
if (!this.options.shardId && 'SHARD_ID' in process.env) {
|
||||||
this.options.shard_id = Number(process.env.SHARD_ID);
|
this.options.shardId = Number(process.env.SHARD_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.options.shard_count && 'SHARD_COUNT' in process.env) {
|
if (!this.options.shardCount && 'SHARD_COUNT' in process.env) {
|
||||||
this.options.shard_count = Number(process.env.SHARD_COUNT);
|
this.options.shardCount = Number(process.env.SHARD_COUNT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -150,8 +150,8 @@ class Client extends EventEmitter {
|
|||||||
this._timeouts = new Set();
|
this._timeouts = new Set();
|
||||||
this._intervals = new Set();
|
this._intervals = new Set();
|
||||||
|
|
||||||
if (this.options.message_sweep_interval > 0) {
|
if (this.options.messageSweepInterval > 0) {
|
||||||
this.setInterval(this.sweepMessages.bind(this), this.options.message_sweep_interval * 1000);
|
this.setInterval(this.sweepMessages.bind(this), this.options.messageSweepInterval * 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,12 +273,12 @@ class Client extends EventEmitter {
|
|||||||
/**
|
/**
|
||||||
* Sweeps all channels' messages and removes the ones older than the max message lifetime.
|
* Sweeps all channels' messages and removes the ones older than the max message lifetime.
|
||||||
* If the message has been edited, the time of the edit is used rather than the time of the original message.
|
* If the message has been edited, the time of the edit is used rather than the time of the original message.
|
||||||
* @param {number} [lifetime=this.options.message_cache_lifetime] Messages that are older than this (in seconds)
|
* @param {number} [lifetime=this.options.messageCacheLifetime] Messages that are older than this (in seconds)
|
||||||
* will be removed from the caches. The default is based on the client's `message_cache_lifetime` option.
|
* will be removed from the caches. The default is based on the client's `messageCacheLifetime` option.
|
||||||
* @returns {number} Amount of messages that were removed from the caches,
|
* @returns {number} Amount of messages that were removed from the caches,
|
||||||
* or -1 if the message cache lifetime is unlimited
|
* or -1 if the message cache lifetime is unlimited
|
||||||
*/
|
*/
|
||||||
sweepMessages(lifetime = this.options.message_cache_lifetime) {
|
sweepMessages(lifetime = this.options.messageCacheLifetime) {
|
||||||
if (typeof lifetime !== 'number' || isNaN(lifetime)) throw new TypeError('Lifetime must be a number.');
|
if (typeof lifetime !== 'number' || isNaN(lifetime)) throw new TypeError('Lifetime must be a number.');
|
||||||
if (lifetime <= 0) {
|
if (lifetime <= 0) {
|
||||||
this.emit('debug', 'Didn\'t sweep messages - lifetime is unlimited');
|
this.emit('debug', 'Didn\'t sweep messages - lifetime is unlimited');
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class ClientDataManager {
|
|||||||
* @event Client#guildCreate
|
* @event Client#guildCreate
|
||||||
* @param {Guild} guild The created guild
|
* @param {Guild} guild The created guild
|
||||||
*/
|
*/
|
||||||
if (this.client.options.fetch_all_members) {
|
if (this.client.options.fetchAllMembers) {
|
||||||
guild.fetchMembers().then(() => { this.client.emit(Constants.Events.GUILD_CREATE, guild); });
|
guild.fetchMembers().then(() => { this.client.emit(Constants.Events.GUILD_CREATE, guild); });
|
||||||
} else {
|
} else {
|
||||||
this.client.emit(Constants.Events.GUILD_CREATE, guild);
|
this.client.emit(Constants.Events.GUILD_CREATE, guild);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ class ChannelDeleteAction extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
scheduleForDeletion(id) {
|
scheduleForDeletion(id) {
|
||||||
this.client.setTimeout(() => this.deleted.delete(id), this.client.options.rest_ws_bridge_timeout);
|
this.client.setTimeout(() => this.deleted.delete(id), this.client.options.restWsBridgeTimeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ class GuildDeleteAction extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
scheduleForDeletion(id) {
|
scheduleForDeletion(id) {
|
||||||
this.client.setTimeout(() => this.deleted.delete(id), this.client.options.rest_ws_bridge_timeout);
|
this.client.setTimeout(() => this.deleted.delete(id), this.client.options.restWsBridgeTimeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class GuildMemberRemoveAction extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
scheduleForDeletion(guildID, userID) {
|
scheduleForDeletion(guildID, userID) {
|
||||||
this.client.setTimeout(() => this.deleted.delete(guildID + userID), this.client.options.rest_ws_bridge_timeout);
|
this.client.setTimeout(() => this.deleted.delete(guildID + userID), this.client.options.restWsBridgeTimeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class GuildRoleDeleteAction extends Action {
|
|||||||
}
|
}
|
||||||
|
|
||||||
scheduleForDeletion(guildID, roleID) {
|
scheduleForDeletion(guildID, roleID) {
|
||||||
this.client.setTimeout(() => this.deleted.delete(guildID + roleID), this.client.options.rest_ws_bridge_timeout);
|
this.client.setTimeout(() => this.deleted.delete(guildID + roleID), this.client.options.restWsBridgeTimeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class MessageDeleteAction extends Action {
|
|||||||
|
|
||||||
scheduleForDeletion(channelID, messageID) {
|
scheduleForDeletion(channelID, messageID) {
|
||||||
this.client.setTimeout(() => this.deleted.delete(channelID + messageID),
|
this.client.setTimeout(() => this.deleted.delete(channelID + messageID),
|
||||||
this.client.options.rest_ws_bridge_timeout);
|
this.client.options.restWsBridgeTimeout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ class RESTManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getRequestHandler() {
|
getRequestHandler() {
|
||||||
switch (this.client.options.api_request_method) {
|
switch (this.client.options.apiRequestMethod) {
|
||||||
case 'sequential':
|
case 'sequential':
|
||||||
return SequentialRequestHandler;
|
return SequentialRequestHandler;
|
||||||
case 'burst':
|
case 'burst':
|
||||||
|
|||||||
@@ -41,18 +41,18 @@ class RESTMethods {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
this.rest.makeRequest('get', Constants.Endpoints.gateway, true)
|
this.rest.makeRequest('get', Constants.Endpoints.gateway, true)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
this.rest.client.ws.gateway = `${res.url}/?encoding=json&v=${this.rest.client.options.protocol_version}`;
|
this.rest.client.ws.gateway = `${res.url}/?encoding=json&v=${this.rest.client.options.protocolVersion}`;
|
||||||
resolve(this.rest.client.ws.gateway);
|
resolve(this.rest.client.ws.gateway);
|
||||||
})
|
})
|
||||||
.catch(reject);
|
.catch(reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(channel, content, { tts, nonce, disable_everyone, split } = {}, file = null) {
|
sendMessage(channel, content, { tts, nonce, disableEveryone, split } = {}, file = null) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (typeof content !== 'undefined') content = this.rest.client.resolver.resolveString(content);
|
if (typeof content !== 'undefined') content = this.rest.client.resolver.resolveString(content);
|
||||||
|
|
||||||
if (disable_everyone || (typeof disable_everyone === 'undefined' && this.rest.client.options.disable_everyone)) {
|
if (disableEveryone || (typeof disableEveryone === 'undefined' && this.rest.client.options.disableEveryone)) {
|
||||||
content = content.replace('@everyone', '@\u200beveryone').replace('@here', '@\u200bhere');
|
content = content.replace('@everyone', '@\u200beveryone').replace('@here', '@\u200bhere');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -171,8 +171,8 @@ class WebSocketManager extends EventEmitter {
|
|||||||
this.reconnecting = false;
|
this.reconnecting = false;
|
||||||
const payload = this.client.options.ws;
|
const payload = this.client.options.ws;
|
||||||
payload.token = this.client.token;
|
payload.token = this.client.token;
|
||||||
if (this.client.options.shard_count > 0) {
|
if (this.client.options.shardCount > 0) {
|
||||||
payload.shard = [Number(this.client.options.shard_id), Number(this.client.options.shard_count)];
|
payload.shard = [Number(this.client.options.shardId), Number(this.client.options.shardCount)];
|
||||||
}
|
}
|
||||||
this.client.emit('debug', 'Identifying as new session');
|
this.client.emit('debug', 'Identifying as new session');
|
||||||
this.send({
|
this.send({
|
||||||
@@ -256,7 +256,7 @@ class WebSocketManager extends EventEmitter {
|
|||||||
}
|
}
|
||||||
if (unavailableCount === 0) {
|
if (unavailableCount === 0) {
|
||||||
this.status = Constants.Status.NEARLY;
|
this.status = Constants.Status.NEARLY;
|
||||||
if (this.client.options.fetch_all_members) {
|
if (this.client.options.fetchAllMembers) {
|
||||||
const promises = this.client.guilds.array().map(g => g.fetchMembers());
|
const promises = this.client.guilds.array().map(g => g.fetchMembers());
|
||||||
Promise.all(promises).then(() => this._emitReady()).catch(e => {
|
Promise.all(promises).then(() => this._emitReady()).catch(e => {
|
||||||
this.client.emit(Constants.Event.WARN, `Error on pre-ready guild member fetching - ${e}`);
|
this.client.emit(Constants.Event.WARN, `Error on pre-ready guild member fetching - ${e}`);
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class ShardClientUtil {
|
|||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
get id() {
|
get id() {
|
||||||
return this.client.options.shard_id;
|
return this.client.options.shardId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -26,7 +26,7 @@ class ShardClientUtil {
|
|||||||
* @type {number}
|
* @type {number}
|
||||||
*/
|
*/
|
||||||
get count() {
|
get count() {
|
||||||
return this.client.options.shard_count;
|
return this.client.options.shardCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class TextBasedChannel {
|
|||||||
* @typedef {Object} MessageOptions
|
* @typedef {Object} MessageOptions
|
||||||
* @property {boolean} [tts=false] Whether or not the message should be spoken aloud
|
* @property {boolean} [tts=false] Whether or not the message should be spoken aloud
|
||||||
* @property {string} [nonce=''] The nonce for the message
|
* @property {string} [nonce=''] The nonce for the message
|
||||||
* @property {boolean} [disable_everyone=this.client.options.disable_everyone] Whether or not @everyone and @here
|
* @property {boolean} [disableEveryone=this.client.options.disableEveryone] Whether or not @everyone and @here
|
||||||
* should be replaced with plain-text
|
* should be replaced with plain-text
|
||||||
* @property {boolean|SplitOptions} [split=false] Whether or not the message should be split into multiple messages if
|
* @property {boolean|SplitOptions} [split=false] Whether or not the message should be split into multiple messages if
|
||||||
* it exceeds the character limit. If an object is provided, these are the options for splitting the message.
|
* it exceeds the character limit. If an object is provided, these are the options for splitting the message.
|
||||||
@@ -320,7 +320,7 @@ class TextBasedChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_cacheMessage(message) {
|
_cacheMessage(message) {
|
||||||
const maxSize = this.client.options.max_message_cache;
|
const maxSize = this.client.options.maxMessageCache;
|
||||||
if (maxSize === 0) return null;
|
if (maxSize === 0) return null;
|
||||||
if (this.messages.size >= maxSize) this.messages.delete(this.messages.keys().next().value);
|
if (this.messages.size >= maxSize) this.messages.delete(this.messages.keys().next().value);
|
||||||
|
|
||||||
|
|||||||
@@ -1,35 +1,35 @@
|
|||||||
/**
|
/**
|
||||||
* Options for a Client.
|
* Options for a Client.
|
||||||
* @typedef {Object} ClientOptions
|
* @typedef {Object} ClientOptions
|
||||||
* @property {string} [api_request_method='sequential'] 'sequential' or 'burst'. Sequential executes all requests in
|
* @property {string} [apiRequestMethod='sequential'] 'sequential' or 'burst'. Sequential executes all requests in
|
||||||
* the order they are triggered, whereas burst runs multiple at a time, and doesn't guarantee a particular order.
|
* the order they are triggered, whereas burst runs multiple at a time, and doesn't guarantee a particular order.
|
||||||
* @property {number} [shard_id=0] The ID of this shard
|
* @property {number} [shardId=0] The ID of this shard
|
||||||
* @property {number} [shard_count=0] The number of shards
|
* @property {number} [shardCount=0] The number of shards
|
||||||
* @property {number} [max_message_cache=200] Number of messages to cache per channel
|
* @property {number} [maxMessageCache=200] Number of messages to cache per channel
|
||||||
* @property {number} [message_cache_lifetime=0] How long until a message should be uncached by the message sweeping
|
* @property {number} [messageCacheLifetime=0] How long until a message should be uncached by the message sweeping
|
||||||
* (in seconds, 0 for forever)
|
* (in seconds, 0 for forever)
|
||||||
* @property {number} [message_sweep_interval=0] How frequently to remove messages from the cache that are older than
|
* @property {number} [messageSweepInterval=0] How frequently to remove messages from the cache that are older than
|
||||||
* the max message lifetime (in seconds, 0 for never)
|
* the max message lifetime (in seconds, 0 for never)
|
||||||
* @property {boolean} [fetch_all_members=false] Whether to cache all guild members and users upon startup
|
* @property {boolean} [fetchAllMembers=false] Whether to cache all guild members and users upon startup
|
||||||
* @property {boolean} [disable_everyone=false] Default value for MessageOptions.disable_everyone
|
* @property {boolean} [disableEveryone=false] Default value for MessageOptions.disableEveryone
|
||||||
* @property {number} [rest_ws_bridge_timeout=5000] Maximum time permitted between REST responses and their
|
* @property {number} [restWsBridgeTimeout=5000] Maximum time permitted between REST responses and their
|
||||||
* corresponding websocket events
|
* corresponding websocket events
|
||||||
* @property {WebsocketOptions} [ws] Options for the websocket
|
* @property {WebsocketOptions} [ws] Options for the websocket
|
||||||
*/
|
*/
|
||||||
exports.DefaultOptions = {
|
exports.DefaultOptions = {
|
||||||
api_request_method: 'sequential',
|
apiRequestMethod: 'sequential',
|
||||||
shard_id: 0,
|
shardId: 0,
|
||||||
shard_count: 0,
|
shardCount: 0,
|
||||||
max_message_cache: 200,
|
maxMessageCache: 200,
|
||||||
message_cache_lifetime: 0,
|
messageCacheLifetime: 0,
|
||||||
message_sweep_interval: 0,
|
messageSweepInterval: 0,
|
||||||
fetch_all_members: false,
|
fetchAllMembers: false,
|
||||||
disable_everyone: false,
|
disableEveryone: false,
|
||||||
rest_ws_bridge_timeout: 5000,
|
restWsBridgeTimeout: 5000,
|
||||||
protocol_version: 6,
|
protocolVersion: 6,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Websocket options.
|
* Websocket options. These are left as snake_case to match the API.
|
||||||
* @typedef {Object} WebsocketOptions
|
* @typedef {Object} WebsocketOptions
|
||||||
* @property {number} [large_threshold=250] Number of members in a guild to be considered large
|
* @property {number} [large_threshold=250] Number of members in a guild to be considered large
|
||||||
* @property {boolean} [compress=true] Whether to compress data sent on the connection
|
* @property {boolean} [compress=true] Whether to compress data sent on the connection
|
||||||
@@ -72,10 +72,10 @@ exports.Errors = {
|
|||||||
NOT_A_PERMISSION: 'Invalid permission string or number.',
|
NOT_A_PERMISSION: 'Invalid permission string or number.',
|
||||||
INVALID_RATE_LIMIT_METHOD: 'Unknown rate limiting method.',
|
INVALID_RATE_LIMIT_METHOD: 'Unknown rate limiting method.',
|
||||||
BAD_LOGIN: 'Incorrect login details were provided.',
|
BAD_LOGIN: 'Incorrect login details were provided.',
|
||||||
INVALID_SHARD: 'Invalid shard settings were provided',
|
INVALID_SHARD: 'Invalid shard settings were provided.',
|
||||||
};
|
};
|
||||||
|
|
||||||
const API = `https://discordapp.com/api/v${exports.DefaultOptions.protocol_version}`;
|
const API = `https://discordapp.com/api/v${exports.DefaultOptions.protocolVersion}`;
|
||||||
|
|
||||||
const Endpoints = exports.Endpoints = {
|
const Endpoints = exports.Endpoints = {
|
||||||
// general endpoints
|
// general endpoints
|
||||||
|
|||||||
Reference in New Issue
Block a user