role name must be less than 100 characters (#2584)

This commit is contained in:
LTS20050703
2022-11-15 01:35:02 +07:00
committed by GitHub
parent cd5915c8b6
commit e995a651ce
4 changed files with 11 additions and 4 deletions

View File

@@ -42,7 +42,7 @@ export async function createRole(
}
export interface CreateGuildRole {
/** Name of the role, default: "new role" */
/** Name of the role, max 100 characters, default: "new role" */
name?: string;
/** Bitwise value of the enabled/disabled permissions, default: everyone permissions in guild */
permissions?: PermissionStrings[];

View File

@@ -39,7 +39,7 @@ export async function editRole(bot: Bot, guildId: BigString, roleId: BigString,
}
export interface EditGuildRole {
/** Name of the role, default: "new role" */
/** Name of the role, max 100 characters, default: "new role" */
name?: string;
/** Bitwise value of the enabled/disabled permissions, default: everyone permissions in guild */
permissions?: PermissionStrings[];

View File

@@ -7,6 +7,10 @@ export function createRole(bot: BotWithCache) {
bot.helpers.createRole = async function (guildId, options, reason) {
requireBotGuildPermissions(bot, bot.transformers.snowflake(guildId), ["MANAGE_ROLES"]);
if (options.name && !bot.utils.validateLength(options.name, { max: 100 })) {
throw new Error("Role name must be less than 100 characters");
}
return await createRole(guildId, options, reason);
};
}

View File

@@ -1,6 +1,5 @@
import { BotWithCache } from "../../deps.ts";
import { higherRolePosition } from "../permissions.ts";
import { highestRole, requireBotGuildPermissions } from "../permissions.ts";
import { higherRolePosition, highestRole, requireBotGuildPermissions } from "../permissions.ts";
export function editRole(bot: BotWithCache) {
const editRole = bot.helpers.editRole;
@@ -26,6 +25,10 @@ export function editRole(bot: BotWithCache) {
requireBotGuildPermissions(bot, guild, ["MANAGE_ROLES"]);
}
if (options.name && !bot.utils.validateLength(options.name, { max: 100 })) {
throw new Error("Role name must be less than 100 characters");
}
return await editRole(guildId, id, options);
};
}