From 6d64d17b7dc4353d1efc2b498b4691ce92b86a03 Mon Sep 17 00:00:00 2001 From: Samuel Elliott Date: Sat, 14 Apr 2018 18:43:18 +0100 Subject: [PATCH] Add embeds --- client/src/structs/discord/message.js | 45 ++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/client/src/structs/discord/message.js b/client/src/structs/discord/message.js index 68462092..5edc720b 100644 --- a/client/src/structs/discord/message.js +++ b/client/src/structs/discord/message.js @@ -47,6 +47,45 @@ export class Reaction { } } +const embeds = new WeakMap(); + +export class Embed { + constructor(data, message_id, channel_id) { + if (embeds.has(data)) return embeds.get(data); + embeds.set(data, this); + + this.discordObject = data; + this.message_id = message_id; + this.channel_id = channel_id; + } + + get title() { return this.discordObject.title } + get type() { return this.discordObject.type } + get description() { return this.discordObject.description } + get url() { return this.discordObject.url } + get timestamp() { return this.discordObject.timestamp } + get colour() { return this.discordObject.color } + get footer() { return this.discordObject.footer } + get image() { return this.discordObject.image } + get thumbnail() { return this.discordObject.thumbnail } + get video() { return this.discordObject.video } + get provider() { return this.discordObject.provider } + get author() { return this.discordObject.author } + get fields() { return this.discordObject.fields } + + get channel() { + return Channel.fromId(this.channel_id); + } + + get message() { + if (this.channel) return this.channel.messages.find(m => m.id === this.message_id); + } + + get guild() { + if (this.channel) return this.channel.guild; + } +} + const messages = new WeakMap(); export class Message { @@ -59,6 +98,7 @@ export class Message { } static get Reaction() { return Reaction } + static get Embed() { return Embed } get id() { return this.discordObject.id } get channel_id() { return this.discordObject.channel_id } @@ -68,7 +108,6 @@ export class Message { get content() { return this.discordObject.content } get content_parsed() { return this.discordObject.contentParsed } get invite_codes() { return this.discordObject.invites } - get embeds() { return this.discordObject.embeds } get attachments() { return this.discordObject.attachments } get mentions() { return this.discordObject.mentions } get mention_roles() { return this.discordObject.mentionRoles } @@ -100,6 +139,10 @@ export class Message { if (this.channel) return this.channel.guild; } + get embeds() { + return List.from(this.discordObject.embeds, r => new Embed(r, this.id, this.channel_id)); + } + get reactions() { return List.from(this.discordObject.reactions, r => new Reaction(r, this.id, this.channel_id)); }