mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 17:13:31 +01:00
chore: consistency/prettier (#3852)
* chore: consistency/prettier * chore: rebase * chore: rebase * chore: include typings * fix: include typings file in prettier lint-staged
This commit is contained in:
@@ -1,10 +1,18 @@
|
||||
'use strict';
|
||||
|
||||
const Invite = require('./Invite');
|
||||
const Integration = require('./Integration');
|
||||
const Base = require('./Base');
|
||||
const GuildAuditLogs = require('./GuildAuditLogs');
|
||||
const Webhook = require('./Webhook');
|
||||
const Integration = require('./Integration');
|
||||
const Invite = require('./Invite');
|
||||
const VoiceRegion = require('./VoiceRegion');
|
||||
const Webhook = require('./Webhook');
|
||||
const GuildChannelManager = require('../src/managers/GuildChannelManager');
|
||||
const GuildEmojiManager = require('../src/managers/GuildEmojiManager');
|
||||
const GuildMemberManager = require('../src/managers/GuildMemberManager');
|
||||
const PresenceManager = require('../src/managers/PresenceManager');
|
||||
const RoleManager = require('../src/managers/RoleManager');
|
||||
const VoiceStateManager = require('../src/managers/VoiceStateManager');
|
||||
const Collection = require('../util/Collection');
|
||||
const {
|
||||
ChannelTypes,
|
||||
DefaultMessageNotifications,
|
||||
@@ -12,19 +20,10 @@ const {
|
||||
VerificationLevels,
|
||||
ExplicitContentFilterLevels,
|
||||
} = require('../util/Constants');
|
||||
const Collection = require('../util/Collection');
|
||||
const Util = require('../util/Util');
|
||||
const DataResolver = require('../util/DataResolver');
|
||||
const Snowflake = require('../util/Snowflake');
|
||||
const SystemChannelFlags = require('../util/SystemChannelFlags');
|
||||
const GuildMemberManager = require('../managers/GuildMemberManager');
|
||||
const RoleManager = require('../managers/RoleManager');
|
||||
const GuildEmojiManager = require('../managers/GuildEmojiManager');
|
||||
const GuildChannelManager = require('../managers/GuildChannelManager');
|
||||
const PresenceManager = require('../managers/PresenceManager');
|
||||
const VoiceStateManager = require('../managers/VoiceStateManager');
|
||||
const Base = require('./Base');
|
||||
const { Error, TypeError } = require('../errors');
|
||||
const Util = require('../util/Util');
|
||||
|
||||
/**
|
||||
* Represents a guild (or a server) on Discord.
|
||||
@@ -110,7 +109,6 @@ class Guild extends Base {
|
||||
return this.client.ws.shards.get(this.shardID);
|
||||
}
|
||||
|
||||
/* eslint-disable complexity */
|
||||
/**
|
||||
* Sets up the guild.
|
||||
* @param {*} data The raw data of the guild
|
||||
@@ -279,8 +277,8 @@ class Guild extends Base {
|
||||
* The value set for the guild's default message notifications
|
||||
* @type {DefaultMessageNotifications|number}
|
||||
*/
|
||||
this.defaultMessageNotifications = DefaultMessageNotifications[data.default_message_notifications] ||
|
||||
data.default_message_notifications;
|
||||
this.defaultMessageNotifications =
|
||||
DefaultMessageNotifications[data.default_message_notifications] || data.default_message_notifications;
|
||||
|
||||
/**
|
||||
* The value set for the guild's system channel flags
|
||||
@@ -483,9 +481,12 @@ class Guild extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get owner() {
|
||||
return this.members.cache.get(this.ownerID) || (this.client.options.partials.includes(PartialTypes.GUILD_MEMBER) ?
|
||||
this.members.add({ user: { id: this.ownerID } }, true) :
|
||||
null);
|
||||
return (
|
||||
this.members.cache.get(this.ownerID) ||
|
||||
(this.client.options.partials.includes(PartialTypes.GUILD_MEMBER)
|
||||
? this.members.add({ user: { id: this.ownerID } }, true)
|
||||
: null)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -550,10 +551,12 @@ class Guild extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get me() {
|
||||
return this.members.cache.get(this.client.user.id) ||
|
||||
(this.client.options.partials.includes(PartialTypes.GUILD_MEMBER) ?
|
||||
this.members.add({ user: { id: this.client.user.id } }, true) :
|
||||
null);
|
||||
return (
|
||||
this.members.cache.get(this.client.user.id) ||
|
||||
(this.client.options.partials.includes(PartialTypes.GUILD_MEMBER)
|
||||
? this.members.add({ user: { id: this.client.user.id } }, true)
|
||||
: null)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -582,10 +585,13 @@ class Guild extends Base {
|
||||
* @returns {Promise<Guild>}
|
||||
*/
|
||||
fetch() {
|
||||
return this.client.api.guilds(this.id).get().then(data => {
|
||||
this._patch(data);
|
||||
return this;
|
||||
});
|
||||
return this.client.api
|
||||
.guilds(this.id)
|
||||
.get()
|
||||
.then(data => {
|
||||
this._patch(data);
|
||||
return this;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -596,14 +602,17 @@ class Guild extends Base {
|
||||
*/
|
||||
|
||||
/**
|
||||
* Fetches information on a banned user from this guild.
|
||||
* Fetches information on a banned user from this guild.
|
||||
* @param {UserResolvable} user The User to fetch the ban info of
|
||||
* @returns {Promise<BanInfo>}
|
||||
*/
|
||||
fetchBan(user) {
|
||||
const id = this.client.users.resolveID(user);
|
||||
if (!id) throw new Error('FETCH_BAN_RESOLVE_ID');
|
||||
return this.client.api.guilds(this.id).bans(id).get()
|
||||
return this.client.api
|
||||
.guilds(this.id)
|
||||
.bans(id)
|
||||
.get()
|
||||
.then(ban => ({
|
||||
reason: ban.reason,
|
||||
user: this.client.users.add(ban.user),
|
||||
@@ -615,15 +624,18 @@ class Guild extends Base {
|
||||
* @returns {Promise<Collection<Snowflake, BanInfo>>}
|
||||
*/
|
||||
fetchBans() {
|
||||
return this.client.api.guilds(this.id).bans.get().then(bans =>
|
||||
bans.reduce((collection, ban) => {
|
||||
collection.set(ban.user.id, {
|
||||
reason: ban.reason,
|
||||
user: this.client.users.add(ban.user),
|
||||
});
|
||||
return collection;
|
||||
}, new Collection()),
|
||||
);
|
||||
return this.client.api
|
||||
.guilds(this.id)
|
||||
.bans.get()
|
||||
.then(bans =>
|
||||
bans.reduce((collection, ban) => {
|
||||
collection.set(ban.user.id, {
|
||||
reason: ban.reason,
|
||||
user: this.client.users.add(ban.user),
|
||||
});
|
||||
return collection;
|
||||
}, new Collection()),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -637,11 +649,15 @@ class Guild extends Base {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
fetchIntegrations() {
|
||||
return this.client.api.guilds(this.id).integrations.get().then(data =>
|
||||
data.reduce((collection, integration) =>
|
||||
collection.set(integration.id, new Integration(this.client, integration, this)),
|
||||
new Collection()),
|
||||
);
|
||||
return this.client.api
|
||||
.guilds(this.id)
|
||||
.integrations.get()
|
||||
.then(data =>
|
||||
data.reduce(
|
||||
(collection, integration) => collection.set(integration.id, new Integration(this.client, integration, this)),
|
||||
new Collection(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -658,7 +674,9 @@ class Guild extends Base {
|
||||
* @returns {Promise<Guild>}
|
||||
*/
|
||||
createIntegration(data, reason) {
|
||||
return this.client.api.guilds(this.id).integrations.post({ data, reason })
|
||||
return this.client.api
|
||||
.guilds(this.id)
|
||||
.integrations.post({ data, reason })
|
||||
.then(() => this);
|
||||
}
|
||||
|
||||
@@ -678,7 +696,9 @@ class Guild extends Base {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
fetchInvites() {
|
||||
return this.client.api.guilds(this.id).invites.get()
|
||||
return this.client.api
|
||||
.guilds(this.id)
|
||||
.invites.get()
|
||||
.then(inviteItems => {
|
||||
const invites = new Collection();
|
||||
for (const inviteItem of inviteItems) {
|
||||
@@ -705,7 +725,9 @@ class Guild extends Base {
|
||||
if (!this.features.includes('VANITY_URL')) {
|
||||
return Promise.reject(new Error('VANITY_URL'));
|
||||
}
|
||||
return this.client.api.guilds(this.id, 'vanity-url').get()
|
||||
return this.client.api
|
||||
.guilds(this.id, 'vanity-url')
|
||||
.get()
|
||||
.then(res => res.code);
|
||||
}
|
||||
|
||||
@@ -719,11 +741,14 @@ class Guild extends Base {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
fetchWebhooks() {
|
||||
return this.client.api.guilds(this.id).webhooks.get().then(data => {
|
||||
const hooks = new Collection();
|
||||
for (const hook of data) hooks.set(hook.id, new Webhook(this.client, hook));
|
||||
return hooks;
|
||||
});
|
||||
return this.client.api
|
||||
.guilds(this.id)
|
||||
.webhooks.get()
|
||||
.then(data => {
|
||||
const hooks = new Collection();
|
||||
for (const hook of data) hooks.set(hook.id, new Webhook(this.client, hook));
|
||||
return hooks;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -731,11 +756,14 @@ class Guild extends Base {
|
||||
* @returns {Promise<Collection<string, VoiceRegion>>}
|
||||
*/
|
||||
fetchVoiceRegions() {
|
||||
return this.client.api.guilds(this.id).regions.get().then(res => {
|
||||
const regions = new Collection();
|
||||
for (const region of res) regions.set(region.id, new VoiceRegion(region));
|
||||
return regions;
|
||||
});
|
||||
return this.client.api
|
||||
.guilds(this.id)
|
||||
.regions.get()
|
||||
.then(res => {
|
||||
const regions = new Collection();
|
||||
for (const region of res) regions.set(region.id, new VoiceRegion(region));
|
||||
return regions;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -755,10 +783,13 @@ class Guild extends Base {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
fetchEmbed() {
|
||||
return this.client.api.guilds(this.id).embed.get().then(data => ({
|
||||
enabled: data.enabled,
|
||||
channel: data.channel_id ? this.channels.cache.get(data.channel_id) : null,
|
||||
}));
|
||||
return this.client.api
|
||||
.guilds(this.id)
|
||||
.embed.get()
|
||||
.then(data => ({
|
||||
enabled: data.enabled,
|
||||
channel: data.channel_id ? this.channels.cache.get(data.channel_id) : null,
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -779,12 +810,16 @@ class Guild extends Base {
|
||||
if (options.before && options.before instanceof GuildAuditLogs.Entry) options.before = options.before.id;
|
||||
if (typeof options.type === 'string') options.type = GuildAuditLogs.Actions[options.type];
|
||||
|
||||
return this.client.api.guilds(this.id)['audit-logs'].get({ query: {
|
||||
before: options.before,
|
||||
limit: options.limit,
|
||||
user_id: this.client.users.resolveID(options.user),
|
||||
action_type: options.type,
|
||||
} })
|
||||
return this.client.api
|
||||
.guilds(this.id)
|
||||
['audit-logs'].get({
|
||||
query: {
|
||||
before: options.before,
|
||||
limit: options.limit,
|
||||
user_id: this.client.users.resolveID(options.user),
|
||||
action_type: options.type,
|
||||
},
|
||||
})
|
||||
.then(data => GuildAuditLogs.build(this, data));
|
||||
}
|
||||
|
||||
@@ -811,14 +846,18 @@ class Guild extends Base {
|
||||
for (let role of options.roles instanceof Collection ? options.roles.values() : options.roles) {
|
||||
role = this.roles.resolve(role);
|
||||
if (!role) {
|
||||
return Promise.reject(new TypeError('INVALID_TYPE', 'options.roles',
|
||||
'Array or Collection of Roles or Snowflakes', true));
|
||||
return Promise.reject(
|
||||
new TypeError('INVALID_TYPE', 'options.roles', 'Array or Collection of Roles or Snowflakes', true),
|
||||
);
|
||||
}
|
||||
roles.push(role.id);
|
||||
}
|
||||
options.roles = roles;
|
||||
}
|
||||
return this.client.api.guilds(this.id).members(user).put({ data: options })
|
||||
return this.client.api
|
||||
.guilds(this.id)
|
||||
.members(user)
|
||||
.put({ data: options })
|
||||
.then(data => this.members.add(data));
|
||||
}
|
||||
|
||||
@@ -859,9 +898,10 @@ class Guild extends Base {
|
||||
if (data.name) _data.name = data.name;
|
||||
if (data.region) _data.region = data.region;
|
||||
if (typeof data.verificationLevel !== 'undefined') {
|
||||
_data.verification_level = typeof data.verificationLevel === 'number' ?
|
||||
Number(data.verificationLevel) :
|
||||
ExplicitContentFilterLevels.indexOf(data.verificationLevel);
|
||||
_data.verification_level =
|
||||
typeof data.verificationLevel === 'number'
|
||||
? Number(data.verificationLevel)
|
||||
: ExplicitContentFilterLevels.indexOf(data.verificationLevel);
|
||||
}
|
||||
if (typeof data.afkChannel !== 'undefined') {
|
||||
_data.afk_channel_id = this.client.channels.resolveID(data.afkChannel);
|
||||
@@ -875,19 +915,23 @@ class Guild extends Base {
|
||||
if (data.splash) _data.splash = data.splash;
|
||||
if (data.banner) _data.banner = data.banner;
|
||||
if (typeof data.explicitContentFilter !== 'undefined') {
|
||||
_data.explicit_content_filter = typeof data.explicitContentFilter === 'number' ?
|
||||
data.explicitContentFilter :
|
||||
ExplicitContentFilterLevels.indexOf(data.explicitContentFilter);
|
||||
_data.explicit_content_filter =
|
||||
typeof data.explicitContentFilter === 'number'
|
||||
? data.explicitContentFilter
|
||||
: ExplicitContentFilterLevels.indexOf(data.explicitContentFilter);
|
||||
}
|
||||
if (typeof data.defaultMessageNotifications !== 'undefined') {
|
||||
_data.default_message_notifications = typeof data.defaultMessageNotifications === 'string' ?
|
||||
DefaultMessageNotifications.indexOf(data.defaultMessageNotifications) :
|
||||
data.defaultMessageNotifications;
|
||||
_data.default_message_notifications =
|
||||
typeof data.defaultMessageNotifications === 'string'
|
||||
? DefaultMessageNotifications.indexOf(data.defaultMessageNotifications)
|
||||
: data.defaultMessageNotifications;
|
||||
}
|
||||
if (typeof data.systemChannelFlags !== 'undefined') {
|
||||
_data.system_channel_flags = SystemChannelFlags.resolve(data.systemChannelFlags);
|
||||
}
|
||||
return this.client.api.guilds(this.id).patch({ data: _data, reason })
|
||||
return this.client.api
|
||||
.guilds(this.id)
|
||||
.patch({ data: _data, reason })
|
||||
.then(newData => this.client.actions.GuildUpdate.handle(newData).updated);
|
||||
}
|
||||
|
||||
@@ -1094,12 +1138,16 @@ class Guild extends Base {
|
||||
position: r.position,
|
||||
}));
|
||||
|
||||
return this.client.api.guilds(this.id).channels.patch({ data: updatedChannels }).then(() =>
|
||||
this.client.actions.GuildChannelsPositionUpdate.handle({
|
||||
guild_id: this.id,
|
||||
channels: updatedChannels,
|
||||
}).guild,
|
||||
);
|
||||
return this.client.api
|
||||
.guilds(this.id)
|
||||
.channels.patch({ data: updatedChannels })
|
||||
.then(
|
||||
() =>
|
||||
this.client.actions.GuildChannelsPositionUpdate.handle({
|
||||
guild_id: this.id,
|
||||
channels: updatedChannels,
|
||||
}).guild,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1126,14 +1174,18 @@ class Guild extends Base {
|
||||
}));
|
||||
|
||||
// Call the API to update role positions
|
||||
return this.client.api.guilds(this.id).roles.patch({
|
||||
data: rolePositions,
|
||||
}).then(() =>
|
||||
this.client.actions.GuildRolePositionUpdate.handle({
|
||||
guild_id: this.id,
|
||||
roles: rolePositions,
|
||||
}).guild,
|
||||
);
|
||||
return this.client.api
|
||||
.guilds(this.id)
|
||||
.roles.patch({
|
||||
data: rolePositions,
|
||||
})
|
||||
.then(
|
||||
() =>
|
||||
this.client.actions.GuildRolePositionUpdate.handle({
|
||||
guild_id: this.id,
|
||||
roles: rolePositions,
|
||||
}).guild,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1143,13 +1195,16 @@ class Guild extends Base {
|
||||
* @returns {Promise<Guild>}
|
||||
*/
|
||||
setEmbed(embed, reason) {
|
||||
return this.client.api.guilds(this.id).embed.patch({
|
||||
data: {
|
||||
enabled: embed.enabled,
|
||||
channel_id: this.channels.resolveID(embed.channel),
|
||||
},
|
||||
reason,
|
||||
}).then(() => this);
|
||||
return this.client.api
|
||||
.guilds(this.id)
|
||||
.embed.patch({
|
||||
data: {
|
||||
enabled: embed.enabled,
|
||||
channel_id: this.channels.resolveID(embed.channel),
|
||||
},
|
||||
reason,
|
||||
})
|
||||
.then(() => this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1163,7 +1218,10 @@ class Guild extends Base {
|
||||
*/
|
||||
leave() {
|
||||
if (this.ownerID === this.client.user.id) return Promise.reject(new Error('GUILD_OWNED'));
|
||||
return this.client.api.users('@me').guilds(this.id).delete()
|
||||
return this.client.api
|
||||
.users('@me')
|
||||
.guilds(this.id)
|
||||
.delete()
|
||||
.then(() => this.client.actions.GuildDelete.handle({ id: this.id }).guild);
|
||||
}
|
||||
|
||||
@@ -1177,7 +1235,9 @@ class Guild extends Base {
|
||||
* .catch(console.error);
|
||||
*/
|
||||
delete() {
|
||||
return this.client.api.guilds(this.id).delete()
|
||||
return this.client.api
|
||||
.guilds(this.id)
|
||||
.delete()
|
||||
.then(() => this.client.actions.GuildDelete.handle({ id: this.id }).guild);
|
||||
}
|
||||
|
||||
@@ -1203,10 +1263,9 @@ class Guild extends Base {
|
||||
this.ownerID === guild.ownerID &&
|
||||
this.verificationLevel === guild.verificationLevel &&
|
||||
this.embedEnabled === guild.embedEnabled &&
|
||||
(this.features === guild.features || (
|
||||
this.features.length === guild.features.length &&
|
||||
this.features.every((feat, i) => feat === guild.features[i]))
|
||||
);
|
||||
(this.features === guild.features ||
|
||||
(this.features.length === guild.features.length &&
|
||||
this.features.every((feat, i) => feat === guild.features[i])));
|
||||
|
||||
if (equal) {
|
||||
if (this.embedChannel) {
|
||||
@@ -1261,9 +1320,9 @@ class Guild extends Base {
|
||||
*/
|
||||
_sortedChannels(channel) {
|
||||
const category = channel.type === ChannelTypes.CATEGORY;
|
||||
return Util.discordSort(this.channels.cache.filter(c =>
|
||||
c.type === channel.type && (category || c.parent === channel.parent),
|
||||
));
|
||||
return Util.discordSort(
|
||||
this.channels.cache.filter(c => c.type === channel.type && (category || c.parent === channel.parent)),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user