fix(Action): Conditionally add recipient

#9925 djs
This commit is contained in:
Elysia 2023-11-13 20:28:30 +07:00
parent fe6a30e074
commit caf508dec9
3 changed files with 26 additions and 7 deletions

View File

@ -32,18 +32,31 @@ class GenericAction {
}
getChannel(data) {
const payloadData = { recipients: data.recipients ?? [data.author ?? data.user ?? { id: data.user_id }] };
const payloadData = {};
const id = data.channel_id ?? data.id;
if ('recipients' in data) {
payloadData.recipients = data.recipients;
} else {
// Try to resolve the recipient, but do not add the client user.
const recipient = data.author ?? data.user ?? { id: data.user_id };
if (recipient.id !== this.client.user.id) payloadData.recipients = [recipient];
}
if (id !== undefined) payloadData.id = id;
if ('guild_id' in data) payloadData.guild_id = data.guild_id;
if ('last_message_id' in data) payloadData.last_message_id = data.last_message_id;
return data.channel ?? this.getPayload(payloadData, this.client.channels, id, PartialTypes.CHANNEL);
return (
data[this.client.actions.injectedChannel] ??
this.getPayload(payloadData, this.client.channels, id, PartialTypes.CHANNEL)
);
}
getMessage(data, channel, cache) {
const id = data.message_id ?? data.id;
return (
data.message ??
data[this.client.actions.injectedMessage] ??
this.getPayload(
{
id,
@ -78,7 +91,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) {

View File

@ -3,6 +3,12 @@
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'));

View File

@ -811,9 +811,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),
me_burst: burst,
},