Added ILLEGAL_CHANNEL_NAMES
and NULL_CHANNEL_NAMES
guild feature flags
This commit is contained in:
parent
f9ff5b35f3
commit
35c7489f72
@ -3,7 +3,7 @@ import { BaseClass } from "./BaseClass";
|
||||
import { Guild } from "./Guild";
|
||||
import { PublicUserProjection, User } from "./User";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { containsAll, emitEvent, getPermission, Snowflake, trimSpecial } from "../util";
|
||||
import { containsAll, emitEvent, getPermission, Snowflake, trimSpecial, InvisibleCharacters } from "../util";
|
||||
import { ChannelCreateEvent, ChannelRecipientRemoveEvent } from "../interfaces";
|
||||
import { Recipient } from "./Recipient";
|
||||
import { Message } from "./Message";
|
||||
@ -147,6 +147,7 @@ export class Channel extends BaseClass {
|
||||
skipExistsCheck?: boolean;
|
||||
skipPermissionCheck?: boolean;
|
||||
skipEventEmit?: boolean;
|
||||
skipNameChecks?: boolean;
|
||||
}
|
||||
) {
|
||||
if (!opts?.skipPermissionCheck) {
|
||||
@ -155,6 +156,23 @@ export class Channel extends BaseClass {
|
||||
permissions.hasThrow("MANAGE_CHANNELS");
|
||||
}
|
||||
|
||||
if (!opts?.skipNameChecks) {
|
||||
const guild = await Guild.findOneOrFail({ id: channel.guild_id });
|
||||
if (!guild.features.includes("ILLEGAL_CHANNEL_NAMES") && channel.name) {
|
||||
for (var character of InvisibleCharacters)
|
||||
channel.name = channel.name.split(character).join("-");
|
||||
|
||||
channel.name = channel.name.split(/\-+/g).join("-"); //replace multiple occurances with just one
|
||||
channel.name = channel.name.split("-").filter(Boolean).join("-"); //trim '-' character
|
||||
}
|
||||
|
||||
if (!guild.features.includes("NULL_CHANNEL_NAMES")) {
|
||||
if (channel.name) channel.name = channel.name.trim();
|
||||
|
||||
if (!channel.name) throw new HTTPError("Channel name cannot be empty.");
|
||||
}
|
||||
}
|
||||
|
||||
switch (channel.type) {
|
||||
case ChannelType.GUILD_TEXT:
|
||||
case ChannelType.GUILD_VOICE:
|
||||
|
55
util/src/util/InvisibleCharacters.ts
Normal file
55
util/src/util/InvisibleCharacters.ts
Normal file
@ -0,0 +1,55 @@
|
||||
export const InvisibleCharacters = [
|
||||
"\t",
|
||||
" ",
|
||||
"",
|
||||
"͏",
|
||||
"",
|
||||
"ᅟ",
|
||||
"ᅠ",
|
||||
"឴",
|
||||
"឵",
|
||||
"",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
" ",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
" ",
|
||||
" ",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
" ",
|
||||
"⠀",
|
||||
"ㅤ",
|
||||
"",
|
||||
"ᅠ",
|
||||
"𝅙",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
""
|
||||
]
|
@ -18,3 +18,4 @@ export * from "./Snowflake";
|
||||
export * from "./String";
|
||||
export * from "./Array";
|
||||
export * from "./TraverseDirectory";
|
||||
export * from "./InvisibleCharacters";
|
Loading…
x
Reference in New Issue
Block a user