mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
Add new ESLint rules
This commit is contained in:
@@ -8,6 +8,8 @@
|
||||
"node": true
|
||||
},
|
||||
"rules": {
|
||||
"no-await-in-loop": "warn",
|
||||
"no-compare-neg-zero": "error",
|
||||
"no-extra-parens": ["warn", "all", {
|
||||
"nestedBinaryExpressions": false
|
||||
}],
|
||||
@@ -53,6 +55,7 @@
|
||||
"no-new": "error",
|
||||
"no-octal-escape": "error",
|
||||
"no-return-assign": "error",
|
||||
"no-return-await": "error",
|
||||
"no-self-compare": "error",
|
||||
"no-sequences": "error",
|
||||
"no-throw-literal": "error",
|
||||
@@ -61,8 +64,11 @@
|
||||
"no-useless-call": "error",
|
||||
"no-useless-concat": "error",
|
||||
"no-useless-escape": "error",
|
||||
"no-useless-return": "error",
|
||||
"no-void": "error",
|
||||
"no-warning-comments": "warn",
|
||||
"prefer-promise-reject-errors": "error",
|
||||
"require-await": "warn",
|
||||
"wrap-iife": "error",
|
||||
"yoda": "error",
|
||||
|
||||
@@ -79,6 +85,7 @@
|
||||
"array-bracket-spacing": "error",
|
||||
"block-spacing": "error",
|
||||
"brace-style": ["error", "1tbs", { "allowSingleLine": true }],
|
||||
"capitalized-comments": ["error", "always", { "ignoreConsecutiveComments": true }],
|
||||
"comma-dangle": ["error", "always-multiline"],
|
||||
"comma-spacing": "error",
|
||||
"comma-style": "error",
|
||||
@@ -107,6 +114,7 @@
|
||||
"no-trailing-spaces": "error",
|
||||
"no-unneeded-ternary": "error",
|
||||
"no-whitespace-before-property": "error",
|
||||
"nonblock-statement-body-position": "error",
|
||||
"object-curly-spacing": ["error", "always"],
|
||||
"operator-assignment": "error",
|
||||
"operator-linebreak": ["error", "after"],
|
||||
@@ -121,6 +129,7 @@
|
||||
"space-infix-ops": "error",
|
||||
"space-unary-ops": "error",
|
||||
"spaced-comment": "error",
|
||||
"template-tag-spacing": "error",
|
||||
"unicode-bom": "error",
|
||||
|
||||
"arrow-body-style": "error",
|
||||
|
||||
@@ -17,18 +17,18 @@ class GuildDeleteAction extends Action {
|
||||
}
|
||||
|
||||
if (guild.available && data.unavailable) {
|
||||
// guild is unavailable
|
||||
// Guild is unavailable
|
||||
guild.available = false;
|
||||
client.emit(Constants.Events.GUILD_UNAVAILABLE, guild);
|
||||
|
||||
// stops the GuildDelete packet thinking a guild was actually deleted,
|
||||
// Stops the GuildDelete packet thinking a guild was actually deleted,
|
||||
// handles emitting of event itself
|
||||
return {
|
||||
guild: null,
|
||||
};
|
||||
}
|
||||
|
||||
// delete guild
|
||||
// Delete guild
|
||||
client.guilds.delete(guild.id);
|
||||
this.deleted.set(guild.id, guild);
|
||||
this.scheduleForDeletion(guild.id);
|
||||
|
||||
@@ -354,7 +354,7 @@ class RESTMethods {
|
||||
});
|
||||
}
|
||||
|
||||
// untested but probably will work
|
||||
// Untested but probably will work
|
||||
deleteGuild(guild) {
|
||||
return this.rest.makeRequest('del', Constants.Endpoints.guild(guild.id), true).then(() =>
|
||||
this.client.actions.GuildDelete.handle({ id: guild.id }).guild
|
||||
@@ -486,7 +486,7 @@ class RESTMethods {
|
||||
if (data.roles) data.roles = data.roles.map(role => role instanceof Role ? role.id : role);
|
||||
|
||||
let endpoint = Constants.Endpoints.guildMember(member.guild.id, member.id);
|
||||
// fix your endpoints, discord ;-;
|
||||
// Fix your endpoints, discord ;-;
|
||||
if (member.id === this.client.user.id) {
|
||||
const keys = Object.keys(data);
|
||||
if (keys.length === 1 && keys[0] === 'nick') {
|
||||
|
||||
@@ -43,9 +43,7 @@ class RequestHandler {
|
||||
/**
|
||||
* Attempts to get this RequestHandler to process its current queue
|
||||
*/
|
||||
handle() {
|
||||
return;
|
||||
}
|
||||
handle() {} // eslint-disable-line no-empty-function
|
||||
}
|
||||
|
||||
module.exports = RequestHandler;
|
||||
|
||||
@@ -267,6 +267,7 @@ class VoiceBroadcast extends VolumeInterface {
|
||||
|
||||
_startPlaying() {
|
||||
if (this.tickInterval) clearInterval(this.tickInterval);
|
||||
// Old code?
|
||||
// this.tickInterval = this.client.setInterval(this.tick.bind(this), 20);
|
||||
this._startTime = Date.now();
|
||||
this._count = 0;
|
||||
|
||||
@@ -203,6 +203,7 @@ class StreamDispatcher extends VolumeInterface {
|
||||
|
||||
if (this.paused) {
|
||||
this.setSpeaking(false);
|
||||
// Old code?
|
||||
// data.timestamp = data.timestamp + 4294967295 ? data.timestamp + 960 : 0;
|
||||
data.pausedTime += data.length * 10;
|
||||
this.player.voiceConnection.voiceManager.client.setTimeout(() => this.process(), data.length * 10);
|
||||
|
||||
@@ -11,9 +11,7 @@ class BaseOpus {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
destroy() {
|
||||
return;
|
||||
}
|
||||
destroy() {} // eslint-disable-line no-empty-function
|
||||
}
|
||||
|
||||
module.exports = BaseOpus;
|
||||
|
||||
@@ -7,9 +7,7 @@ class VoiceReadable extends Readable {
|
||||
this.open = true;
|
||||
}
|
||||
|
||||
_read() {
|
||||
return;
|
||||
}
|
||||
_read() {} // eslint-disable-line no-empty-function
|
||||
|
||||
_push(d) {
|
||||
if (this.open) this.push(d);
|
||||
|
||||
@@ -20,7 +20,7 @@ class VoiceReceiver extends EventEmitter {
|
||||
constructor(connection) {
|
||||
super();
|
||||
/*
|
||||
need a queue because we don't get the ssrc of the user speaking until after the first few packets,
|
||||
Need a queue because we don't get the ssrc of the user speaking until after the first few packets,
|
||||
so we queue up unknown SSRCs until they become known, then empty the queue.
|
||||
*/
|
||||
this.queues = new Map();
|
||||
@@ -68,7 +68,6 @@ class VoiceReceiver extends EventEmitter {
|
||||
if (!this.destroyed) return;
|
||||
this.voiceConnection.sockets.udp.socket.on('message', this._listener);
|
||||
this.destroyed = false;
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,12 +8,12 @@ class GuildCreateHandler extends AbstractHandler {
|
||||
const guild = client.guilds.get(data.id);
|
||||
if (guild) {
|
||||
if (!guild.available && !data.unavailable) {
|
||||
// a newly available guild
|
||||
// A newly available guild
|
||||
guild.setup(data);
|
||||
this.packetManager.ws.checkIfReady();
|
||||
}
|
||||
} else {
|
||||
// a new guild
|
||||
// A new guild
|
||||
client.dataManager.newGuild(data);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,22 +16,22 @@ class GuildEmojisUpdate extends AbstractHandler {
|
||||
const deletions = mappify(guild.emojis.entries());
|
||||
|
||||
for (const emoji of data.emojis) {
|
||||
// determine type of emoji event
|
||||
// Determine type of emoji event
|
||||
const cachedEmoji = guild.emojis.get(emoji.id);
|
||||
if (cachedEmoji) {
|
||||
deletions.delete(emoji.id);
|
||||
if (!cachedEmoji.equals(emoji, true)) {
|
||||
// emoji updated
|
||||
// Emoji updated
|
||||
client.actions.GuildEmojiUpdate.handle(cachedEmoji, emoji);
|
||||
}
|
||||
} else {
|
||||
// emoji added
|
||||
// Emoji added
|
||||
client.actions.GuildEmojiCreate.handle(guild, emoji);
|
||||
}
|
||||
}
|
||||
|
||||
for (const emoji of deletions.values()) {
|
||||
// emoji deleted
|
||||
// Emoji deleted
|
||||
client.actions.GuildEmojiDelete.handle(emoji);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const AbstractHandler = require('./AbstractHandler');
|
||||
const Constants = require('../../../../util/Constants');
|
||||
// uncomment in v12
|
||||
// Uncomment in v12
|
||||
// const Collection = require('../../../../util/Collection');
|
||||
|
||||
class GuildMembersChunkHandler extends AbstractHandler {
|
||||
@@ -10,7 +10,7 @@ class GuildMembersChunkHandler extends AbstractHandler {
|
||||
const guild = client.guilds.get(data.guild_id);
|
||||
if (!guild) return;
|
||||
|
||||
// uncomment in v12
|
||||
// Uncomment in v12
|
||||
// const members = new Collection();
|
||||
//
|
||||
// for (const member of data.members) members.set(member.id, guild._addMember(member, false));
|
||||
|
||||
@@ -9,7 +9,7 @@ class PresenceUpdateHandler extends AbstractHandler {
|
||||
let user = client.users.get(data.user.id);
|
||||
const guild = client.guilds.get(data.guild_id);
|
||||
|
||||
// step 1
|
||||
// Step 1
|
||||
if (!user) {
|
||||
if (data.user.username) {
|
||||
user = client.dataManager.newUser(data.user);
|
||||
|
||||
@@ -17,7 +17,7 @@ class VoiceStateUpdateHandler extends AbstractHandler {
|
||||
member.voiceChannel.members.delete(oldVoiceChannelMember.id);
|
||||
}
|
||||
|
||||
// if the member left the voice channel, unset their speaking property
|
||||
// If the member left the voice channel, unset their speaking property
|
||||
if (!data.channel_id) member.speaking = null;
|
||||
|
||||
if (member.user.id === client.user.id && data.channel_id) {
|
||||
|
||||
@@ -37,25 +37,26 @@ class DMChannel extends Channel {
|
||||
}
|
||||
|
||||
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
||||
send() { return; }
|
||||
sendMessage() { return; }
|
||||
sendEmbed() { return; }
|
||||
sendFile() { return; }
|
||||
sendFiles() { return; }
|
||||
sendCode() { return; }
|
||||
fetchMessage() { return; }
|
||||
fetchMessages() { return; }
|
||||
fetchPinnedMessages() { return; }
|
||||
search() { return; }
|
||||
startTyping() { return; }
|
||||
stopTyping() { return; }
|
||||
get typing() { return; }
|
||||
get typingCount() { return; }
|
||||
createCollector() { return; }
|
||||
awaitMessages() { return; }
|
||||
// doesn't work on DM channels; bulkDelete() { return; }
|
||||
acknowledge() { return; }
|
||||
_cacheMessage() { return; }
|
||||
/* eslint-disable no-empty-function */
|
||||
send() {}
|
||||
sendMessage() {}
|
||||
sendEmbed() {}
|
||||
sendFile() {}
|
||||
sendFiles() {}
|
||||
sendCode() {}
|
||||
fetchMessage() {}
|
||||
fetchMessages() {}
|
||||
fetchPinnedMessages() {}
|
||||
search() {}
|
||||
startTyping() {}
|
||||
stopTyping() {}
|
||||
get typing() {}
|
||||
get typingCount() {}
|
||||
createCollector() {}
|
||||
awaitMessages() {}
|
||||
// Doesn't work on DM channels; bulkDelete() {}
|
||||
acknowledge() {}
|
||||
_cacheMessage() {}
|
||||
}
|
||||
|
||||
TextBasedChannel.applyToClass(DMChannel, true, ['bulkDelete']);
|
||||
|
||||
@@ -153,25 +153,26 @@ class GroupDMChannel extends Channel {
|
||||
}
|
||||
|
||||
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
||||
send() { return; }
|
||||
sendMessage() { return; }
|
||||
sendEmbed() { return; }
|
||||
sendFile() { return; }
|
||||
sendFiles() { return; }
|
||||
sendCode() { return; }
|
||||
fetchMessage() { return; }
|
||||
fetchMessages() { return; }
|
||||
fetchPinnedMessages() { return; }
|
||||
search() { return; }
|
||||
startTyping() { return; }
|
||||
stopTyping() { return; }
|
||||
get typing() { return; }
|
||||
get typingCount() { return; }
|
||||
createCollector() { return; }
|
||||
awaitMessages() { return; }
|
||||
// doesn't work on group DMs; bulkDelete() { return; }
|
||||
acknowledge() { return; }
|
||||
_cacheMessage() { return; }
|
||||
/* eslint-disable no-empty-function */
|
||||
send() {}
|
||||
sendMessage() {}
|
||||
sendEmbed() {}
|
||||
sendFile() {}
|
||||
sendFiles() {}
|
||||
sendCode() {}
|
||||
fetchMessage() {}
|
||||
fetchMessages() {}
|
||||
fetchPinnedMessages() {}
|
||||
search() {}
|
||||
startTyping() {}
|
||||
stopTyping() {}
|
||||
get typing() {}
|
||||
get typingCount() {}
|
||||
createCollector() {}
|
||||
awaitMessages() {}
|
||||
// Doesn't work on group DMs; bulkDelete() {}
|
||||
acknowledge() {}
|
||||
_cacheMessage() {}
|
||||
}
|
||||
|
||||
TextBasedChannel.applyToClass(GroupDMChannel, true, ['bulkDelete']);
|
||||
|
||||
@@ -371,7 +371,7 @@ class Guild {
|
||||
fetchMembers(query = '', limit = 0) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (this.memberCount === this.members.size) {
|
||||
// uncomment in v12
|
||||
// Uncomment in v12
|
||||
// resolve(this.members)
|
||||
resolve(this);
|
||||
return;
|
||||
@@ -388,10 +388,9 @@ class Guild {
|
||||
if (guild.id !== this.id) return;
|
||||
if (this.memberCount === this.members.size || members.length < 1000) {
|
||||
this.client.removeListener(Constants.Events.GUILD_MEMBERS_CHUNK, handler);
|
||||
// uncomment in v12
|
||||
// Uncomment in v12
|
||||
// resolve(this.members)
|
||||
resolve(this);
|
||||
return;
|
||||
}
|
||||
};
|
||||
this.client.on(Constants.Events.GUILD_MEMBERS_CHUNK, handler);
|
||||
|
||||
@@ -501,11 +501,12 @@ class GuildMember {
|
||||
}
|
||||
|
||||
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
||||
send() { return; }
|
||||
sendMessage() { return; }
|
||||
sendEmbed() { return; }
|
||||
sendFile() { return; }
|
||||
sendCode() { return; }
|
||||
/* eslint-disable no-empty-function */
|
||||
send() {}
|
||||
sendMessage() {}
|
||||
sendEmbed() {}
|
||||
sendFile() {}
|
||||
sendCode() {}
|
||||
}
|
||||
|
||||
TextBasedChannel.applyToClass(GuildMember);
|
||||
|
||||
@@ -119,7 +119,7 @@ class MessageCollector extends EventEmitter {
|
||||
|
||||
const onEnd = (...args) => {
|
||||
cleanup();
|
||||
reject(...args);
|
||||
reject(...args); // eslint-disable-line prefer-promise-reject-errors
|
||||
};
|
||||
|
||||
this.once('message', onMessage);
|
||||
|
||||
@@ -42,7 +42,7 @@ class MessageReaction {
|
||||
*/
|
||||
get emoji() {
|
||||
if (this._emoji instanceof Emoji) return this._emoji;
|
||||
// check to see if the emoji has become known to the client
|
||||
// Check to see if the emoji has become known to the client
|
||||
if (this._emoji.id) {
|
||||
const emojis = this.message.client.emojis;
|
||||
if (emojis.has(this._emoji.id)) {
|
||||
@@ -62,7 +62,7 @@ class MessageReaction {
|
||||
remove(user = this.message.client.user) {
|
||||
const message = this.message;
|
||||
user = this.message.client.resolver.resolveUserID(user);
|
||||
if (!user) return Promise.reject('Couldn\'t resolve the user ID to remove from the reaction.');
|
||||
if (!user) return Promise.reject(new Error('Couldn\'t resolve the user ID to remove from the reaction.'));
|
||||
return message.client.rest.methods.removeMessageReaction(
|
||||
message, this.emoji.identifier, user
|
||||
);
|
||||
|
||||
@@ -90,7 +90,7 @@ class OAuth2Application {
|
||||
this.flags = data.flags;
|
||||
|
||||
/**
|
||||
* oauth2 secret for the app
|
||||
* OAuth2 secret for the application
|
||||
* @type {boolean}
|
||||
*/
|
||||
this.secret = data.secret;
|
||||
|
||||
@@ -73,25 +73,26 @@ class TextChannel extends GuildChannel {
|
||||
}
|
||||
|
||||
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
||||
send() { return; }
|
||||
sendMessage() { return; }
|
||||
sendEmbed() { return; }
|
||||
sendFile() { return; }
|
||||
sendFiles() { return; }
|
||||
sendCode() { return; }
|
||||
fetchMessage() { return; }
|
||||
fetchMessages() { return; }
|
||||
fetchPinnedMessages() { return; }
|
||||
search() { return; }
|
||||
startTyping() { return; }
|
||||
stopTyping() { return; }
|
||||
get typing() { return; }
|
||||
get typingCount() { return; }
|
||||
createCollector() { return; }
|
||||
awaitMessages() { return; }
|
||||
bulkDelete() { return; }
|
||||
acknowledge() { return; }
|
||||
_cacheMessage() { return; }
|
||||
/* eslint-disable no-empty-function */
|
||||
send() {}
|
||||
sendMessage() {}
|
||||
sendEmbed() {}
|
||||
sendFile() {}
|
||||
sendFiles() {}
|
||||
sendCode() {}
|
||||
fetchMessage() {}
|
||||
fetchMessages() {}
|
||||
fetchPinnedMessages() {}
|
||||
search() {}
|
||||
startTyping() {}
|
||||
stopTyping() {}
|
||||
get typing() {}
|
||||
get typingCount() {}
|
||||
createCollector() {}
|
||||
awaitMessages() {}
|
||||
bulkDelete() {}
|
||||
acknowledge() {}
|
||||
_cacheMessage() {}
|
||||
}
|
||||
|
||||
TextBasedChannel.applyToClass(TextChannel, true);
|
||||
|
||||
@@ -280,11 +280,12 @@ class User {
|
||||
}
|
||||
|
||||
// These are here only for documentation purposes - they are implemented by TextBasedChannel
|
||||
send() { return; }
|
||||
sendMessage() { return; }
|
||||
sendEmbed() { return; }
|
||||
sendFile() { return; }
|
||||
sendCode() { return; }
|
||||
/* eslint-disable no-empty-function */
|
||||
send() {}
|
||||
sendMessage() {}
|
||||
sendEmbed() {}
|
||||
sendFile() {}
|
||||
sendCode() {}
|
||||
}
|
||||
|
||||
TextBasedChannel.applyToClass(User);
|
||||
|
||||
@@ -38,7 +38,7 @@ class UserConnection {
|
||||
this.revoked = data.revoked;
|
||||
|
||||
/**
|
||||
* an array of partial server integrations (not yet implemented in this lib)
|
||||
* Partial server integrations (not yet implemented)
|
||||
* @type {Object[]}
|
||||
*/
|
||||
this.integrations = data.integrations;
|
||||
|
||||
@@ -81,7 +81,6 @@ class TextBasedChannel {
|
||||
|
||||
if (options.embed && options.embed.file) options.file = options.embed.file;
|
||||
|
||||
// backward compat
|
||||
if (options.file) {
|
||||
if (options.files) options.files.push(options.file);
|
||||
else options.files = [options.file];
|
||||
|
||||
@@ -82,7 +82,7 @@ const PROTOCOL_VERSION = exports.PROTOCOL_VERSION = 6;
|
||||
const HOST = exports.HOST = `https://discordapp.com`;
|
||||
const API = exports.API = `${HOST}/api/v${PROTOCOL_VERSION}`;
|
||||
const Endpoints = exports.Endpoints = {
|
||||
// general
|
||||
// General
|
||||
login: `${API}/auth/login`,
|
||||
logout: `${API}/auth/logout`,
|
||||
gateway: `${API}/gateway`,
|
||||
@@ -92,7 +92,7 @@ const Endpoints = exports.Endpoints = {
|
||||
assets: asset => `${HOST}/assets/${asset}`,
|
||||
CDN: 'https://cdn.discordapp.com',
|
||||
|
||||
// users
|
||||
// Users
|
||||
user: userID => `${API}/users/${userID}`,
|
||||
userChannels: userID => `${Endpoints.user(userID)}/channels`,
|
||||
userProfile: userID => `${Endpoints.user(userID)}/profile`,
|
||||
@@ -110,7 +110,7 @@ const Endpoints = exports.Endpoints = {
|
||||
|
||||
voiceRegions: `${API}/voice/regions`,
|
||||
|
||||
// guilds
|
||||
// Guilds
|
||||
guilds: `${API}/guilds`,
|
||||
guild: guildID => `${Endpoints.guilds}/${guildID}`,
|
||||
guildIcon: (guildID, hash) => `${Endpoints.CDN}/icons/${guildID}/${hash}.jpg`,
|
||||
@@ -132,7 +132,7 @@ const Endpoints = exports.Endpoints = {
|
||||
guildSearch: guildID => `${Endpoints.guild(guildID)}/messages/search`,
|
||||
guildVoiceRegions: guildID => `${Endpoints.guild(guildID)}/regions`,
|
||||
|
||||
// channels
|
||||
// Channels
|
||||
channels: `${API}/channels`,
|
||||
channel: channelID => `${Endpoints.channels}/${channelID}`,
|
||||
channelMessages: channelID => `${Endpoints.channel(channelID)}/messages`,
|
||||
@@ -145,7 +145,7 @@ const Endpoints = exports.Endpoints = {
|
||||
|
||||
dmChannelRecipient: (channelID, recipientID) => `${Endpoints.channel(channelID)}/recipients/${recipientID}`,
|
||||
|
||||
// message reactions
|
||||
// Message reactions
|
||||
messageReactions: (channelID, messageID) => `${Endpoints.channelMessage(channelID, messageID)}/reactions`,
|
||||
messageReaction:
|
||||
(channel, msg, emoji, limit) =>
|
||||
@@ -156,14 +156,14 @@ const Endpoints = exports.Endpoints = {
|
||||
userMessageReaction: (channel, msg, emoji, limit, id) =>
|
||||
`${Endpoints.messageReaction(channel, msg, emoji, limit)}/${id}`,
|
||||
|
||||
// webhooks
|
||||
// Webhooks
|
||||
webhook: (webhookID, token) => `${API}/webhooks/${webhookID}${token ? `/${token}` : ''}`,
|
||||
|
||||
// oauth
|
||||
// OAuth
|
||||
oauth2Application: appID => `${API}/oauth2/applications/${appID}`,
|
||||
getApp: id => `${API}/oauth2/authorize?client_id=${id}`,
|
||||
|
||||
// emoji
|
||||
// Emoji
|
||||
emoji: emojiID => `${Endpoints.CDN}/emojis/${emojiID}.png`,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user