summary refs log tree commit diff
path: root/util/src/entities
diff options
context:
space:
mode:
Diffstat (limited to 'util/src/entities')
-rw-r--r--util/src/entities/Channel.ts27
-rw-r--r--util/src/entities/Config.ts73
-rw-r--r--util/src/entities/Guild.ts2
-rw-r--r--util/src/entities/Message.ts2
-rw-r--r--util/src/entities/User.ts4
5 files changed, 75 insertions, 33 deletions
diff --git a/util/src/entities/Channel.ts b/util/src/entities/Channel.ts

index 69c08be7..3e8cd5ef 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")) { @@ -237,6 +245,7 @@ export class Channel extends BaseClass { static async createDMChannel(recipients: string[], creator_user_id: string, name?: string) { recipients = recipients.unique().filter((x) => x !== creator_user_id); + //@ts-ignore some typeorm typescript issue const otherRecipientsUsers = await User.find({ where: recipients.map((x) => ({ id: x })) }); // TODO: check config for max number of recipients @@ -246,7 +255,7 @@ export class Channel extends BaseClass { } **/ - const type = recipients.length > 1 ? ChannelType.DM : ChannelType.GROUP_DM; + const type = recipients.length > 1 ? ChannelType.GROUP_DM : ChannelType.DM; let channel = null; @@ -299,7 +308,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..9eca84ad 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 { @@ -85,6 +86,7 @@ export interface ConfigValue { maxReactions: number; maxAttachmentSize: number; maxBulkDelete: number; + maxEmbedDownloadSize: number; }; channel: { maxPins: number; @@ -120,6 +122,7 @@ export interface ConfigValue { secret: string | null; }; ipdataApiKey: string | null; + defaultRights: string; }; login: { requireCaptcha: boolean; @@ -191,7 +194,7 @@ export interface ConfigValue { releases: { useLocalRelease: Boolean; //TODO upstreamVersion: string; - } + }; }, metrics: { timeout: number; @@ -201,7 +204,7 @@ export interface ConfigValue { endpoint: string; traceSampleRate: number; environment: string; - } + }; } export const DefaultConfigOptions: ConfigValue = { @@ -232,29 +235,30 @@ export const DefaultConfigOptions: ConfigValue = { }, limits: { user: { - maxGuilds: 100, - maxUsername: 32, - maxFriends: 1000, + maxGuilds: 1048576, + maxUsername: 127, + maxFriends: 5000, }, guild: { - maxRoles: 250, - maxEmojis: 50, // TODO: max emojis per guild per nitro level - maxMembers: 250000, - maxChannels: 500, - maxChannelsInCategory: 50, - hideOfflineMember: 1000, + maxRoles: 1000, + maxEmojis: 2000, + maxMembers: 25000000, + maxChannels: 65535, + maxChannelsInCategory: 65535, + hideOfflineMember: 3, }, message: { - maxCharacters: 2000, - maxTTSCharacters: 200, - maxReactions: 20, - maxAttachmentSize: 8388608, - maxBulkDelete: 100, + maxCharacters: 1048576, + maxTTSCharacters: 160, + maxReactions: 2048, + maxAttachmentSize: 1024 * 1024 * 1024, + maxEmbedDownloadSize: 1024 * 1024 * 5, + maxBulkDelete: 1000, }, channel: { - maxPins: 50, + maxPins: 500, maxTopic: 1024, - maxWebhooks: 10, + maxWebhooks: 100, }, rate: { disabled: true, @@ -263,9 +267,8 @@ export const DefaultConfigOptions: ConfigValue = { window: 5, }, global: { - count: 20, + count: 250, window: 5, - bot: 250, }, error: { count: 10, @@ -311,6 +314,36 @@ 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 + + Rights.FLAGS.MANAGE_GUILDS + + Rights.FLAGS.MANAGE_MESSAGES + + Rights.FLAGS.USE_MASS_INVITES + ).toString() }, login: { requireCaptcha: false, diff --git a/util/src/entities/Guild.ts b/util/src/entities/Guild.ts
index 70bb41c5..ef31a237 100644 --- a/util/src/entities/Guild.ts +++ b/util/src/entities/Guild.ts
@@ -248,7 +248,7 @@ export class Guild extends BaseClass { welcome_channels: { description: string; emoji_id?: string; - emoji_name: string; + emoji_name?: string; channel_id: string; }[]; }; diff --git a/util/src/entities/Message.ts b/util/src/entities/Message.ts
index e18cf691..013e92a9 100644 --- a/util/src/entities/Message.ts +++ b/util/src/entities/Message.ts
@@ -114,7 +114,7 @@ export class Message extends BaseClass { @ManyToOne(() => Application) application?: Application; - @Column({ nullable: true }) + @Column({ nullable: true, type: "longtext" }) content?: string; @Column() diff --git a/util/src/entities/User.ts b/util/src/entities/User.ts
index 9b1c494e..4035dfe9 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 @@ -318,7 +318,7 @@ export const defaultSettings: UserSettings = { inline_attachment_media: true, inline_embed_media: true, locale: "en-US", - message_display_compact: true, + message_display_compact: false, native_phone_integration_enabled: true, render_embeds: true, render_reactions: true,