Skip to content

Commit

Permalink
feat: super reactions
Browse files Browse the repository at this point in the history
  • Loading branch information
TTtie committed Oct 10, 2023
1 parent 5588a27 commit 7b876cf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
6 changes: 3 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -764,8 +764,8 @@ declare namespace Dysnomia {
messageCreate: [message: Message<PossiblyUncachedTextableChannel>];
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<PossiblyUncachedTextableChannel>, oldMessage: OldMessage | null];
Expand Down Expand Up @@ -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;
Expand Down
29 changes: 24 additions & 5 deletions lib/gateway/Shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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": {
Expand All @@ -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 {
Expand All @@ -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": {
Expand Down
7 changes: 5 additions & 2 deletions lib/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>) for that specific reaction emoji.
* @type {Object<string, object>}
*/
this.reactions = {};
Expand Down Expand Up @@ -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
};
});
}
Expand Down

0 comments on commit 7b876cf

Please sign in to comment.