diff --git a/src/managers/roles.ts b/src/managers/roles.ts index f0a1fda..965f825 100644 --- a/src/managers/roles.ts +++ b/src/managers/roles.ts @@ -80,18 +80,21 @@ export class RolesManager extends BaseManager { } /** Delete a Guild Role */ - async delete(role: Role | string): Promise { + async delete(role: Role | string): Promise { + const oldRole = await this.get(typeof role === 'object' ? role.id : role) + await this.client.rest.delete( GUILD_ROLE(this.guild.id, typeof role === 'object' ? role.id : role) ) - return true + + return oldRole } async edit(role: Role | string, options: RoleModifyPayload): Promise { if (role instanceof Role) { role = role.id } - const resp = await this.client.rest.patch( + const resp: RolePayload = await this.client.rest.patch( GUILD_ROLE(this.guild.id, role), options ) diff --git a/src/structures/guild.ts b/src/structures/guild.ts index ec02a44..a1ee116 100644 --- a/src/structures/guild.ts +++ b/src/structures/guild.ts @@ -11,7 +11,10 @@ import { GuildPreview, MessageNotification, ContentFilter, - GuildModifyOptions + GuildModifyOptions, + GuildGetPruneCountOptions, + GuildGetPruneCountPayload, + GuildPruneCountPayload } from '../types/guild.ts' import { Base } from './base.ts' import { CreateGuildRoleOptions, RolesManager } from '../managers/roles.ts' @@ -26,7 +29,12 @@ import { GuildEmojisManager } from '../managers/guildEmojis.ts' import { Member } from './member.ts' import { User } from './user.ts' import { Application } from './application.ts' -import { GUILD_BAN, GUILD_BANS, GUILD_INTEGRATIONS } from '../types/endpoint.ts' +import { + GUILD_BAN, + GUILD_BANS, + GUILD_INTEGRATIONS, + GUILD_PRUNE +} from '../types/endpoint.ts' import { GuildVoiceStatesManager } from '../managers/guildVoiceStates.ts' import { RequestMembersOptions } from '../gateway/index.ts' import { GuildPresencesManager } from '../managers/presences.ts' @@ -354,6 +362,29 @@ export class Guild extends Base { return result === undefined ? this : result } + + async getPruneCount(options: GuildGetPruneCountOptions): Promise { + const query: GuildGetPruneCountPayload = { + days: options.days, + include_roles: + options.includeRoles !== undefined + ? options.includeRoles + .map((role) => (role instanceof Role ? role.id : role)) + .join(',') + : undefined + } + + const result: GuildPruneCountPayload = await this.client.rest.get( + // eslint-disable-next-line @typescript-eslint/restrict-plus-operands + GUILD_PRUNE(this.id) + + '?' + + Object.entries(query) + .map(([key, value]) => `${key}=${value}`) + .join('&') + ) + + return result.pruned as number + } } export class GuildIntegration extends Base { diff --git a/src/structures/role.ts b/src/structures/role.ts index f5e9129..91050aa 100644 --- a/src/structures/role.ts +++ b/src/structures/role.ts @@ -50,6 +50,10 @@ export class Role extends Base { this.mentionable = data.mentionable ?? this.mentionable } + async delete(): Promise { + return this.guild.roles.delete(this) + } + async edit(options: RoleModifyPayload): Promise { return this.guild.roles.edit(this, options) } diff --git a/src/types/guild.ts b/src/types/guild.ts index 90989c7..938b6bd 100644 --- a/src/types/guild.ts +++ b/src/types/guild.ts @@ -280,3 +280,17 @@ export interface GuildModifyOptions { publicUpdatesChannelID?: string | null preferredLocale?: string | null } + +export interface GuildPruneCountPayload { + pruned: number | null +} + +export interface GuildGetPruneCountPayload { + days?: number + include_roles?: string +} + +export interface GuildGetPruneCountOptions { + days?: number + includeRoles?: Array +}