mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 19:13:31 +01:00
Add MessageEmbed and subclasses
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -1,5 +1,6 @@
|
|||||||
const Collection = require('../util/Collection');
|
const Collection = require('../util/Collection');
|
||||||
const Attachment = require('./MessageAttachment');
|
const Attachment = require('./MessageAttachment');
|
||||||
|
const Embed = require('./MessageEmbed');
|
||||||
/**
|
/**
|
||||||
* Represents a Message on Discord
|
* Represents a Message on Discord
|
||||||
*/
|
*/
|
||||||
@@ -73,9 +74,9 @@ class Message {
|
|||||||
this.nonce = data.nonce;
|
this.nonce = data.nonce;
|
||||||
/**
|
/**
|
||||||
* A list of embeds in the message - e.g. YouTube Player
|
* A list of embeds in the message - e.g. YouTube Player
|
||||||
* @type {Array<Object>}
|
* @type {Array<Embed>}
|
||||||
*/
|
*/
|
||||||
this.embeds = data.embeds;
|
this.embeds = data.embeds.map(e => new Embed(this, e));
|
||||||
/**
|
/**
|
||||||
* A collection of attachments in the message - e.g. Pictures - mapped by their ID.
|
* A collection of attachments in the message - e.g. Pictures - mapped by their ID.
|
||||||
* @type {Collection<String, MessageAttachment>}
|
* @type {Collection<String, MessageAttachment>}
|
||||||
@@ -156,7 +157,7 @@ class Message {
|
|||||||
this.nonce = data.nonce;
|
this.nonce = data.nonce;
|
||||||
}
|
}
|
||||||
if (data.embeds) {
|
if (data.embeds) {
|
||||||
this.embeds = data.embeds;
|
this.embeds = data.embeds.map(e => new Embed(this, e));
|
||||||
}
|
}
|
||||||
if (data.attachments) {
|
if (data.attachments) {
|
||||||
this.attachments = new Collection();
|
this.attachments = new Collection();
|
||||||
|
|||||||
@@ -5,10 +5,12 @@ class MessageAttachment {
|
|||||||
constructor(message, data) {
|
constructor(message, data) {
|
||||||
/**
|
/**
|
||||||
* The Client that instantiated this Message.
|
* The Client that instantiated this Message.
|
||||||
|
* @type {Client}
|
||||||
*/
|
*/
|
||||||
this.client = message.client;
|
this.client = message.client;
|
||||||
/**
|
/**
|
||||||
* The message this attachment is part of.
|
* The message this attachment is part of.
|
||||||
|
* @type {Message}
|
||||||
*/
|
*/
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.setup(data);
|
this.setup(data);
|
||||||
|
|||||||
121
src/structures/MessageEmbed.js
Normal file
121
src/structures/MessageEmbed.js
Normal file
@@ -0,0 +1,121 @@
|
|||||||
|
/**
|
||||||
|
* Represents a thumbnail for a Message embed
|
||||||
|
*/
|
||||||
|
class MessageEmbedThumbnail {
|
||||||
|
constructor(embed, data) {
|
||||||
|
/**
|
||||||
|
* The embed this thumbnail is part of
|
||||||
|
* @type {MessageEmbed}
|
||||||
|
*/
|
||||||
|
this.embed = embed;
|
||||||
|
this.setup(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
setup(data) {
|
||||||
|
/**
|
||||||
|
* The URL for this thumbnail
|
||||||
|
* @type {String}
|
||||||
|
*/
|
||||||
|
this.url = data.url;
|
||||||
|
/**
|
||||||
|
* The Proxy URL for this thumbnail
|
||||||
|
* @type {String}
|
||||||
|
*/
|
||||||
|
this.proxyURL = data.proxy_url;
|
||||||
|
/**
|
||||||
|
* The height of the thumbnail
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
this.height = data.height;
|
||||||
|
/**
|
||||||
|
* The width of the thumbnail
|
||||||
|
* @type {Number}
|
||||||
|
*/
|
||||||
|
this.width = data.width;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a Provider for a Message embed
|
||||||
|
*/
|
||||||
|
class MessageEmbedProvider {
|
||||||
|
constructor(embed, data) {
|
||||||
|
/**
|
||||||
|
* The embed this provider is part of
|
||||||
|
* @type {MessageEmbed}
|
||||||
|
*/
|
||||||
|
this.embed = embed;
|
||||||
|
this.setup(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
setup(data) {
|
||||||
|
/**
|
||||||
|
* The name of this provider
|
||||||
|
* @type {String}
|
||||||
|
*/
|
||||||
|
this.name = data.name;
|
||||||
|
/**
|
||||||
|
* The URL of this provider
|
||||||
|
* @type {String}
|
||||||
|
*/
|
||||||
|
this.url = data.url;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents an embed in an image - e.g. preview of image
|
||||||
|
*/
|
||||||
|
class MessageEmbed {
|
||||||
|
constructor(message, data) {
|
||||||
|
/**
|
||||||
|
* The message this embed is part of
|
||||||
|
* @type {Message}
|
||||||
|
*/
|
||||||
|
this.message = message;
|
||||||
|
/**
|
||||||
|
* The client that instantiated this embed
|
||||||
|
* @type {Client}
|
||||||
|
*/
|
||||||
|
this.client = message.client;
|
||||||
|
this.setup(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
setup(data) {
|
||||||
|
/**
|
||||||
|
* The title of this embed, if there is one
|
||||||
|
* @type {?String}
|
||||||
|
*/
|
||||||
|
this.title = data.title;
|
||||||
|
/**
|
||||||
|
* The type of this embed
|
||||||
|
* @type {String}
|
||||||
|
*/
|
||||||
|
this.type = data.type;
|
||||||
|
/**
|
||||||
|
* The description of this embed, if there is one
|
||||||
|
* @type {?String}
|
||||||
|
*/
|
||||||
|
this.description = data.description;
|
||||||
|
/**
|
||||||
|
* The URL of this embed
|
||||||
|
* @type {String}
|
||||||
|
*/
|
||||||
|
this.url = data.url;
|
||||||
|
if (data.thumbnail) {
|
||||||
|
/**
|
||||||
|
* The thumbnail of this embed, if there is one
|
||||||
|
* @type {MessageEmbedThumbnail}
|
||||||
|
*/
|
||||||
|
this.thumbnail = new MessageEmbedThumbnail(this, data.thumbnail);
|
||||||
|
}
|
||||||
|
if (data.provider) {
|
||||||
|
/**
|
||||||
|
* The provider of this embed, if there is one
|
||||||
|
* @type {MessageEmbedProvider}
|
||||||
|
*/
|
||||||
|
this.provider = new MessageEmbedProvider(this, data.provider);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = MessageEmbed;
|
||||||
Reference in New Issue
Block a user