diff --git a/util/src/entities/Channel.ts b/util/src/entities/Channel.ts
index 69c08be7..f3c40c83 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";
@@ -149,7 +149,7 @@ export class Channel extends BaseClass {
orphanedRowAction: "delete",
})
webhooks?: Webhook[];
-
+
// TODO: DM channel
static async createChannel(
channel: Partial<Channel>,
@@ -175,12 +175,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")) {
@@ -299,7 +307,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/entities/Config.ts b/util/src/entities/Config.ts
index 063a4d4d..f77991a9 100644
--- a/util/src/entities/Config.ts
+++ b/util/src/entities/Config.ts
@@ -4,6 +4,7 @@ import crypto from "crypto";
import { Snowflake } from "../util/Snowflake";
import { SessionsReplace } from "..";
import { hostname } from "os";
+import { Rights } from "../util/Rights";
@Entity("config")
export class ConfigEntity extends BaseClassWithoutId {
@@ -120,6 +121,7 @@ export interface ConfigValue {
secret: string | null;
};
ipdataApiKey: string | null;
+ defaultRights: string;
};
login: {
requireCaptcha: boolean;
@@ -311,6 +313,33 @@ export const DefaultConfigOptions: ConfigValue = {
secret: null,
},
ipdataApiKey: "eca677b284b3bac29eb72f5e496aa9047f26543605efe99ff2ce35c9",
+ defaultRights: (
+ Rights.FLAGS.CREATE_CHANNELS +
+ Rights.FLAGS.CREATE_DMS +
+ Rights.FLAGS.CREATE_DM_GROUPS +
+ Rights.FLAGS.CREATE_GUILDS +
+ Rights.FLAGS.CREATE_INVITES +
+ Rights.FLAGS.CREATE_ROLES +
+ Rights.FLAGS.CREATE_TEMPLATES +
+ Rights.FLAGS.CREATE_WEBHOOKS +
+ Rights.FLAGS.JOIN_GUILDS +
+ Rights.FLAGS.PIN_MESSAGES +
+ Rights.FLAGS.SELF_ADD_REACTIONS +
+ Rights.FLAGS.SELF_DELETE_MESSAGES +
+ Rights.FLAGS.SELF_EDIT_MESSAGES +
+ Rights.FLAGS.SELF_EDIT_NAME +
+ Rights.FLAGS.SEND_MESSAGES +
+ Rights.FLAGS.USE_ACTIVITIES +
+ Rights.FLAGS.USE_VIDEO +
+ Rights.FLAGS.USE_VOICE +
+ Rights.FLAGS.INVITE_USERS +
+ Rights.FLAGS.SELF_DELETE_DISABLE +
+ Rights.FLAGS.DEBTABLE +
+ Rights.FLAGS.KICK_BAN_MEMBERS +
+ Rights.FLAGS.SELF_LEAVE_GROUPS +
+ Rights.FLAGS.SELF_ADD_DISCOVERABLE +
+ Rights.FLAGS.USE_ACHIEVEMENTS
+ ).toString()
},
login: {
requireCaptcha: false,
diff --git a/util/src/entities/User.ts b/util/src/entities/User.ts
index 9b1c494e..49a7fbc6 100644
--- a/util/src/entities/User.ts
+++ b/util/src/entities/User.ts
@@ -268,7 +268,7 @@ export class User extends BaseClass {
disabled: false,
deleted: false,
email: email,
- rights: "0", // TODO: grant rights correctly, as 0 actually stands for no rights at all
+ rights: Config.get().security.defaultRights,
nsfw_allowed: true, // TODO: depending on age
public_flags: "0",
flags: "0", // TODO: generate
diff --git a/util/src/util/Constants.ts b/util/src/util/Constants.ts
index a5d3fcd2..81a7165d 100644
--- a/util/src/util/Constants.ts
+++ b/util/src/util/Constants.ts
@@ -73,9 +73,13 @@ export const VoiceOPCodes = {
HEARTBEAT: 3,
SESSION_DESCRIPTION: 4,
SPEAKING: 5,
+ HEARTBEAT_ACK: 6,
+ RESUME: 7,
HELLO: 8,
- CLIENT_CONNECT: 12,
- CLIENT_DISCONNECT: 13,
+ RESUMED: 9,
+ CLIENT_CONNECT: 12, // incorrect, op 12 is probably used for video
+ CLIENT_DISCONNECT: 13, // incorrect
+ VERSION: 16, //not documented
};
export const Events = {
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
|