Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Reactions): Support super reactions #1470

Merged
merged 23 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
907ce5d
Add to Message#reactions
conorwastakenwastaken Jan 14, 2024
f1680d8
Docs
conorwastakenwastaken Jan 14, 2024
5c15856
Handle super reactions on events
conorwastakenwastaken Jan 14, 2024
b5271bc
Sent burst value with event
conorwastakenwastaken Jan 14, 2024
bde7c92
Merge remote-tracking branch 'upstream/dev' into super-reactions
conorwastakenwastaken Jan 17, 2024
00db2bf
Fix
conorwastakenwastaken Jan 21, 2024
1fdd394
Merge remote-tracking branch 'upstream/dev' into super-reactions
conorwastakenwastaken Jan 21, 2024
ab9c5ae
Fix jsdocs
conorwastakenwastaken Jan 21, 2024
190b9c9
Merge branch 'dev' into super-reactions
conorwastakenwastaken Jan 22, 2024
26df5ae
Unnecessary
conorwastakenwastaken Feb 6, 2024
105b58e
Merge branch 'dev' into super-reactions
conorwastakenwastaken Feb 6, 2024
3af3071
Merge remote-tracking branch 'upstream/dev' into super-reactions
conorwastakenwastaken Apr 20, 2024
2f42830
Document `getMessageReaction#type` option
conorwastakenwastaken Apr 20, 2024
79754c7
Document reaction types
conorwastakenwastaken Apr 20, 2024
5049e3d
Merge branch 'dev' into super-reactions
conorwastakenwastaken Apr 20, 2024
a459fe9
Backwards compatibility
conorwastakenwastaken Jun 7, 2024
4a03503
Add reaction type
conorwastakenwastaken Jun 7, 2024
4b07df8
Use ReactionTypes
conorwastakenwastaken Jun 9, 2024
fcd1705
Merge remote-tracking branch 'upstream/dev' into super-reactions
conorwastakenwastaken Jun 9, 2024
c852036
Merge branch 'dev' into super-reactions
bsian03 Jun 18, 2024
b635841
Merge branch 'dev' into super-reactions
bsian03 Jul 8, 2024
158787a
Interface reactions
bsian03 Jul 11, 2024
8ddc2d5
Merge branch 'dev' of https://github.com/abalabahaha/eris into 1470
bsian03 Jul 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -863,8 +863,8 @@ declare namespace Eris {
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, burst: boolean];
messageReactionRemove: [message: PossiblyUncachedMessage, emoji: PartialEmoji, userID: string, burst: boolean];
messageReactionRemoveAll: [message: PossiblyUncachedMessage];
messageReactionRemoveEmoji: [message: PossiblyUncachedMessage, emoji: PartialEmoji];
messageUpdate: [message: Message<PossiblyUncachedTextableChannel>, oldMessage: OldMessage | null];
Expand Down Expand Up @@ -3546,7 +3546,7 @@ declare namespace Eris {
messageReference: MessageReference | null;
pinned: boolean;
prefix?: string;
reactions: { [s: string]: { count: number; me: boolean } };
reactions: { [s: string]: { burst_colors: string[], count: number, count_details: { burst: number, normal: number }, me: boolean, me_burst: boolean } };
referencedMessage?: Message | null;
roleMentions: string[];
stickerItems?: StickerItems[];
Expand Down
29 changes: 24 additions & 5 deletions lib/gateway/Shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -1108,13 +1108,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].count_details[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].me_burst = true;
} else {
message.reactions[reaction].me = true;
conorwastakenwastaken marked this conversation as resolved.
Show resolved Hide resolved
}
}
message.reactions[reaction].burst_colors = packet.d.burst_colors;
} else {
message.reactions[reaction] = {
burst_colors: packet.d.burst_colors,
count: 1,
me: packet.d.user_id === this.client.user.id
count_details: {
burst: +packet.d.burst,
normal: +!packet.d.burst
},
me: packet.d.user_id === this.client.user.id && !packet.d.burst,
me_burst: packet.d.user_id === this.client.user.id && packet.d.burst
};
}
} else {
Expand All @@ -1139,8 +1151,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} burst Whether the reaction is a super reaction
*/
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 @@ -1154,10 +1167,15 @@ class Shard extends EventEmitter {
const reactionObj = message.reactions[reaction];
if(reactionObj) {
--reactionObj.count;
--reactionObj.count_details[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) {
message.reactions[reaction].me_burst = false;
} else {
message.reactions[reaction].me = false;
}
}
}
} else {
Expand All @@ -1182,8 +1200,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} burst Whether the reaction is a super reaction
*/
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
9 changes: 6 additions & 3 deletions lib/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const User = require("./User");
* @prop {String?} applicationID The ID of the interaction's application
* @prop {Array<Object>} attachments Array of attachments
* @prop {User} author The message author
* @prop {PrivateChannel | TextChannel | NewsChannel} channel The channel the message is in. Can be partial with only the id if the channel is not cached.
* @prop {PrivateChannel | TextChannel | NewsChannel} channel The channel the message is in. Can be partial with only the ID if the channel is not cached.
* @prop {Array<String>} channelMentions Array of mentions channels' ids
* @prop {String?} cleanContent Message content with mentions replaced by names. Mentions are currently escaped, but this behavior is [DEPRECATED] and will be removed soon. Use allowed mentions, the official way of avoiding unintended mentions, when creating messages.
* @prop {Command?} command The Command used in the Message, if any (CommandClient only)
Expand Down Expand Up @@ -41,7 +41,7 @@ const User = require("./User");
* @prop {String?} messageReference.messageID The ID of the original message this message was crossposted from
* @prop {Boolean} pinned Whether the message is pinned or not
* @prop {String?} prefix The prefix used in the Message, if any (CommandClient only)
* @prop {Object} reactions 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.
* @prop {Object} reactions An object containing the reactions on the message. Each key is a reaction emoji and each value is an object with properties `burst_colors` (Array<String>), `count` (Number), `count_details` (an object with `burst` and `normal` keys corresponding to the amount of reactions), `me` (Boolean) and `me_burst` for that specific reaction emoji.
* @prop {Message?} referencedMessage The message that was replied to. If undefined, message data was not received. If null, the message was deleted.
* @prop {Array<String>} roleMentions Array of mentioned roles' ids
* @prop {Array<Object>?} stickers [DEPRECATED] The stickers sent with the message
Expand Down Expand Up @@ -304,8 +304,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] = {
burst_colors: reaction.burst_colors,
count: reaction.count,
me: reaction.me
count_details: reaction.count_details,
me: reaction.me,
me_burst: reaction.me_burst
};
});
}
Expand Down