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

fix(Actions): inject built data by using a symbol #9204

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/client/actions/Action.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GenericAction {
getChannel(data) {
const id = data.channel_id ?? data.id;
return (
data.channel ??
data[this.client.actions.injectedChannel] ??
this.getPayload(
{
id,
Expand All @@ -51,7 +51,7 @@ class GenericAction {
getMessage(data, channel, cache) {
const id = data.message_id ?? data.id;
return (
data.message ??
data[this.client.actions.injectedMessage] ??
this.getPayload(
{
id,
Expand Down Expand Up @@ -86,7 +86,7 @@ class GenericAction {

getUser(data) {
const id = data.user_id;
return data.user ?? this.getPayload({ id }, this.client.users, id, PartialTypes.USER);
return data[this.client.actions.injectedUser] ?? this.getPayload({ id }, this.client.users, id, PartialTypes.USER);
}

getUserFromMember(data) {
Expand Down
7 changes: 7 additions & 0 deletions src/client/actions/ActionsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ class ActionsManager {
constructor(client) {
this.client = client;

// These symbols represent fully built data that we inject at times when calling actions manually. Action#getUser,
// for example, will return the injected data (which is assumed to be a built structure) instead of trying to make
// it from provided data
this.injectedUser = Symbol('djs.actions.injectedUser');
this.injectedChannel = Symbol('djs.actions.injectedChannel');
this.injectedMessage = Symbol('djs.actions.injectedMessage');

this.register(require('./ApplicationCommandPermissionsUpdate'));
this.register(require('./AutoModerationActionExecution'));
this.register(require('./AutoModerationRuleCreate'));
Expand Down
6 changes: 3 additions & 3 deletions src/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -802,9 +802,9 @@ class Message extends Base {

return this.client.actions.MessageReactionAdd.handle(
{
user: this.client.user,
channel: this.channel,
message: this,
[this.client.actions.injectedUser]: this.client.user,
[this.client.actions.injectedChannel]: this.channel,
[this.client.actions.injectedMessage]: this,
emoji: Util.resolvePartialEmoji(emoji),
},
true,
Expand Down