From ab0ecb0e69cb11687b38bc80fb0114be0a7f4d88 Mon Sep 17 00:00:00 2001 From: izexi <43889168+izexi@users.noreply.github.com> Date: Sun, 14 Apr 2019 09:58:27 +0100 Subject: [PATCH 1/6] add Invite#deletable --- src/structures/Invite.js | 11 +++++++++++ typings/index.d.ts | 1 + 2 files changed, 12 insertions(+) diff --git a/src/structures/Invite.js b/src/structures/Invite.js index fec3f2d7d1d2..70a258bd69f5 100644 --- a/src/structures/Invite.js +++ b/src/structures/Invite.js @@ -1,6 +1,7 @@ 'use strict'; const { Endpoints } = require('../util/Constants'); +const Permissions = require('../util/Permissions'); const Base = require('./Base'); /** @@ -91,6 +92,16 @@ class Invite extends Base { return this.createdTimestamp ? new Date(this.createdTimestamp) : null; } + /** + * Whether the invite is deletable by the client user + * @type {boolean} + * @readonly + */ + get deletable() { + return this.channel.permissionsFor(this.client.user).has(Permissions.FLAGS.MANAGE_CHANNELS, false) || + this.guild.me.permissions.has(Permissions.FLAGS.MANAGE_GUILD); + } + /** * The timestamp the invite will expire at * @type {?number} diff --git a/typings/index.d.ts b/typings/index.d.ts index 4af8827c3eff..5f114940c8fa 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -613,6 +613,7 @@ declare module 'discord.js' { public code: string; public readonly createdAt: Date; public createdTimestamp: number; + public readonly deletable: boolean; public readonly expiresAt: Date; public readonly expiresTimestamp: number; public guild: Guild; From eb35b5e5393176c78ea7653ca49e7daa5924ac6f Mon Sep 17 00:00:00 2001 From: izexi <43889168+izexi@users.noreply.github.com> Date: Mon, 15 Apr 2019 20:18:28 +0100 Subject: [PATCH 2/6] fix ci --- typings/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index b9d929097bf8..a2cc5fb7ac27 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -614,8 +614,8 @@ declare module 'discord.js' { constructor(client: Client, data: object); public channel: GuildChannel; public code: string; - public readonly deletable: boolean; - public readonly createdAt: Date | null; + public readonly deletable: boolean; + public readonly createdAt: Date | null; public createdTimestamp: number | null; public readonly expiresAt: Date | null; public readonly expiresTimestamp: number | null; From 6ec773de3a7e7631de79b02d70ea2a5f04cb4f1b Mon Sep 17 00:00:00 2001 From: izexi <43889168+izexi@users.noreply.github.com> Date: Mon, 15 Apr 2019 20:25:56 +0100 Subject: [PATCH 3/6] reee --- typings/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index a2cc5fb7ac27..6a6e44861121 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -614,8 +614,8 @@ declare module 'discord.js' { constructor(client: Client, data: object); public channel: GuildChannel; public code: string; - public readonly deletable: boolean; - public readonly createdAt: Date | null; + public readonly deletable: boolean; + public readonly createdAt: Date | null; public createdTimestamp: number | null; public readonly expiresAt: Date | null; public readonly expiresTimestamp: number | null; From dd82fc0afc2c0c8d5a2c0b86db31f7e63f2d2285 Mon Sep 17 00:00:00 2001 From: izexi <43889168+izexi@users.noreply.github.com> Date: Mon, 15 Apr 2019 20:31:19 +0100 Subject: [PATCH 4/6] since guild is nullable --- src/structures/Invite.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/structures/Invite.js b/src/structures/Invite.js index 70a258bd69f5..715e6ae7e434 100644 --- a/src/structures/Invite.js +++ b/src/structures/Invite.js @@ -98,8 +98,9 @@ class Invite extends Base { * @readonly */ get deletable() { + const guild = this.guild || this.channel.guild; return this.channel.permissionsFor(this.client.user).has(Permissions.FLAGS.MANAGE_CHANNELS, false) || - this.guild.me.permissions.has(Permissions.FLAGS.MANAGE_GUILD); + guild.me.permissions.has(Permissions.FLAGS.MANAGE_GUILD); } /** From 560f44119be6dc98636c66d968a95110e219a407 Mon Sep 17 00:00:00 2001 From: izexi <43889168+izexi@users.noreply.github.com> Date: Sun, 21 Apr 2019 13:38:46 +0100 Subject: [PATCH 5/6] accommodate for external invites --- src/structures/Invite.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/structures/Invite.js b/src/structures/Invite.js index 715e6ae7e434..24df9ad127a2 100644 --- a/src/structures/Invite.js +++ b/src/structures/Invite.js @@ -98,7 +98,8 @@ class Invite extends Base { * @readonly */ get deletable() { - const guild = this.guild || this.channel.guild; + const guild = this.channel.guild; + if (!guild || !this.client.guilds.has(guild.id)) return false; return this.channel.permissionsFor(this.client.user).has(Permissions.FLAGS.MANAGE_CHANNELS, false) || guild.me.permissions.has(Permissions.FLAGS.MANAGE_GUILD); } From a95846ced2f90178d104beab5bbe922efd4d4651 Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Mon, 22 Apr 2019 09:18:00 +0200 Subject: [PATCH 6/6] nit(Invite): use guild instead of channel.guild --- src/structures/Invite.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/Invite.js b/src/structures/Invite.js index 24df9ad127a2..43d8c6524b3c 100644 --- a/src/structures/Invite.js +++ b/src/structures/Invite.js @@ -98,7 +98,7 @@ class Invite extends Base { * @readonly */ get deletable() { - const guild = this.channel.guild; + const guild = this.guild; if (!guild || !this.client.guilds.has(guild.id)) return false; return this.channel.permissionsFor(this.client.user).has(Permissions.FLAGS.MANAGE_CHANNELS, false) || guild.me.permissions.has(Permissions.FLAGS.MANAGE_GUILD);