Add embeds

This commit is contained in:
Samuel Elliott 2018-04-14 18:43:18 +01:00
parent 695d088f60
commit 6d64d17b7d
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6
1 changed files with 44 additions and 1 deletions

View File

@ -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));
}