diff --git a/structures/Guild.ts b/structures/Guild.ts index 85f5ede..80742ca 100644 --- a/structures/Guild.ts +++ b/structures/Guild.ts @@ -50,9 +50,7 @@ export interface ModifyGuildEmoji { * @link https://discord.com/developers/docs/resources/guild#create-guild-ban */ export interface CreateGuildBan { - /** Number of days to delete messages for (0-7) */ deleteMessageDays?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7; - /** Reason for the ban */ reason?: string; } @@ -68,6 +66,15 @@ export interface ModifyGuildMember { communicationDisabledUntil?: number; } +/** + * @link https://discord.com/developers/docs/resources/guild#begin-guild-prune + * */ +export interface BeginGuildPrune { + days?: number; + computePruneCount?: boolean; + includeRoles?: Snowflake[]; +} + /** * Represents a guild * @link https://discord.com/developers/docs/resources/guild#guild-object @@ -261,7 +268,7 @@ export class Guild extends BaseGuild implements Model { const member = await this.session.rest.runMethod( this.session.rest, "PATCH", - Routes.GUILD_MEMBER(this.id, memberId) + Routes.GUILD_MEMBER(this.id, memberId), { nick: options.nick, roles: options.roles, @@ -269,11 +276,36 @@ export class Guild extends BaseGuild implements Model { deaf: options.deaf, channel_id: options.channelId, communication_disabled_until: options.communicationDisabledUntil ? new Date(options.communicationDisabledUntil).toISOString() : undefined, - }, + } ); return new Member(this.session, member, this.id); } + + async pruneMembers(options: BeginGuildPrune): Promise { + const result = await this.session.rest.runMethod<{ pruned: number }>( + this.session.rest, + "POST", + Routes.GUILD_PRUNE(this.id), + { + days: options.days, + compute_prune_count: options.computePruneCount, + include_roles: options.includeRoles, + }, + ); + + return result.pruned; + } + + async getPruneCount(): Promise { + const result = await this.session.rest.runMethod<{ pruned: number }>( + this.session.rest, + "GET", + Routes.GUILD_PRUNE(this.id), + ); + + return result.pruned; + } } export default Guild; diff --git a/structures/Role.ts b/structures/Role.ts index b8a53cf..be1f878 100644 --- a/structures/Role.ts +++ b/structures/Role.ts @@ -48,7 +48,6 @@ export class Role implements Model { } async delete(): Promise { - // cool jS trick await Guild.prototype.deleteRole.call({ id: this.guildId, session: this.session }, this.id); } diff --git a/util/Routes.ts b/util/Routes.ts index 9ebfcb6..34638c7 100644 --- a/util/Routes.ts +++ b/util/Routes.ts @@ -147,10 +147,8 @@ export function INTERACTION_ID_TOKEN(interactionId: Snowflake, token: string) { export function WEBHOOK(webhookId: Snowflake, token: string, options?: { wait?: boolean; threadId?: Snowflake }) { let url = `/webhooks/${webhookId}/${token}?`; - if (options) { - if (options.wait !== undefined) url += `wait=${options.wait}`; - if (options.threadId) url += `threadId=${options.threadId}`; - } + if (options?.wait !== undefined) url += `wait=${options.wait}`; + if (options?.threadId) url += `threadId=${options.threadId}`; return url; } @@ -158,3 +156,20 @@ export function WEBHOOK(webhookId: Snowflake, token: string, options?: { wait?: export function USER_NICK(guildId: Snowflake) { return `/guilds/${guildId}/members/@me`; } + +/** + * @link https://discord.com/developers/docs/resources/guild#get-guild-prune-count + * */ +export interface GetGuildPruneCountQuery { + days?: number; + includeRoles?: Snowflake | Snowflake[]; +} + +export function GUILD_PRUNE(guildId: Snowflake, options?: GetGuildPruneCountQuery) { + let url = `/guilds/${guildId}/prune?`; + + if (options?.days) url += `days=${options.days}`; + if (options?.includeRoles) url += `&include_roles=${options.includeRoles}`; + + return url; +}