Add guild prune function
This commit is contained in:
parent
2d27068f5c
commit
8b564a4b49
2 changed files with 49 additions and 12 deletions
|
@ -12,9 +12,9 @@ import {
|
||||||
MessageNotification,
|
MessageNotification,
|
||||||
ContentFilter,
|
ContentFilter,
|
||||||
GuildModifyOptions,
|
GuildModifyOptions,
|
||||||
GuildGetPruneCountOptions,
|
|
||||||
GuildGetPruneCountPayload,
|
GuildGetPruneCountPayload,
|
||||||
GuildPruneCountPayload
|
GuildPruneCountPayload,
|
||||||
|
GuildBeginPrunePayload
|
||||||
} from '../types/guild.ts'
|
} from '../types/guild.ts'
|
||||||
import { Base } from './base.ts'
|
import { Base } from './base.ts'
|
||||||
import { CreateGuildRoleOptions, RolesManager } from '../managers/roles.ts'
|
import { CreateGuildRoleOptions, RolesManager } from '../managers/roles.ts'
|
||||||
|
@ -363,15 +363,15 @@ export class Guild extends Base {
|
||||||
return result === undefined ? this : result
|
return result === undefined ? this : result
|
||||||
}
|
}
|
||||||
|
|
||||||
async getPruneCount(options: GuildGetPruneCountOptions): Promise<number> {
|
async getPruneCount(
|
||||||
|
days?: number,
|
||||||
|
includeRoles?: Array<Role | string>
|
||||||
|
): Promise<number> {
|
||||||
const query: GuildGetPruneCountPayload = {
|
const query: GuildGetPruneCountPayload = {
|
||||||
days: options.days,
|
days: days,
|
||||||
include_roles:
|
include_roles: includeRoles
|
||||||
options.includeRoles !== undefined
|
?.map((role) => (role instanceof Role ? role.id : role))
|
||||||
? options.includeRoles
|
|
||||||
.map((role) => (role instanceof Role ? role.id : role))
|
|
||||||
.join(',')
|
.join(',')
|
||||||
: undefined
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const result: GuildPruneCountPayload = await this.client.rest.get(
|
const result: GuildPruneCountPayload = await this.client.rest.get(
|
||||||
|
@ -385,6 +385,42 @@ export class Guild extends Base {
|
||||||
|
|
||||||
return result.pruned as number
|
return result.pruned as number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async prune(
|
||||||
|
days?: number,
|
||||||
|
computePruneCount?: false,
|
||||||
|
includeRoles?: Array<Role | string>
|
||||||
|
): Promise<null>
|
||||||
|
async prune(
|
||||||
|
days?: number,
|
||||||
|
computePruneCount?: true,
|
||||||
|
includeRoles?: Array<Role | string>
|
||||||
|
): Promise<number>
|
||||||
|
async prune(
|
||||||
|
days?: number,
|
||||||
|
computePruneCount?: undefined,
|
||||||
|
includeRoles?: Array<Role | string>
|
||||||
|
): Promise<number>
|
||||||
|
async prune(
|
||||||
|
days?: number,
|
||||||
|
computePruneCount?: boolean,
|
||||||
|
includeRoles?: Array<Role | string>
|
||||||
|
): Promise<number | null> {
|
||||||
|
const body: GuildBeginPrunePayload = {
|
||||||
|
days: days,
|
||||||
|
compute_prune_count: computePruneCount,
|
||||||
|
include_roles: includeRoles?.map((role) =>
|
||||||
|
role instanceof Role ? role.id : role
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const result: GuildPruneCountPayload = await this.client.rest.post(
|
||||||
|
GUILD_PRUNE(this.id),
|
||||||
|
body
|
||||||
|
)
|
||||||
|
|
||||||
|
return result.pruned
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class GuildIntegration extends Base {
|
export class GuildIntegration extends Base {
|
||||||
|
|
|
@ -290,7 +290,8 @@ export interface GuildGetPruneCountPayload {
|
||||||
include_roles?: string
|
include_roles?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GuildGetPruneCountOptions {
|
export interface GuildBeginPrunePayload {
|
||||||
days?: number
|
days?: number
|
||||||
includeRoles?: Array<Role | string>
|
compute_prune_count?: boolean
|
||||||
|
include_roles?: string[]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue