UNPKG

detritus-client

Version:

A Typescript NodeJS library to interact with Discord's API, both Rest and Gateway.

91 lines (90 loc) 3.16 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Reaction = void 0; const baseset_1 = require("../collections/baseset"); const constants_1 = require("../constants"); const basestructure_1 = require("./basestructure"); const emoji_1 = require("./emoji"); const keysReaction = new baseset_1.BaseSet([ constants_1.DiscordKeys.CHANNEL_ID, constants_1.DiscordKeys.COUNT, constants_1.DiscordKeys.EMOJI, constants_1.DiscordKeys.GUILD_ID, constants_1.DiscordKeys.IS_PARTIAL, constants_1.DiscordKeys.MESSAGE_ID, constants_1.DiscordKeys.ME, ]); const keysMergeReaction = new baseset_1.BaseSet([ constants_1.DiscordKeys.GUILD_ID, ]); /** * Reaction Structure, used in [Message] * we don't store the userIds since we only get them on reaction adds * @category Structure */ class Reaction extends basestructure_1.BaseStructure { constructor(client, data, isClone) { super(client, undefined, isClone); this._keys = keysReaction; this._keysMerge = keysMergeReaction; this.channelId = ''; this.count = 0; this.isPartial = false; this.messageId = ''; this.me = false; this.merge(data); } get canClear() { const channel = this.channel; return !!(channel && channel.canManageMessages); } get channel() { return this.client.channels.get(this.channelId) || null; } get guild() { if (this.guildId) { return this.client.guilds.get(this.guildId) || null; } return null; } get message() { return this.client.messages.get(this.messageId) || null; } add() { return this.client.rest.createReaction(this.channelId, this.messageId, this.emoji.endpointFormat); } clear() { return this.client.rest.deleteReactions(this.channelId, this.messageId); } delete(userId = '@me') { return this.client.rest.deleteReaction(this.channelId, this.messageId, this.emoji.endpointFormat, userId); } deleteAll() { return this.client.rest.deleteReactionsEmoji(this.channelId, this.messageId, this.emoji.endpointFormat); } fetchUsers(options = {}) { return this.client.rest.fetchReactions(this.channelId, this.messageId, this.emoji.endpointFormat, options); } mergeValue(key, value) { if (value !== undefined) { switch (key) { case constants_1.DiscordKeys.EMOJI: { const emojiId = value.id || value.name; let emoji; if (this.client.emojis.has(this.guildId || null, emojiId)) { emoji = this.client.emojis.get(this.guildId || null, emojiId); } else { emoji = new emoji_1.Emoji(this.client, value); } value = emoji; } ; break; } return super.mergeValue(key, value); } } } exports.Reaction = Reaction;