Skip to content

Commit

Permalink
Include forgotten properties in reaction events
Browse files Browse the repository at this point in the history
  • Loading branch information
DonovanDMC committed Jun 10, 2024
1 parent 1151c64 commit f73241e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
18 changes: 14 additions & 4 deletions lib/gateway/Shard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -792,9 +792,14 @@ export default class Shard extends TypedEmitter<ShardEvents> {
guild,
guildID: packet.d.guild_id,
id: packet.d.message_id ,
// @TODO (1.11.0): Convert this to only be User, and add a member field
author: packet.d.message_author_id === undefined ? undefined : guild?.members.get(packet.d.message_author_id) ?? this.client.users.get(packet.d.message_author_id) ?? { id: packet.d.message_author_id }
}, reactor, packet.d.emoji, packet.d.burst);
author: packet.d.message_author_id === undefined ? undefined : this.client.users.get(packet.d.message_author_id) ?? { id: packet.d.message_author_id },
member: packet.d.message_author_id === undefined ? undefined : guild?.members.get(packet.d.message_author_id) ?? { id: packet.d.message_author_id }
}, reactor, {
burst: packet.d.burst,
burstColors: packet.d.burst_colors,
emoji: packet.d.emoji,
type: packet.d.type
});
break;
}

Expand Down Expand Up @@ -831,7 +836,12 @@ export default class Shard extends TypedEmitter<ShardEvents> {
guild: packet.d.guild_id ? this.client.guilds.get(packet.d.guild_id) : undefined,
guildID: packet.d.guild_id,
id: packet.d.message_id
}, reactor, packet.d.emoji, packet.d.burst);
}, reactor, {
burst: packet.d.burst,
burstColors: packet.d.burst_colors,
emoji: packet.d.emoji,
type: packet.d.type
});
break;
}

Expand Down
7 changes: 7 additions & 0 deletions lib/types/channels.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1242,3 +1242,10 @@ export interface PollAnswerCount {
/** The IDs of the users that voted. This will always be out of sync unless you either {@link Poll#getAnswerUsers | fetch the answer voters over REST}, or if the poll was created after the bot started, and stays in the cache. */
users: Array<string>;
}

export interface EventReaction {
burst: boolean;
burstColors?: Array<string>;
emoji: PartialEmoji;
type: ReactionType;
}
7 changes: 4 additions & 3 deletions lib/types/events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import type {
ThreadMember,
UncachedThreadMember,
AnyVoiceChannel,
PollAnswer
PollAnswer,
EventReaction
} from "./channels";
import type { RawRequest } from "./request-handler";
import type { AutoModerationActionExecution, DeletedPrivateChannel, VoiceChannelEffect } from "./gateway";
Expand Down Expand Up @@ -180,9 +181,9 @@ export interface ClientEvents {
/** @event Emitted when a vote is added to a poll. Requires the `GUILD_MESSAGE_POLLS` for guild messages, and `DIRECT_MESSAGE_POLLS` for direct messages. */
messagePollVoteRemove: [message: PossiblyUncachedMessage, user: User | Uncached, answer: PollAnswer | { answerID: number; }];
/** @event Emitted when a reaction is added to a message. For uncached messages, `author` will not be present if the reaction was added to a webhook message. Requires the `GUILD_MESSAGE_REACTIONS` for guild messages, and `DIRECT_MESSAGE_REACTIONS` for direct messages. */
messageReactionAdd: [message: PossiblyUncachedMessage & { author?: Member | User | Uncached; }, reactor: Member | User | Uncached, reaction: PartialEmoji, burst: boolean];
messageReactionAdd: [message: PossiblyUncachedMessage & { author?: User | Uncached; member?: Member | Uncached; }, reactor: Member | User | Uncached, reaction: EventReaction];
/** @event Emitted when a reaction is removed from a message. Requires the `GUILD_MESSAGE_REACTIONS` for guild messages, and `DIRECT_MESSAGE_REACTIONS` for direct messages. */
messageReactionRemove: [message: PossiblyUncachedMessage, reactor: Member | User | Uncached, reaction: PartialEmoji, burst: boolean];
messageReactionRemove: [message: PossiblyUncachedMessage, reactor: Member | User | Uncached, reaction: EventReaction];
/** @event Emitted when all reactions are removed from a message. Requires the `GUILD_MESSAGE_REACTIONS` for guild messages, and `DIRECT_MESSAGE_REACTIONS` for direct messages. */
messageReactionRemoveAll: [message: PossiblyUncachedMessage];
/** @event Emitted when a specific reaction is removed for all users from a message. Requires the `GUILD_MESSAGE_REACTIONS` for guild messages, and `DIRECT_MESSAGE_REACTIONS` for direct messages. */
Expand Down
4 changes: 3 additions & 1 deletion lib/types/gateway-raw.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import type { RawScheduledEvent } from "./scheduled-events";
import type { RawVoiceState } from "./voice";
import type { RawInteraction } from "./interactions";
import type { RawAuditLogEntry } from "./audit-log";
import type { GatewayOPCodes, InviteTargetTypes } from "../Constants";
import type { GatewayOPCodes, InviteTargetTypes, ReactionType } from "../Constants";

export type AnyReceivePacket = AnyDispatchPacket | HeartbeatPacket | ReconnectPacket | InvalidSessionPacket | HelloPacket | HeartbeatAckPacket;
export interface RawPacket {
Expand Down Expand Up @@ -427,6 +427,7 @@ export interface MessageReactionAddPacket extends BaseDispatchPacket {
member?: RawMember;
message_author_id?: string;
message_id: string;
type: ReactionType;
user_id: string;
};
t: "MESSAGE_REACTION_ADD";
Expand All @@ -440,6 +441,7 @@ export interface MessageReactionRemovePacket extends BaseDispatchPacket {
emoji: PartialEmoji;
guild_id?: string;
message_id: string;
type: ReactionType;
user_id: string;
};
t: "MESSAGE_REACTION_REMOVE";
Expand Down

0 comments on commit f73241e

Please sign in to comment.