mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 10:33:30 +01:00
fix(GuildAuditLog): Remove Promises in constructor (#7089)
This commit is contained in:
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
const { Collection } = require('@discordjs/collection');
|
const { Collection } = require('@discordjs/collection');
|
||||||
const Integration = require('./Integration');
|
const Integration = require('./Integration');
|
||||||
|
const Invite = require('./Invite');
|
||||||
const { StageInstance } = require('./StageInstance');
|
const { StageInstance } = require('./StageInstance');
|
||||||
const { Sticker } = require('./Sticker');
|
const { Sticker } = require('./Sticker');
|
||||||
const Webhook = require('./Webhook');
|
const Webhook = require('./Webhook');
|
||||||
const { OverwriteTypes, PartialTypes } = require('../util/Constants');
|
const { OverwriteTypes, PartialTypes } = require('../util/Constants');
|
||||||
const Permissions = require('../util/Permissions');
|
|
||||||
const SnowflakeUtil = require('../util/SnowflakeUtil');
|
const SnowflakeUtil = require('../util/SnowflakeUtil');
|
||||||
const Util = require('../util/Util');
|
const Util = require('../util/Util');
|
||||||
|
|
||||||
@@ -502,19 +502,21 @@ class GuildAuditLogsEntry {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else if (targetType === Targets.INVITE) {
|
} else if (targetType === Targets.INVITE) {
|
||||||
this.target = guild.members.fetch(guild.client.user.id).then(async me => {
|
let change = this.changes.find(c => c.key === 'code');
|
||||||
if (me.permissions.has(Permissions.FLAGS.MANAGE_GUILD)) {
|
change = change.new ?? change.old;
|
||||||
let change = this.changes.find(c => c.key === 'code');
|
|
||||||
change = change.new ?? change.old;
|
this.target =
|
||||||
const invites = await guild.invites.fetch();
|
guild.invites.cache.get(change) ??
|
||||||
this.target = invites.find(i => i.code === change) ?? null;
|
new Invite(
|
||||||
} else {
|
guild.client,
|
||||||
this.target = this.changes.reduce((o, c) => {
|
this.changes.reduce(
|
||||||
o[c.key] = c.new ?? c.old;
|
(o, c) => {
|
||||||
return o;
|
o[c.key] = c.new ?? c.old;
|
||||||
}, {});
|
return o;
|
||||||
}
|
},
|
||||||
});
|
{ guild },
|
||||||
|
),
|
||||||
|
);
|
||||||
} else if (targetType === Targets.MESSAGE) {
|
} else if (targetType === Targets.MESSAGE) {
|
||||||
// Discord sends a channel id for the MESSAGE_BULK_DELETE action type.
|
// Discord sends a channel id for the MESSAGE_BULK_DELETE action type.
|
||||||
this.target =
|
this.target =
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ const { Error } = require('../errors');
|
|||||||
const { Endpoints } = require('../util/Constants');
|
const { Endpoints } = require('../util/Constants');
|
||||||
const Permissions = require('../util/Permissions');
|
const Permissions = require('../util/Permissions');
|
||||||
|
|
||||||
|
// TODO: Convert `inviter` and `channel` in this class to a getter.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents an invitation to a guild channel.
|
* Represents an invitation to a guild channel.
|
||||||
* @extends {Base}
|
* @extends {Base}
|
||||||
@@ -106,12 +108,24 @@ class Invite extends Base {
|
|||||||
this.maxUses ??= null;
|
this.maxUses ??= null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('inviter_id' in data) {
|
||||||
|
/**
|
||||||
|
* The user's id who created this invite
|
||||||
|
* @type {?Snowflake}
|
||||||
|
*/
|
||||||
|
this.inviterId = data.inviter_id;
|
||||||
|
this.inviter = this.client.users.resolve(data.inviter_id);
|
||||||
|
} else {
|
||||||
|
this.inviterId ??= null;
|
||||||
|
}
|
||||||
|
|
||||||
if ('inviter' in data) {
|
if ('inviter' in data) {
|
||||||
/**
|
/**
|
||||||
* The user who created this invite
|
* The user who created this invite
|
||||||
* @type {?User}
|
* @type {?User}
|
||||||
*/
|
*/
|
||||||
this.inviter = this.client.users._add(data.inviter);
|
this.inviter ??= this.client.users._add(data.inviter);
|
||||||
|
this.inviterId = data.inviter.id;
|
||||||
} else {
|
} else {
|
||||||
this.inviter ??= null;
|
this.inviter ??= null;
|
||||||
}
|
}
|
||||||
@@ -154,12 +168,22 @@ class Invite extends Base {
|
|||||||
this.targetType ??= null;
|
this.targetType ??= null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ('channel_id' in data) {
|
||||||
|
/**
|
||||||
|
* The channel's id this invite is for
|
||||||
|
* @type {Snowflake}
|
||||||
|
*/
|
||||||
|
this.channelId = data.channel_id;
|
||||||
|
this.channel = this.client.channels.cache.get(data.channel_id);
|
||||||
|
}
|
||||||
|
|
||||||
if ('channel' in data) {
|
if ('channel' in data) {
|
||||||
/**
|
/**
|
||||||
* The channel this invite is for
|
* The channel this invite is for
|
||||||
* @type {Channel}
|
* @type {Channel}
|
||||||
*/
|
*/
|
||||||
this.channel = this.client.channels._add(data.channel, this.guild, { cache: false });
|
this.channel ??= this.client.channels._add(data.channel, this.guild, { cache: false });
|
||||||
|
this.channelId ??= data.channel.id;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ('created_at' in data) {
|
if ('created_at' in data) {
|
||||||
|
|||||||
4
typings/index.d.ts
vendored
4
typings/index.d.ts
vendored
@@ -1302,6 +1302,7 @@ export class InteractionWebhook extends PartialWebhookMixin() {
|
|||||||
export class Invite extends Base {
|
export class Invite extends Base {
|
||||||
private constructor(client: Client, data: RawInviteData);
|
private constructor(client: Client, data: RawInviteData);
|
||||||
public channel: GuildChannel | PartialGroupDMChannel;
|
public channel: GuildChannel | PartialGroupDMChannel;
|
||||||
|
public channelId: Snowflake;
|
||||||
public code: string;
|
public code: string;
|
||||||
public readonly deletable: boolean;
|
public readonly deletable: boolean;
|
||||||
public readonly createdAt: Date | null;
|
public readonly createdAt: Date | null;
|
||||||
@@ -1310,6 +1311,7 @@ export class Invite extends Base {
|
|||||||
public readonly expiresTimestamp: number | null;
|
public readonly expiresTimestamp: number | null;
|
||||||
public guild: InviteGuild | Guild | null;
|
public guild: InviteGuild | Guild | null;
|
||||||
public inviter: User | null;
|
public inviter: User | null;
|
||||||
|
public inviterId: Snowflake | null;
|
||||||
public maxAge: number | null;
|
public maxAge: number | null;
|
||||||
public maxUses: number | null;
|
public maxUses: number | null;
|
||||||
public memberCount: number;
|
public memberCount: number;
|
||||||
@@ -4356,7 +4358,7 @@ export interface GuildAuditLogsEntryTargetField<TActionType extends GuildAuditLo
|
|||||||
USER: User | null;
|
USER: User | null;
|
||||||
GUILD: Guild;
|
GUILD: Guild;
|
||||||
WEBHOOK: Webhook;
|
WEBHOOK: Webhook;
|
||||||
INVITE: Invite | { [x: string]: unknown };
|
INVITE: Invite;
|
||||||
MESSAGE: TActionType extends 'MESSAGE_BULK_DELETE' ? Guild | { id: Snowflake } : User;
|
MESSAGE: TActionType extends 'MESSAGE_BULK_DELETE' ? Guild | { id: Snowflake } : User;
|
||||||
INTEGRATION: Integration;
|
INTEGRATION: Integration;
|
||||||
CHANNEL: GuildChannel | { id: Snowflake; [x: string]: unknown };
|
CHANNEL: GuildChannel | { id: Snowflake; [x: string]: unknown };
|
||||||
|
|||||||
Reference in New Issue
Block a user