From e62b52d16004111e882b2f00cfa3339294e6ece9 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Thu, 21 Jan 2021 07:57:05 +0100 Subject: [PATCH] feat(handlers): check for message max delete days (#416) * check prune max days * patch(handlers): max days is 30 * change in description too * fix: merge problems --- src/api/handlers/guild.ts | 10 ++++------ src/types/errors.ts | 1 + src/types/guild.ts | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/api/handlers/guild.ts b/src/api/handlers/guild.ts index da75af44d..b70e532ab 100644 --- a/src/api/handlers/guild.ts +++ b/src/api/handlers/guild.ts @@ -479,9 +479,8 @@ export async function swapRoles(guildID: string, rolePositons: PositionSwap) { /** Check how many members would be removed from the server in a prune operation. Requires the KICK_MEMBERS permission */ export async function getPruneCount(guildID: string, options: PruneOptions) { - if (options.days < 1) { - throw new Error(Errors.PRUNE_MIN_DAYS); - } + if (options.days < 1) throw new Error(Errors.PRUNE_MIN_DAYS); + if (options.days > 30) throw new Error(Errors.PRUNE_MAX_DAYS); const hasPerm = await botHasPermission(guildID, ["KICK_MEMBERS"]); if (!hasPerm) { @@ -498,9 +497,8 @@ export async function getPruneCount(guildID: string, options: PruneOptions) { /** Begin pruning all members in the given time period */ export async function pruneMembers(guildID: string, options: PruneOptions) { - if (options.days < 1) { - throw new Error(Errors.PRUNE_MIN_DAYS); - } + if (options.days < 1) throw new Error(Errors.PRUNE_MIN_DAYS); + if (options.days > 30) throw new Error(Errors.PRUNE_MAX_DAYS); const hasPerm = await botHasPermission(guildID, ["KICK_MEMBERS"]); if (!hasPerm) { diff --git a/src/types/errors.ts b/src/types/errors.ts index 33b99d315..fe9582e7e 100644 --- a/src/types/errors.ts +++ b/src/types/errors.ts @@ -42,6 +42,7 @@ export enum Errors { RULES_CHANNEL_CANNOT_BE_DELETED = "RULES_CHANNEL_CANNOT_BE_DELETED", UPDATES_CHANNEL_CANNOT_BE_DELETED = "UPDATES_CHANNEL_CANNOT_BE_DELETED", GUILD_NOT_FOUND = "GUILD_NOT_FOUND", + PRUNE_MAX_DAYS = "PRUNE_MAX_DAYS", GUILD_NOT_DISCOVERABLE = "GUILD_NOT_DISCOVERABLE", MISSING_CHANGE_NICKNAME = "MISSING_CHANGE_NICKNAME", } diff --git a/src/types/guild.ts b/src/types/guild.ts index ffb727c9b..4e15e021e 100644 --- a/src/types/guild.ts +++ b/src/types/guild.ts @@ -535,7 +535,7 @@ export interface PrunePayload { } export interface PruneOptions { - /** number of days to count prune for (1 or more). Defaults to 7 days. */ + /** number of days to count prune for (1 - 30). Defaults to 7 days. */ days: number; /** Include members with these role ids */ roles: string[];