Add get guild prune. add role delete in role structure

This commit is contained in:
Helloyunho 2021-01-21 14:24:41 +09:00
parent 989706e71a
commit 2d27068f5c
4 changed files with 57 additions and 5 deletions

View file

@ -80,18 +80,21 @@ export class RolesManager extends BaseManager<RolePayload, Role> {
}
/** Delete a Guild Role */
async delete(role: Role | string): Promise<boolean> {
async delete(role: Role | string): Promise<Role | undefined> {
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<Role> {
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
)

View file

@ -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<number> {
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 {

View file

@ -50,6 +50,10 @@ export class Role extends Base {
this.mentionable = data.mentionable ?? this.mentionable
}
async delete(): Promise<Role | undefined> {
return this.guild.roles.delete(this)
}
async edit(options: RoleModifyPayload): Promise<Role> {
return this.guild.roles.edit(this, options)
}

View file

@ -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<Role | string>
}