mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 11:03:30 +01:00
Merged master into indev-prism
This commit is contained in:
@@ -315,6 +315,14 @@ class Client extends EventEmitter {
|
|||||||
return this.rest.methods.getWebhook(id, token);
|
return this.rest.methods.getWebhook(id, token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch available voice regions
|
||||||
|
* @returns {Collection<string, VoiceRegion>}
|
||||||
|
*/
|
||||||
|
fetchVoiceRegions() {
|
||||||
|
return this.rest.methods.fetchVoiceRegions();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ const UserProfile = require('../../structures/UserProfile');
|
|||||||
const ClientOAuth2Application = require('../../structures/ClientOAuth2Application');
|
const ClientOAuth2Application = require('../../structures/ClientOAuth2Application');
|
||||||
const Channel = require('../../structures/Channel');
|
const Channel = require('../../structures/Channel');
|
||||||
const Guild = require('../../structures/Guild');
|
const Guild = require('../../structures/Guild');
|
||||||
|
const VoiceRegion = require('../../structures/VoiceRegion');
|
||||||
|
|
||||||
class RESTMethods {
|
class RESTMethods {
|
||||||
constructor(restManager) {
|
constructor(restManager) {
|
||||||
@@ -47,6 +48,15 @@ class RESTMethods {
|
|||||||
return this.rest.makeRequest('get', Constants.Endpoints.botGateway, true);
|
return this.rest.makeRequest('get', Constants.Endpoints.botGateway, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fetchVoiceRegions(guildID) {
|
||||||
|
const endpoint = Constants.Endpoints[guildID ? 'guildVoiceRegions' : 'voiceRegions'];
|
||||||
|
return this.rest.makeRequest('get', guildID ? endpoint(guildID) : endpoint, true).then(res => {
|
||||||
|
const regions = new Collection();
|
||||||
|
for (const region of res) regions.set(region.id, new VoiceRegion(region));
|
||||||
|
return regions;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
sendMessage(channel, content, { tts, nonce, embed, disableEveryone, split, code, reply } = {}, file = null) {
|
sendMessage(channel, content, { tts, nonce, embed, disableEveryone, split, code, reply } = {}, file = null) {
|
||||||
return new Promise((resolve, reject) => { // eslint-disable-line complexity
|
return new Promise((resolve, reject) => { // eslint-disable-line complexity
|
||||||
if (typeof content !== 'undefined') content = this.client.resolver.resolveString(content);
|
if (typeof content !== 'undefined') content = this.client.resolver.resolveString(content);
|
||||||
|
|||||||
@@ -322,6 +322,14 @@ class Guild {
|
|||||||
return this.client.rest.methods.getGuildWebhooks(this);
|
return this.client.rest.methods.getGuildWebhooks(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch available voice regions
|
||||||
|
* @returns {Collection<string, VoiceRegion>}
|
||||||
|
*/
|
||||||
|
fetchVoiceRegions() {
|
||||||
|
return this.client.rest.methods.fetchVoiceRegions(this.id);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch a single guild member from a user.
|
* Fetch a single guild member from a user.
|
||||||
* @param {UserResolvable} user The user to fetch the member for
|
* @param {UserResolvable} user The user to fetch the member for
|
||||||
|
|||||||
@@ -540,7 +540,7 @@ class Message {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_addReaction(emoji, user) {
|
_addReaction(emoji, user) {
|
||||||
const emojiID = emoji.identifier;
|
const emojiID = emoji.id ? `${emoji.name}:${emoji.id}` : encodeURIComponent(emoji.name);
|
||||||
let reaction;
|
let reaction;
|
||||||
if (this.reactions.has(emojiID)) {
|
if (this.reactions.has(emojiID)) {
|
||||||
reaction = this.reactions.get(emojiID);
|
reaction = this.reactions.get(emojiID);
|
||||||
@@ -549,16 +549,13 @@ class Message {
|
|||||||
reaction = new MessageReaction(this, emoji, 0, user.id === this.client.user.id);
|
reaction = new MessageReaction(this, emoji, 0, user.id === this.client.user.id);
|
||||||
this.reactions.set(emojiID, reaction);
|
this.reactions.set(emojiID, reaction);
|
||||||
}
|
}
|
||||||
if (!reaction.users.has(user.id)) {
|
if (!reaction.users.has(user.id)) reaction.users.set(user.id, user);
|
||||||
reaction.users.set(user.id, user);
|
reaction.count++;
|
||||||
reaction.count++;
|
return reaction;
|
||||||
return reaction;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_removeReaction(emoji, user) {
|
_removeReaction(emoji, user) {
|
||||||
const emojiID = emoji.identifier;
|
const emojiID = emoji.id ? `${emoji.name}:${emoji.id}` : encodeURIComponent(emoji.name);
|
||||||
if (this.reactions.has(emojiID)) {
|
if (this.reactions.has(emojiID)) {
|
||||||
const reaction = this.reactions.get(emojiID);
|
const reaction = this.reactions.get(emojiID);
|
||||||
if (reaction.users.has(user.id)) {
|
if (reaction.users.has(user.id)) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
* Represents an embed in a message (image/video preview, rich embed, etc.)
|
* Represents an embed in a message (image/video preview, rich embed, etc.)
|
||||||
|
* <info>This class is only used for *recieved* embeds. If you wish to send one, use the {@link RichEmbed} class.</info>
|
||||||
*/
|
*/
|
||||||
class MessageEmbed {
|
class MessageEmbed {
|
||||||
constructor(message, data) {
|
constructor(message, data) {
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ class VoiceChannel extends GuildChannel {
|
|||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
*/
|
*/
|
||||||
get full() {
|
get full() {
|
||||||
return this.members.size >= this.userLimit;
|
return this.userLimit > 0 && this.members.size >= this.userLimit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
50
src/structures/VoiceRegion.js
Normal file
50
src/structures/VoiceRegion.js
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
/**
|
||||||
|
* Represents a Discord voice region for guilds
|
||||||
|
*/
|
||||||
|
class VoiceRegion {
|
||||||
|
constructor(data) {
|
||||||
|
/**
|
||||||
|
* ID of the region
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
this.id = data.id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Name of the region
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
this.name = data.name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the region is VIP-only
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.vip = data.vip;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the region is deprecated
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.deprecated = data.deprecated;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the region is optimal
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.optimal = data.optimal;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the region is custom
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.custom = data.custom;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A sample hostname for what a connection might look like
|
||||||
|
* @type {string}
|
||||||
|
*/
|
||||||
|
this.sampleHostname = data.sample_hostname;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = VoiceRegion;
|
||||||
@@ -105,6 +105,8 @@ const Endpoints = exports.Endpoints = {
|
|||||||
relationships: (userID) => `${Endpoints.user(userID)}/relationships`,
|
relationships: (userID) => `${Endpoints.user(userID)}/relationships`,
|
||||||
note: (userID) => `${Endpoints.me}/notes/${userID}`,
|
note: (userID) => `${Endpoints.me}/notes/${userID}`,
|
||||||
|
|
||||||
|
voiceRegions: `${API}/voice/regions`,
|
||||||
|
|
||||||
// guilds
|
// guilds
|
||||||
guilds: `${API}/guilds`,
|
guilds: `${API}/guilds`,
|
||||||
guild: (guildID) => `${Endpoints.guilds}/${guildID}`,
|
guild: (guildID) => `${Endpoints.guilds}/${guildID}`,
|
||||||
@@ -124,6 +126,7 @@ const Endpoints = exports.Endpoints = {
|
|||||||
guildChannels: (guildID) => `${Endpoints.guild(guildID)}/channels`,
|
guildChannels: (guildID) => `${Endpoints.guild(guildID)}/channels`,
|
||||||
guildEmojis: (guildID) => `${Endpoints.guild(guildID)}/emojis`,
|
guildEmojis: (guildID) => `${Endpoints.guild(guildID)}/emojis`,
|
||||||
guildSearch: (guildID) => `${Endpoints.guild(guildID)}/messages/search`,
|
guildSearch: (guildID) => `${Endpoints.guild(guildID)}/messages/search`,
|
||||||
|
guildVoiceRegions: (guildID) => `${Endpoints.guild(guildID)}/regions`,
|
||||||
|
|
||||||
// channels
|
// channels
|
||||||
channels: `${API}/channels`,
|
channels: `${API}/channels`,
|
||||||
|
|||||||
Reference in New Issue
Block a user