parent
fe6a30e074
commit
caf508dec9
@ -32,18 +32,31 @@ class GenericAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getChannel(data) {
|
getChannel(data) {
|
||||||
const payloadData = { recipients: data.recipients ?? [data.author ?? data.user ?? { id: data.user_id }] };
|
const payloadData = {};
|
||||||
const id = data.channel_id ?? data.id;
|
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 (id !== undefined) payloadData.id = id;
|
||||||
if ('guild_id' in data) payloadData.guild_id = data.guild_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;
|
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) {
|
getMessage(data, channel, cache) {
|
||||||
const id = data.message_id ?? data.id;
|
const id = data.message_id ?? data.id;
|
||||||
return (
|
return (
|
||||||
data.message ??
|
data[this.client.actions.injectedMessage] ??
|
||||||
this.getPayload(
|
this.getPayload(
|
||||||
{
|
{
|
||||||
id,
|
id,
|
||||||
@ -78,7 +91,7 @@ class GenericAction {
|
|||||||
|
|
||||||
getUser(data) {
|
getUser(data) {
|
||||||
const id = data.user_id;
|
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) {
|
getUserFromMember(data) {
|
||||||
|
@ -3,6 +3,12 @@
|
|||||||
class ActionsManager {
|
class ActionsManager {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
this.client = 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('./ApplicationCommandPermissionsUpdate'));
|
||||||
this.register(require('./AutoModerationActionExecution'));
|
this.register(require('./AutoModerationActionExecution'));
|
||||||
|
@ -811,9 +811,9 @@ class Message extends Base {
|
|||||||
|
|
||||||
return this.client.actions.MessageReactionAdd.handle(
|
return this.client.actions.MessageReactionAdd.handle(
|
||||||
{
|
{
|
||||||
user: this.client.user,
|
[this.client.actions.injectedUser]: this.client.user,
|
||||||
channel: this.channel,
|
[this.client.actions.injectedChannel]: this.channel,
|
||||||
message: this,
|
[this.client.actions.injectedMessage]: this,
|
||||||
emoji: Util.resolvePartialEmoji(emoji),
|
emoji: Util.resolvePartialEmoji(emoji),
|
||||||
me_burst: burst,
|
me_burst: burst,
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user