feat: Guild.pruneMembers etc

This commit is contained in:
Yuzu 2022-07-01 10:46:41 -05:00
parent 5abbe95750
commit ea5f3d53a8
3 changed files with 55 additions and 9 deletions

View File

@ -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<DiscordMemberWithUser>(
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<number> {
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<number> {
const result = await this.session.rest.runMethod<{ pruned: number }>(
this.session.rest,
"GET",
Routes.GUILD_PRUNE(this.id),
);
return result.pruned;
}
}
export default Guild;

View File

@ -48,7 +48,6 @@ export class Role implements Model {
}
async delete(): Promise<void> {
// cool jS trick
await Guild.prototype.deleteRole.call({ id: this.guildId, session: this.session }, this.id);
}

View File

@ -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;
}