1
0
mirror of https://github.com/spacebarchat/server.git synced 2024-11-06 10:52:31 +01:00

Categories skip most of the ALLOW_INVALID_CHANNEL_NAMES checks on discord.com ( they also trim whitespace )

This commit is contained in:
Madeline 2022-04-24 15:09:45 +10:00
parent ec3c158269
commit 2316002cd8
No known key found for this signature in database
GPG Key ID: 1958E017C36F2E47
2 changed files with 17 additions and 9 deletions

View File

@ -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, InvisibleCharacters } from "../util";
import { containsAll, emitEvent, getPermission, Snowflake, trimSpecial, InvisibleCharacters, ChannelTypes } from "../util";
import { ChannelCreateEvent, ChannelRecipientRemoveEvent } from "../interfaces";
import { Recipient } from "./Recipient";
import { Message } from "./Message";
@ -173,12 +173,20 @@ export class Channel extends BaseClass {
if (channel.name.includes(character))
throw new HTTPError("Channel name cannot include invalid characters", 403);
// Categories skip these checks on discord.com
if (channel.type !== ChannelType.GUILD_CATEGORY) {
if (channel.name.includes(" "))
throw new HTTPError("Channel name cannot include invalid characters", 403);
if (channel.name.match(/\-\-+/g))
throw new HTTPError("Channel name cannot include multiple adjacent dashes.", 403)
throw new HTTPError("Channel name cannot include multiple adjacent dashes.", 403);
if (channel.name.charAt(0) === "-" ||
channel.name.charAt(channel.name.length - 1) === "-")
throw new HTTPError("Channel name cannot start/end with dash.", 403)
throw new HTTPError("Channel name cannot start/end with dash.", 403);
}
else
channel.name = channel.name.trim(); //category names are trimmed client side on discord.com
}
if (!guild.features.includes("ALLOW_UNNAMED_CHANNELS")) {

View File

@ -1,7 +1,7 @@
// List from https://invisible-characters.com/
export const InvisibleCharacters = [
'\u{9}', //Tab
'\u{20}', //Space
//'\u{20}', //Space //categories can have spaces in them
'\u{ad}', //Soft hyphen
'\u{34f}', //Combining grapheme joiner
'\u{61c}', //Arabic letter mark