Add reactions

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

View File

@ -9,9 +9,44 @@
*/
import { DiscordApi, DiscordApiModules as Modules } from 'modules';
import { List } from 'structs';
import { Channel } from './channel';
import { User } from './user';
const reactions = new WeakMap();
export class Reaction {
constructor(data, message_id, channel_id) {
if (reactions.has(data)) return reactions.get(data);
reactions.set(data, this);
this.discordObject = data;
this.message_id = message_id;
this.channel_id = channel_id;
}
get emoji() {
const id = this.discordObject.emoji.id;
if (!id || !this.guild) return this.discordObject.emoji;
return this.guild.emojis.find(e => e.id === id);
}
get count() { return this.discordObject.count }
get me() { return this.discordObject.me }
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 {
@ -23,6 +58,8 @@ export class Message {
this.discordObject = data;
}
static get Reaction() { return Reaction }
get id() { return this.discordObject.id }
get channel_id() { return this.discordObject.channel_id }
get webhook_id() { return this.discordObject.webhookId }
@ -36,7 +73,6 @@ export class Message {
get mentions() { return this.discordObject.mentions }
get mention_roles() { return this.discordObject.mentionRoles }
get mention_everyone() { return this.discordObject.mentionEveryone }
get reactions() { return this.discordObject.reactions }
get timestamp() { return this.discordObject.timestamp }
get edited_timestamp() { return this.discordObject.editedTimestamp }
get state() { return this.discordObject.state }
@ -64,6 +100,10 @@ export class Message {
if (this.channel) return this.channel.guild;
}
get reactions() {
return List.from(this.discordObject.reactions, r => new Reaction(r, this.id, this.channel_id));
}
get edited() {
return !!this.edited_timestamp;
}