From 7b876cf5d5c9aedd9e711d020f2afa20ae34ecab Mon Sep 17 00:00:00 2001 From: TTtie Date: Sat, 26 Aug 2023 13:07:30 +0000 Subject: [PATCH] feat: super reactions Ref: https://github.com/discord/discord-api-docs/commit/b1bed4665ab0855cd3265fa3617a05bf7a51b353 Ref: https://github.com/discord/discord-api-docs/pull/6375 --- index.d.ts | 6 +++--- lib/gateway/Shard.js | 29 ++++++++++++++++++++++++----- lib/structures/Message.js | 7 +++++-- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/index.d.ts b/index.d.ts index b539178a..3efebb0b 100644 --- a/index.d.ts +++ b/index.d.ts @@ -764,8 +764,8 @@ declare namespace Dysnomia { messageCreate: [message: Message]; messageDelete: [message: PossiblyUncachedMessage]; messageDeleteBulk: [messages: PossiblyUncachedMessage[]]; - messageReactionAdd: [message: PossiblyUncachedMessage, emoji: PartialEmoji, reactor: Member | Uncached]; - messageReactionRemove: [message: PossiblyUncachedMessage, emoji: PartialEmoji, userID: string]; + messageReactionAdd: [message: PossiblyUncachedMessage, emoji: PartialEmoji, reactor: Member | Uncached, isBurst: boolean]; + messageReactionRemove: [message: PossiblyUncachedMessage, emoji: PartialEmoji, userID: string, isBurst: boolean]; messageReactionRemoveAll: [message: PossiblyUncachedMessage]; messageReactionRemoveEmoji: [message: PossiblyUncachedMessage, emoji: PartialEmoji]; messageUpdate: [message: Message, oldMessage: OldMessage | null]; @@ -3315,7 +3315,7 @@ declare namespace Dysnomia { messageReference: MessageReference | null; pinned: boolean; position?: number; - reactions: { [s: string]: { count: number; me: boolean } }; + reactions: { [s: string]: { burstColors: string[]; count: number; countDetails: { burst: number; normal: number }; me: boolean; meBurst: boolean; } }; referencedMessage?: Message | null; roleMentions: string[]; roleSubscriptionData?: RoleSubscriptionData; diff --git a/lib/gateway/Shard.js b/lib/gateway/Shard.js index 7468a79a..a9cff500 100644 --- a/lib/gateway/Shard.js +++ b/lib/gateway/Shard.js @@ -979,13 +979,25 @@ class Shard extends EventEmitter { const reaction = packet.d.emoji.id ? `${packet.d.emoji.name}:${packet.d.emoji.id}` : packet.d.emoji.name; if(message.reactions[reaction]) { ++message.reactions[reaction].count; + ++message.reactions[reaction].countDetails[packet.d.burst ? "burst" : "normal"]; if(packet.d.user_id === this.client.user.id) { - message.reactions[reaction].me = true; + if(packet.d.burst) { + message.reactions[reaction].meBurst = true; + } else { + message.reactions[reaction].me = true; + } } + message.reactions[reaction].burstColors = packet.d.burst_colors; } else { message.reactions[reaction] = { + burstColors: packet.d.burst_colors, count: 1, - me: packet.d.user_id === this.client.user.id + countDetails: { + burst: +packet.d.burst, + normal: +!packet.d.burst + }, + me: packet.d.user_id === this.client.user.id && !packet.d.burst, + meBurst: packet.d.user_id === this.client.user.id && packet.d.burst }; } } else { @@ -1012,8 +1024,9 @@ class Shard extends EventEmitter { * @prop {String?} emoji.id The emoji ID (null for non-custom emojis) * @prop {String} emoji.name The emoji name * @prop {Member | Object} reactor The member, if the reaction is in a guild. If the reaction is not in a guild, this will be an object with an `id` key. No other property is guaranteed + * @prop {Boolean} isBurst Whether the reaction is a super-reaction or not */ - this.emit("messageReactionAdd", message, packet.d.emoji, member || {id: packet.d.user_id}); + this.emit("messageReactionAdd", message, packet.d.emoji, member || {id: packet.d.user_id}, !!packet.d.burst); break; } case "MESSAGE_REACTION_REMOVE": { @@ -1024,10 +1037,15 @@ class Shard extends EventEmitter { const reactionObj = message.reactions[reaction]; if(reactionObj) { --reactionObj.count; + --reactionObj.countDetails[packet.d.burst ? "burst" : "normal"]; if(reactionObj.count === 0) { delete message.reactions[reaction]; } else if(packet.d.user_id === this.client.user.id) { - reactionObj.me = false; + if(packet.d.burst) { + reactionObj.meBurst = false; + } else { + reactionObj.me = false; + } } } } else { @@ -1050,8 +1068,9 @@ class Shard extends EventEmitter { * @prop {String?} emoji.id The ID of the emoji (null for non-custom emojis) * @prop {String} emoji.name The emoji name * @prop {String} userID The ID of the user that removed the reaction + * @prop {Boolean} isBurst Whether the removed reaction is a super-reaction or not */ - this.emit("messageReactionRemove", message, packet.d.emoji, packet.d.user_id); + this.emit("messageReactionRemove", message, packet.d.emoji, packet.d.user_id, !!packet.d.burst); break; } case "MESSAGE_REACTION_REMOVE_ALL": { diff --git a/lib/structures/Message.js b/lib/structures/Message.js index 2d617cea..93b9d4d2 100644 --- a/lib/structures/Message.js +++ b/lib/structures/Message.js @@ -53,7 +53,7 @@ class Message extends Base { */ this.content = ""; /** - * An object containing the reactions on the message. Each key is a reaction emoji and each value is an object with properties `me` (Boolean) and `count` (Number) for that specific reaction emoji. + * An object containing the reactions on the message. Each key is a reaction emoji and each value is an object with properties `me` (Boolean), `meBurst` (Boolean), `count` (Number), `countDetails` (an object with `burst` and `normal` keys corresponding to the amount of reactions of the respective type), and `burstColors` (Array) for that specific reaction emoji. * @type {Object} */ this.reactions = {}; @@ -401,8 +401,11 @@ class Message extends Base { if(data.reactions) { data.reactions.forEach((reaction) => { this.reactions[reaction.emoji.id ? `${reaction.emoji.name}:${reaction.emoji.id}` : reaction.emoji.name] = { + burstColors: reaction.burst_colors, count: reaction.count, - me: reaction.me + countDetails: reaction.count_details, + me: reaction.me, + meBurst: reaction.me_burst }; }); }