diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-04-24 15:09:45 +1000 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-04-24 15:09:45 +1000 |
commit | 903fee9a160f40126671719247578730ce3ad8d0 (patch) | |
tree | eb2d88c3385e1d285136b280d6bcabb01e103883 /util | |
parent | Merge branch 'master' of https://github.com/fosscord/fosscord-server (diff) | |
download | server-903fee9a160f40126671719247578730ce3ad8d0.tar.xz |
Categories skip most of the ALLOW_INVALID_CHANNEL_NAMES checks on discord.com ( they also trim whitespace )
Diffstat (limited to 'util')
-rw-r--r-- | util/src/entities/Channel.ts | 24 | ||||
-rw-r--r-- | util/src/util/InvisibleCharacters.ts | 2 |
2 files changed, 17 insertions, 9 deletions
diff --git a/util/src/entities/Channel.ts b/util/src/entities/Channel.ts index 98766a9d..bf72994f 100644 --- a/util/src/entities/Channel.ts +++ b/util/src/entities/Channel.ts @@ -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"; @@ -147,7 +147,7 @@ export class Channel extends BaseClass { orphanedRowAction: "delete", }) webhooks?: Webhook[]; - + // TODO: DM channel static async createChannel( channel: Partial<Channel>, @@ -173,12 +173,20 @@ export class Channel extends BaseClass { if (channel.name.includes(character)) 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) + // 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); - if (channel.name.charAt(0) === "-" || - channel.name.charAt(channel.name.length - 1) === "-") - throw new HTTPError("Channel name cannot start/end with dash.", 403) + if (channel.name.charAt(0) === "-" || + channel.name.charAt(channel.name.length - 1) === "-") + 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")) { @@ -297,7 +305,7 @@ export class Channel extends BaseClass { await emitEvent({ event: "CHANNEL_CREATE", data: channel_dto, user_id: creator_user_id }); } - if (recipients.length === 1) return channel_dto; + if (recipients.length === 1) return channel_dto; else return channel_dto.excludedRecipients([creator_user_id]); } diff --git a/util/src/util/InvisibleCharacters.ts b/util/src/util/InvisibleCharacters.ts index 2b014e14..a48cfab0 100644 --- a/util/src/util/InvisibleCharacters.ts +++ b/util/src/util/InvisibleCharacters.ts @@ -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 |