summary refs log tree commit diff
path: root/util/src/entities
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/util/entities/Application.ts (renamed from util/src/entities/Application.ts)115
-rw-r--r--src/util/entities/Attachment.ts (renamed from util/src/entities/Attachment.ts)0
-rw-r--r--src/util/entities/AuditLog.ts (renamed from util/src/entities/AuditLog.ts)0
-rw-r--r--src/util/entities/BackupCodes.ts (renamed from util/src/entities/BackupCodes.ts)16
-rw-r--r--src/util/entities/Ban.ts (renamed from util/src/entities/Ban.ts)0
-rw-r--r--src/util/entities/Categories.ts (renamed from util/src/entities/Categories.ts)0
-rw-r--r--src/util/entities/Channel.ts (renamed from util/src/entities/Channel.ts)71
-rw-r--r--src/util/entities/ClientRelease.ts (renamed from util/src/entities/ClientRelease.ts)0
-rw-r--r--src/util/entities/ConnectedAccount.ts (renamed from util/src/entities/ConnectedAccount.ts)0
-rw-r--r--src/util/entities/Emoji.ts (renamed from util/src/entities/Emoji.ts)0
-rw-r--r--src/util/entities/Encryption.ts (renamed from util/src/entities/Encryption.ts)2
-rw-r--r--src/util/entities/Group.ts (renamed from util/src/entities/Group.ts)0
-rw-r--r--src/util/entities/Guild.ts (renamed from util/src/entities/Guild.ts)39
-rw-r--r--src/util/entities/Invite.ts (renamed from util/src/entities/Invite.ts)15
-rw-r--r--src/util/entities/Member.ts (renamed from util/src/entities/Member.ts)44
-rw-r--r--src/util/entities/Message.ts (renamed from util/src/entities/Message.ts)1
-rw-r--r--src/util/entities/Migration.ts (renamed from util/src/entities/Migration.ts)0
-rw-r--r--src/util/entities/Note.ts (renamed from util/src/entities/Note.ts)0
-rw-r--r--src/util/entities/RateLimit.ts (renamed from util/src/entities/RateLimit.ts)0
-rw-r--r--src/util/entities/ReadState.ts (renamed from util/src/entities/ReadState.ts)0
-rw-r--r--src/util/entities/Recipient.ts (renamed from util/src/entities/Recipient.ts)0
-rw-r--r--src/util/entities/Relationship.ts (renamed from util/src/entities/Relationship.ts)0
-rw-r--r--src/util/entities/Role.ts (renamed from util/src/entities/Role.ts)0
-rw-r--r--src/util/entities/Session.ts (renamed from util/src/entities/Session.ts)0
-rw-r--r--src/util/entities/Sticker.ts (renamed from util/src/entities/Sticker.ts)0
-rw-r--r--src/util/entities/StickerPack.ts (renamed from util/src/entities/StickerPack.ts)0
-rw-r--r--src/util/entities/Team.ts (renamed from util/src/entities/Team.ts)0
-rw-r--r--src/util/entities/TeamMember.ts (renamed from util/src/entities/TeamMember.ts)0
-rw-r--r--src/util/entities/Template.ts (renamed from util/src/entities/Template.ts)0
-rw-r--r--src/util/entities/User.ts (renamed from util/src/entities/User.ts)193
-rw-r--r--src/util/entities/UserGroup.ts (renamed from util/src/entities/UserGroup.ts)0
-rw-r--r--src/util/entities/VoiceState.ts (renamed from util/src/entities/VoiceState.ts)0
-rw-r--r--src/util/entities/Webhook.ts (renamed from util/src/entities/Webhook.ts)0
-rw-r--r--src/util/entities/index.ts (renamed from util/src/entities/index.ts)1
-rw-r--r--util/src/entities/BaseClass.ts75
-rw-r--r--util/src/entities/Config.ts413
36 files changed, 235 insertions, 750 deletions
diff --git a/util/src/entities/Application.ts b/src/util/entities/Application.ts

index fab3d93f..103f8e84 100644 --- a/util/src/entities/Application.ts +++ b/src/util/entities/Application.ts
@@ -1,4 +1,4 @@ -import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm"; +import { Column, Entity, JoinColumn, ManyToOne, OneToOne, RelationId } from "typeorm"; import { BaseClass } from "./BaseClass"; import { Guild } from "./Guild"; import { Team } from "./Team"; @@ -8,21 +8,77 @@ import { User } from "./User"; export class Application extends BaseClass { @Column() name: string; - + @Column({ nullable: true }) icon?: string; - - @Column() + + @Column({ nullable: true }) description: string; - - @Column({ type: "simple-array", nullable: true }) - rpc_origins?: string[]; - + + @Column({ nullable: true }) + summary: string = ""; + + @Column({ type: "simple-json", nullable: true }) + type?: any; + @Column() - bot_public: boolean; - + hook: boolean = true; + + @Column() + bot_public?: boolean = true; + + @Column() + bot_require_code_grant?: boolean = false; + @Column() - bot_require_code_grant: boolean; + verify_key: string; + + @JoinColumn({ name: "owner_id" }) + @ManyToOne(() => User) + owner: User; + + @Column() + flags: number = 0; + + @Column({ type: "simple-array", nullable: true }) + redirect_uris: string[] = []; + + @Column({ nullable: true }) + rpc_application_state: number = 0; + + @Column({ nullable: true }) + store_application_state: number = 1; + + @Column({ nullable: true }) + verification_state: number = 1; + + @Column({ nullable: true }) + interactions_endpoint_url?: string; + + @Column({ nullable: true }) + integration_public: boolean = true; + + @Column({ nullable: true }) + integration_require_code_grant: boolean = false; + + @Column({ nullable: true }) + discoverability_state: number = 1; + + @Column({ nullable: true }) + discovery_eligibility_flags: number = 2240; + + @JoinColumn({ name: "bot_user_id" }) + @OneToOne(() => User) + bot?: User; + + @Column({ type: "simple-array", nullable: true }) + tags?: string[]; + + @Column({ nullable: true }) + cover_image?: string; // the application's default rich presence invite cover image hash + + @Column({ type: "simple-json", nullable: true }) + install_params?: {scopes: string[], permissions: string}; @Column({ nullable: true }) terms_of_service_url?: string; @@ -30,38 +86,29 @@ export class Application extends BaseClass { @Column({ nullable: true }) privacy_policy_url?: string; - @JoinColumn({ name: "owner_id" }) - @ManyToOne(() => User) - owner?: User; + //just for us - @Column({ nullable: true }) - summary?: string; + //@Column({ type: "simple-array", nullable: true }) + //rpc_origins?: string[]; + + //@JoinColumn({ name: "guild_id" }) + //@ManyToOne(() => Guild) + //guild?: Guild; // if this application is a game sold, this field will be the guild to which it has been linked - @Column() - verify_key: string; + //@Column({ nullable: true }) + //primary_sku_id?: string; // if this application is a game sold, this field will be the id of the "Game SKU" that is created, + + //@Column({ nullable: true }) + //slug?: string; // if this application is a game sold, this field will be the URL slug that links to the store page @JoinColumn({ name: "team_id" }) @ManyToOne(() => Team, { onDelete: "CASCADE", + nullable: true }) team?: Team; - @JoinColumn({ name: "guild_id" }) - @ManyToOne(() => Guild) - guild: Guild; // if this application is a game sold, this field will be the guild to which it has been linked - - @Column({ nullable: true }) - primary_sku_id?: string; // if this application is a game sold, this field will be the id of the "Game SKU" that is created, - - @Column({ nullable: true }) - slug?: string; // if this application is a game sold, this field will be the URL slug that links to the store page - - @Column({ nullable: true }) - cover_image?: string; // the application's default rich presence invite cover image hash - - @Column() - flags: string; // the application's public flags -} + } export interface ApplicationCommand { id: string; diff --git a/util/src/entities/Attachment.ts b/src/util/entities/Attachment.ts
index 7b4b17eb..7b4b17eb 100644 --- a/util/src/entities/Attachment.ts +++ b/src/util/entities/Attachment.ts
diff --git a/util/src/entities/AuditLog.ts b/src/util/entities/AuditLog.ts
index b003e7ba..b003e7ba 100644 --- a/util/src/entities/AuditLog.ts +++ b/src/util/entities/AuditLog.ts
diff --git a/util/src/entities/BackupCodes.ts b/src/util/entities/BackupCodes.ts
index d532a39a..9092c14e 100644 --- a/util/src/entities/BackupCodes.ts +++ b/src/util/entities/BackupCodes.ts
@@ -1,7 +1,6 @@ import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm"; import { BaseClass } from "./BaseClass"; import { User } from "./User"; -import crypto from "crypto"; @Entity("backup_codes") export class BackupCode extends BaseClass { @@ -17,19 +16,4 @@ export class BackupCode extends BaseClass { @Column() expired: boolean; -} - -export function generateMfaBackupCodes(user_id: string) { - let backup_codes: BackupCode[] = []; - for (let i = 0; i < 10; i++) { - const code = BackupCode.create({ - user: { id: user_id }, - code: crypto.randomBytes(4).toString("hex"), // 8 characters - consumed: false, - expired: false, - }); - backup_codes.push(code); - } - - return backup_codes; } \ No newline at end of file diff --git a/util/src/entities/Ban.ts b/src/util/entities/Ban.ts
index 9504bd8e..9504bd8e 100644 --- a/util/src/entities/Ban.ts +++ b/src/util/entities/Ban.ts
diff --git a/util/src/entities/Categories.ts b/src/util/entities/Categories.ts
index 81fbc303..81fbc303 100644 --- a/util/src/entities/Categories.ts +++ b/src/util/entities/Categories.ts
diff --git a/util/src/entities/Channel.ts b/src/util/entities/Channel.ts
index 69c08be7..a576d7af 100644 --- a/util/src/entities/Channel.ts +++ b/src/util/entities/Channel.ts
@@ -1,8 +1,9 @@ import { Column, Entity, JoinColumn, ManyToOne, OneToMany, RelationId } from "typeorm"; +import { OrmUtils } from "../util/imports/OrmUtils"; import { BaseClass } from "./BaseClass"; import { Guild } from "./Guild"; import { PublicUserProjection, User } from "./User"; -import { HTTPError } from "lambert-server"; +import { HTTPError } from "../util/imports/HTTPError"; import { containsAll, emitEvent, getPermission, Snowflake, trimSpecial, InvisibleCharacters } from "../util"; import { ChannelCreateEvent, ChannelRecipientRemoveEvent } from "../interfaces"; import { Recipient } from "./Recipient"; @@ -34,7 +35,7 @@ export enum ChannelType { KANBAN = 34, // confluence like kanban board VOICELESS_WHITEBOARD = 35, // whiteboard but without voice (whiteboard + voice is the same as stage) CUSTOM_START = 64, // start custom channel types from here - UNHANDLED = 255 // unhandled unowned pass-through channel type + UNHANDLED = 255, // unhandled unowned pass-through channel type } @Entity("channels") @@ -149,7 +150,14 @@ export class Channel extends BaseClass { orphanedRowAction: "delete", }) webhooks?: Webhook[]; + + @Column({ nullable: true }) + flags?: number = 0; + @Column({ nullable: true }) + default_thread_rate_limit_per_user?: number = 0; + + // TODO: DM channel static async createChannel( channel: Partial<Channel>, @@ -169,23 +177,21 @@ export class Channel extends BaseClass { } if (!opts?.skipNameChecks) { - const guild = await Guild.findOneOrFail({ id: channel.guild_id }); + const guild = await Guild.findOneOrFail({ where: { id: channel.guild_id } }); if (!guild.features.includes("ALLOW_INVALID_CHANNEL_NAMES") && channel.name) { - for (var character of InvisibleCharacters) + for (let character of InvisibleCharacters) 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) + 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); } if (!guild.features.includes("ALLOW_UNNAMED_CHANNELS")) { - if (!channel.name) - throw new HTTPError("Channel name cannot be empty.", 403); + if (!channel.name) throw new HTTPError("Channel name cannot be empty.", 403); } } @@ -194,7 +200,7 @@ export class Channel extends BaseClass { case ChannelType.GUILD_NEWS: case ChannelType.GUILD_VOICE: if (channel.parent_id && !opts?.skipExistsCheck) { - const exists = await Channel.findOneOrFail({ id: channel.parent_id }); + const exists = await Channel.findOneOrFail({ where: { id: channel.parent_id } }); if (!exists) throw new HTTPError("Parent id channel doesn't exist", 400); if (exists.guild_id !== channel.guild_id) throw new HTTPError("The category channel needs to be in the guild"); @@ -222,13 +228,13 @@ export class Channel extends BaseClass { }; await Promise.all([ - new Channel(channel).save(), + OrmUtils.mergeDeep(new Channel(), channel).save(), !opts?.skipEventEmit ? emitEvent({ - event: "CHANNEL_CREATE", - data: channel, - guild_id: channel.guild_id, - } as ChannelCreateEvent) + event: "CHANNEL_CREATE", + data: channel, + guild_id: channel.guild_id, + } as ChannelCreateEvent) : Promise.resolve(), ]); @@ -246,7 +252,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; @@ -263,7 +269,8 @@ export class Channel extends BaseClass { if (containsAll(re, channelRecipients)) { if (channel == null) { channel = ur.channel; - await ur.assign({ closed: false }).save(); + ur = OrmUtils.mergeDeep(ur, { closed: false }); + await ur.save(); } } } @@ -272,17 +279,21 @@ export class Channel extends BaseClass { if (channel == null) { name = trimSpecial(name); - channel = await new Channel({ - name, - type, - owner_id: type === ChannelType.DM ? undefined : null, // 1:1 DMs are ownerless in fosscord-server - created_at: new Date(), - last_message_id: null, - recipients: channelRecipients.map( - (x) => - new Recipient({ user_id: x, closed: !(type === ChannelType.GROUP_DM || x === creator_user_id) }) - ), - }).save(); + channel = await ( + OrmUtils.mergeDeep(new Channel(), { + name, + type, + owner_id: type === ChannelType.DM ? undefined : null, // 1:1 DMs are ownerless in fosscord-server + created_at: new Date(), + last_message_id: null, + recipients: channelRecipients.map((x) => + OrmUtils.mergeDeep(new Recipient(), { + user_id: x, + closed: !(type === ChannelType.GROUP_DM || x === creator_user_id), + }) + ), + }) as Channel + ).save(); } const channel_dto = await DmChannelDTO.from(channel); @@ -299,7 +310,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/ClientRelease.ts b/src/util/entities/ClientRelease.ts
index c5afd307..c5afd307 100644 --- a/util/src/entities/ClientRelease.ts +++ b/src/util/entities/ClientRelease.ts
diff --git a/util/src/entities/ConnectedAccount.ts b/src/util/entities/ConnectedAccount.ts
index 09ae30ab..09ae30ab 100644 --- a/util/src/entities/ConnectedAccount.ts +++ b/src/util/entities/ConnectedAccount.ts
diff --git a/util/src/entities/Emoji.ts b/src/util/entities/Emoji.ts
index a3615b7d..a3615b7d 100644 --- a/util/src/entities/Emoji.ts +++ b/src/util/entities/Emoji.ts
diff --git a/util/src/entities/Encryption.ts b/src/util/entities/Encryption.ts
index 3b82ff84..6b578d15 100644 --- a/util/src/entities/Encryption.ts +++ b/src/util/entities/Encryption.ts
@@ -2,7 +2,7 @@ import { Column, Entity, JoinColumn, ManyToOne, OneToMany, RelationId } from "ty import { BaseClass } from "./BaseClass"; import { Guild } from "./Guild"; import { PublicUserProjection, User } from "./User"; -import { HTTPError } from "lambert-server"; +import { HTTPError } from ".."; import { containsAll, emitEvent, getPermission, Snowflake, trimSpecial, InvisibleCharacters } from "../util"; import { BitField, BitFieldResolvable, BitFlag } from "../util/BitField"; import { Recipient } from "./Recipient"; diff --git a/util/src/entities/Group.ts b/src/util/entities/Group.ts
index b24d38cf..b24d38cf 100644 --- a/util/src/entities/Group.ts +++ b/src/util/entities/Group.ts
diff --git a/util/src/entities/Guild.ts b/src/util/entities/Guild.ts
index 70bb41c5..d146e577 100644 --- a/util/src/entities/Guild.ts +++ b/src/util/entities/Guild.ts
@@ -1,4 +1,5 @@ import { Column, Entity, JoinColumn, ManyToMany, ManyToOne, OneToMany, OneToOne, RelationId } from "typeorm"; +import { OrmUtils } from "../util/imports/OrmUtils"; import { Config, handleFile, Snowflake } from ".."; import { Ban } from "./Ban"; import { BaseClass } from "./BaseClass"; @@ -52,7 +53,7 @@ export class Guild extends BaseClass { afk_channel?: Channel; @Column({ nullable: true }) - afk_timeout?: number; + afk_timeout?: number = Config.get().defaults.guild.afkTimeout; // * commented out -> use owner instead // application id of the guild creator if it is bot-created @@ -70,7 +71,7 @@ export class Guild extends BaseClass { banner?: string; @Column({ nullable: true }) - default_message_notifications?: number; + default_message_notifications?: number = Config.get().defaults.guild.defaultMessageNotifications; @Column({ nullable: true }) description?: string; @@ -79,7 +80,7 @@ export class Guild extends BaseClass { discovery_splash?: string; @Column({ nullable: true }) - explicit_content_filter?: number; + explicit_content_filter?: number = Config.get().defaults.guild.explicitContentFilter; @Column({ type: "simple-array" }) features: string[]; //TODO use enum @@ -95,19 +96,19 @@ export class Guild extends BaseClass { large?: boolean; @Column({ nullable: true }) - max_members?: number; // e.g. default 100.000 + max_members?: number = Config.get().limits.guild.maxMembers; // e.g. default 100.000 @Column({ nullable: true }) - max_presences?: number; + max_presences?: number = Config.get().defaults.guild.maxPresences; @Column({ nullable: true }) - max_video_channel_users?: number; // ? default: 25, is this max 25 streaming or watching + max_video_channel_users?: number = Config.get().defaults.guild.maxVideoChannelUsers; // ? default: 25, is this max 25 streaming or watching @Column({ nullable: true }) - member_count?: number; + member_count?: number = 0; @Column({ nullable: true }) - presence_count?: number; // users online + presence_count?: number = 0; // users online @OneToMany(() => Member, (member: Member) => member.guild, { cascade: true, @@ -269,7 +270,7 @@ export class Guild extends BaseClass { @Column({ nullable: true }) nsfw?: boolean; - + // TODO: nested guilds @Column({ nullable: true }) parent?: string; @@ -277,6 +278,10 @@ export class Guild extends BaseClass { // only for developer portal permissions?: number; + //new guild settings, 11/08/2022: + @Column({ nullable: true }) + premium_progress_bar_enabled: boolean = false; + static async createGuild(body: { name?: string; icon?: string | null; @@ -285,7 +290,7 @@ export class Guild extends BaseClass { }) { const guild_id = Snowflake.generate(); - const guild = await new Guild({ + const guild: Guild = OrmUtils.mergeDeep(new Guild(), { name: body.name || "Fosscord", icon: await handleFile(`/icons/${guild_id}`, body.icon as string), region: Config.get().regions.default, @@ -316,11 +321,12 @@ export class Guild extends BaseClass { welcome_channels: [], }, widget_enabled: true, // NB: don't set it as false to prevent artificial restrictions - }).save(); + }); + await guild.save(); // we have to create the role _after_ the guild because else we would get a "SQLITE_CONSTRAINT: FOREIGN KEY constraint failed" error // TODO: make the @everyone a pseudorole that is dynamically generated at runtime so we can save storage - await new Role({ + let role: Role = OrmUtils.mergeDeep(new Role(), { id: guild_id, guild_id: guild_id, color: 0, @@ -332,8 +338,9 @@ export class Guild extends BaseClass { permissions: String("2251804225"), position: 0, icon: null, - unicode_emoji: null - }).save(); + unicode_emoji: null, + }); + await role.save(); if (!body.channels || !body.channels.length) body.channels = [{ id: "01", type: 0, name: "general" }]; @@ -346,9 +353,9 @@ export class Guild extends BaseClass { }); for (const channel of body.channels?.sort((a, b) => (a.parent_id ? 1 : -1))) { - var id = ids.get(channel.id) || Snowflake.generate(); + let id = ids.get(channel.id) || Snowflake.generate(); - var parent_id = ids.get(channel.parent_id); + let parent_id = ids.get(channel.parent_id); await Channel.createChannel({ ...channel, guild_id, id, parent_id }, body.owner_id, { keepId: true, diff --git a/util/src/entities/Invite.ts b/src/util/entities/Invite.ts
index 6ac64ddc..1e0ebe52 100644 --- a/util/src/entities/Invite.ts +++ b/src/util/entities/Invite.ts
@@ -4,19 +4,20 @@ import { BaseClassWithoutId } from "./BaseClass"; import { Channel } from "./Channel"; import { Guild } from "./Guild"; import { User } from "./User"; +import { random } from "@fosscord/api"; export const PublicInviteRelation = ["inviter", "guild", "channel"]; @Entity("invites") export class Invite extends BaseClassWithoutId { @PrimaryColumn() - code: string; + code: string = random(); @Column() - temporary: boolean; + temporary: boolean = true; @Column() - uses: number; + uses: number = 0; @Column() max_uses: number; @@ -25,7 +26,7 @@ export class Invite extends BaseClassWithoutId { max_age: number; @Column() - created_at: Date; + created_at: Date = new Date(); @Column() expires_at: Date; @@ -55,7 +56,9 @@ export class Invite extends BaseClassWithoutId { inviter_id: string; @JoinColumn({ name: "inviter_id" }) - @ManyToOne(() => User) + @ManyToOne(() => User, { + onDelete: "CASCADE" + }) inviter: User; @Column({ nullable: true }) @@ -75,7 +78,7 @@ export class Invite extends BaseClassWithoutId { vanity_url?: boolean; static async joinGuild(user_id: string, code: string) { - const invite = await Invite.findOneOrFail({ code }); + const invite = await Invite.findOneOrFail({ where: { code } }); if (invite.uses++ >= invite.max_uses && invite.max_uses !== 0) await Invite.delete({ code }); else await invite.save(); diff --git a/util/src/entities/Member.ts b/src/util/entities/Member.ts
index fe2d5590..baac58ed 100644 --- a/util/src/entities/Member.ts +++ b/src/util/entities/Member.ts
@@ -20,11 +20,12 @@ import { GuildMemberRemoveEvent, GuildMemberUpdateEvent, } from "../interfaces"; -import { HTTPError } from "lambert-server"; +import { HTTPError } from "../util/imports/HTTPError"; import { Role } from "./Role"; import { BaseClassWithoutId } from "./BaseClass"; import { Ban, PublicGuildRelations } from "."; import { DiscordApiErrors } from "../util/Constants"; +import { OrmUtils } from "../util/imports/OrmUtils"; export const MemberPrivateProjection: (keyof Member)[] = [ "id", @@ -70,7 +71,7 @@ export class Member extends BaseClassWithoutId { @Column({ nullable: true }) nick?: string; - + @JoinTable({ name: "member_roles", joinColumn: { name: "index", referencedColumnName: "index" }, @@ -85,8 +86,8 @@ export class Member extends BaseClassWithoutId { @Column() joined_at: Date; - @Column({ type: "bigint", nullable: true }) - premium_since?: number; + @Column({ nullable: true }) + premium_since?: Date; @Column() deaf: boolean; @@ -102,14 +103,14 @@ export class Member extends BaseClassWithoutId { @Column({ nullable: true }) last_message_id?: string; - + /** @JoinColumn({ name: "id" }) @ManyToOne(() => User, { onDelete: "DO NOTHING", // do not auto-kick force-joined members just because their joiners left the server }) **/ - @Column({ nullable: true}) + @Column({ nullable: true }) joined_by?: string; // TODO: add this when we have proper read receipts @@ -117,22 +118,24 @@ export class Member extends BaseClassWithoutId { // read_state: ReadState; static async IsInGuildOrFail(user_id: string, guild_id: string) { - if (await Member.count({ id: user_id, guild: { id: guild_id } })) return true; + if (await Member.count({ where: { id: user_id, guild: { id: guild_id } } })) return true; throw new HTTPError("You are not member of this guild", 403); } static async removeFromGuild(user_id: string, guild_id: string) { - const guild = await Guild.findOneOrFail({ select: ["owner_id"], where: { id: guild_id } }); + const guild = await Guild.findOneOrFail({ select: ["owner_id", "member_count"], where: { id: guild_id } }); if (guild.owner_id === user_id) throw new Error("The owner cannot be removed of the guild"); const member = await Member.findOneOrFail({ where: { id: user_id, guild_id }, relations: ["user"] }); // use promise all to execute all promises at the same time -> save time + //TODO: check for bugs + if (guild.member_count) guild.member_count--; return Promise.all([ Member.delete({ id: user_id, guild_id, }), - Guild.decrement({ id: guild_id }, "member_count", -1), + //Guild.decrement({ id: guild_id }, "member_count", -1), emitEvent({ event: "GUILD_DELETE", @@ -155,11 +158,11 @@ export class Member extends BaseClassWithoutId { Member.findOneOrFail({ where: { id: user_id, guild_id }, relations: ["user", "roles"], // we don't want to load the role objects just the ids - select: ["index", "roles.id"], + select: ["index"], }), Role.findOneOrFail({ where: { id: role_id, guild_id }, select: ["id"] }), ]); - member.roles.push(new Role({ id: role_id })); + member.roles.push(OrmUtils.mergeDeep(new Role(), { id: role_id })); await Promise.all([ member.save(), @@ -181,9 +184,9 @@ export class Member extends BaseClassWithoutId { Member.findOneOrFail({ where: { id: user_id, guild_id }, relations: ["user", "roles"], // we don't want to load the role objects just the ids - select: ["roles.id", "index"], + select: ["index"], }), - await Role.findOneOrFail({ id: role_id, guild_id }), + await Role.findOneOrFail({ where: { id: role_id, guild_id } }), ]); member.roles = member.roles.filter((x) => x.id == role_id); @@ -233,7 +236,7 @@ export class Member extends BaseClassWithoutId { throw DiscordApiErrors.USER_BANNED; } const { maxGuilds } = Config.get().limits.user; - const guild_count = await Member.count({ id: user_id }); + const guild_count = await Member.count({ where: { id: user_id } }); if (guild_count >= maxGuilds) { throw new HTTPError(`You are at the ${maxGuilds} server limit.`, 403); } @@ -245,7 +248,7 @@ export class Member extends BaseClassWithoutId { relations: PublicGuildRelations, }); - if (await Member.count({ id: user.id, guild: { id: guild_id } })) + if (await Member.count({ where: { id: user.id, guild: { id: guild_id } } })) throw new HTTPError("You are already a member of this guild", 400); const member = { @@ -254,16 +257,17 @@ export class Member extends BaseClassWithoutId { nick: undefined, roles: [guild_id], // @everyone role joined_at: new Date(), - premium_since: (new Date()).getTime(), + premium_since: null, deaf: false, mute: false, pending: false, }; - + //TODO: check for bugs + if (guild.member_count) guild.member_count++; await Promise.all([ - new Member({ + OrmUtils.mergeDeep(new Member(), { ...member, - roles: [new Role({ id: guild_id })], + roles: [OrmUtils.mergeDeep(new Role(), { id: guild_id })], // read_state: {}, settings: { channel_overrides: [], @@ -276,7 +280,7 @@ export class Member extends BaseClassWithoutId { }, // Member.save is needed because else the roles relations wouldn't be updated }).save(), - Guild.increment({ id: guild_id }, "member_count", 1), + //Guild.increment({ id: guild_id }, "member_count", 1), emitEvent({ event: "GUILD_MEMBER_ADD", data: { diff --git a/util/src/entities/Message.ts b/src/util/entities/Message.ts
index e18cf691..ba3d4f2d 100644 --- a/util/src/entities/Message.ts +++ b/src/util/entities/Message.ts
@@ -8,7 +8,6 @@ import { Column, CreateDateColumn, Entity, - FindConditions, Index, JoinColumn, JoinTable, diff --git a/util/src/entities/Migration.ts b/src/util/entities/Migration.ts
index 3f39ae72..3f39ae72 100644 --- a/util/src/entities/Migration.ts +++ b/src/util/entities/Migration.ts
diff --git a/util/src/entities/Note.ts b/src/util/entities/Note.ts
index 36017c5e..36017c5e 100644 --- a/util/src/entities/Note.ts +++ b/src/util/entities/Note.ts
diff --git a/util/src/entities/RateLimit.ts b/src/util/entities/RateLimit.ts
index f5916f6b..f5916f6b 100644 --- a/util/src/entities/RateLimit.ts +++ b/src/util/entities/RateLimit.ts
diff --git a/util/src/entities/ReadState.ts b/src/util/entities/ReadState.ts
index b915573b..b915573b 100644 --- a/util/src/entities/ReadState.ts +++ b/src/util/entities/ReadState.ts
diff --git a/util/src/entities/Recipient.ts b/src/util/entities/Recipient.ts
index a945f938..a945f938 100644 --- a/util/src/entities/Recipient.ts +++ b/src/util/entities/Recipient.ts
diff --git a/util/src/entities/Relationship.ts b/src/util/entities/Relationship.ts
index c3592c76..c3592c76 100644 --- a/util/src/entities/Relationship.ts +++ b/src/util/entities/Relationship.ts
diff --git a/util/src/entities/Role.ts b/src/util/entities/Role.ts
index 4b721b5b..4b721b5b 100644 --- a/util/src/entities/Role.ts +++ b/src/util/entities/Role.ts
diff --git a/util/src/entities/Session.ts b/src/util/entities/Session.ts
index 969efa89..969efa89 100644 --- a/util/src/entities/Session.ts +++ b/src/util/entities/Session.ts
diff --git a/util/src/entities/Sticker.ts b/src/util/entities/Sticker.ts
index 37bc6fbe..37bc6fbe 100644 --- a/util/src/entities/Sticker.ts +++ b/src/util/entities/Sticker.ts
diff --git a/util/src/entities/StickerPack.ts b/src/util/entities/StickerPack.ts
index ec8c69a2..ec8c69a2 100644 --- a/util/src/entities/StickerPack.ts +++ b/src/util/entities/StickerPack.ts
diff --git a/util/src/entities/Team.ts b/src/util/entities/Team.ts
index 22140b7f..22140b7f 100644 --- a/util/src/entities/Team.ts +++ b/src/util/entities/Team.ts
diff --git a/util/src/entities/TeamMember.ts b/src/util/entities/TeamMember.ts
index b726e1e8..b726e1e8 100644 --- a/util/src/entities/TeamMember.ts +++ b/src/util/entities/TeamMember.ts
diff --git a/util/src/entities/Template.ts b/src/util/entities/Template.ts
index 1d952283..1d952283 100644 --- a/util/src/entities/Template.ts +++ b/src/util/entities/Template.ts
diff --git a/util/src/entities/User.ts b/src/util/entities/User.ts
index 470398a5..5432f298 100644 --- a/util/src/entities/User.ts +++ b/src/util/entities/User.ts
@@ -1,11 +1,11 @@ -import { Column, Entity, FindOneOptions, JoinColumn, OneToMany } from "typeorm"; +import { Column, Entity, FindOneOptions, FindOptionsSelectByString, JoinColumn, OneToMany, OneToOne } from "typeorm"; +import { OrmUtils } from "../util/imports/OrmUtils"; import { BaseClass } from "./BaseClass"; import { BitField } from "../util/BitField"; import { Relationship } from "./Relationship"; import { ConnectedAccount } from "./ConnectedAccount"; import { Config, FieldErrors, Snowflake, trimSpecial } from ".."; -import { Member, Session } from "."; -import { Note } from "./Note"; +import { Member, Session, UserSettings } from "."; export enum PublicUserEnum { username, @@ -83,30 +83,30 @@ export class User extends BaseClass { phone?: string; // phone number of the user @Column({ select: false }) - desktop: boolean; // if the user has desktop app installed + desktop: boolean = false; // if the user has desktop app installed @Column({ select: false }) - mobile: boolean; // if the user has mobile app installed + mobile: boolean = false; // if the user has mobile app installed @Column() - premium: boolean; // if user bought individual premium - - @Column() - premium_type: number; // individual premium level + premium: boolean = Config.get().defaults.user.premium; // if user bought individual premium @Column() - bot: boolean; // if user is bot + premium_type: number = Config.get().defaults.user.premium_type; // individual premium level @Column() + bot: boolean = false; // if user is bot + + @Column({ nullable: true }) bio: string; // short description of the user (max 190 chars -> should be configurable) @Column() - system: boolean; // shouldn't be used, the api sends this field type true, if the generated message comes from a system generated author + system: boolean = false; // shouldn't be used, the api sends this field type true, if the generated message comes from a system generated author @Column({ select: false }) - nsfw_allowed: boolean; // if the user can do age-restricted actions (NSFW channels/guilds/commands) - - @Column({ select: false }) + nsfw_allowed: boolean = true; // if the user can do age-restricted actions (NSFW channels/guilds/commands) // TODO: depending on age + + @Column({ select: false, nullable: true }) mfa_enabled: boolean; // if multi factor authentication is enabled @Column({ select: false, nullable: true }) @@ -116,31 +116,31 @@ export class User extends BaseClass { totp_last_ticket?: string; @Column() - created_at: Date; // registration date + created_at: Date = new Date(); // registration date @Column({ nullable: true }) - premium_since: Date; // premium date + premium_since: Date = new Date(); // premium date @Column({ select: false }) - verified: boolean; // if the user is offically verified + verified: boolean = Config.get().defaults.user.verified; // if the user is offically verified @Column() - disabled: boolean; // if the account is disabled + disabled: boolean = false; // if the account is disabled @Column() - deleted: boolean; // if the user was deleted + deleted: boolean = false; // if the user was deleted @Column({ nullable: true, select: false }) email?: string; // email of the user @Column() - flags: string; // UserFlags + flags: string = "0"; // UserFlags // TODO: generate @Column() - public_flags: number; + public_flags: number = 0; @Column({ type: "bigint" }) - rights: string; // Rights + rights: string = Config.get().register.defaultRights; // Rights @OneToMany(() => Session, (session: Session) => session.user) sessions: Session[]; @@ -166,14 +166,30 @@ export class User extends BaseClass { }; @Column({ type: "simple-array", select: false }) - fingerprints: string[]; // array of fingerprints -> used to prevent multiple accounts + fingerprints: string[] = []; // array of fingerprints -> used to prevent multiple accounts - @Column({ type: "simple-json", select: false }) + + @OneToOne(()=> UserSettings, { + cascade: true, + orphanedRowAction: "delete", + eager: false + }) + @JoinColumn() settings: UserSettings; - + // workaround to prevent fossord-unaware clients from deleting settings not used by them @Column({ type: "simple-json", select: false }) - extended_settings: string; + extended_settings: string = "{}"; + + @Column({ type: "simple-json" }) + notes: { [key: string]: string } = {}; //key is ID of user + + async save(): Promise<any> { + if(!this.settings) this.settings = new UserSettings(); + this.settings.id = this.id; + //await this.settings.save(); + return super.save(); + } toPublicUser() { const user: any = {}; @@ -184,19 +200,17 @@ export class User extends BaseClass { } static async getPublicUser(user_id: string, opts?: FindOneOptions<User>) { - return await User.findOneOrFail( - { id: user_id }, - { - ...opts, - select: [...PublicUserProjection, ...(opts?.select || [])], - } - ); + return await User.findOneOrFail({ + where: { id: user_id }, + select: [...PublicUserProjection, ...((opts?.select as FindOptionsSelectByString<User>) || [])], + ...opts, + }); } - private static async generateDiscriminator(username: string): Promise<string | undefined> { + public static async generateDiscriminator(username: string): Promise<string | undefined> { if (Config.get().register.incrementingDiscriminators) { // discriminator will be incrementally generated - + // First we need to figure out the currently highest discrimnator for the given username and then increment it const users = await User.find({ where: { username }, select: ["discriminator"] }); const highestDiscriminator = Math.max(0, ...users.map((u) => Number(u.discriminator))); @@ -244,7 +258,7 @@ export class User extends BaseClass { throw FieldErrors({ username: { code: "USERNAME_TOO_MANY_USERS", - message: req.t("auth:register.USERNAME_TOO_MANY_USERS"), + message: req?.t("auth:register.USERNAME_TOO_MANY_USERS"), }, }); } @@ -252,40 +266,22 @@ export class User extends BaseClass { // TODO: save date_of_birth // appearently discord doesn't save the date of birth and just calculate if nsfw is allowed // if nsfw_allowed is null/undefined it'll require date_of_birth to set it to true/false - const language = req.language === "en" ? "en-US" : req.language || "en-US"; + const language = req?.language === "en" ? "en-US" : req?.language || "en-US"; - const user = new User({ - created_at: new Date(), + const user = OrmUtils.mergeDeep(new User(), { + //required: username: username, discriminator, id: Snowflake.generate(), - bot: false, - system: false, - premium_since: new Date(), - desktop: false, - mobile: false, - premium: true, - premium_type: 2, - bio: "", - mfa_enabled: false, - verified: true, - disabled: false, - deleted: false, email: email, - rights: "0", // TODO: grant rights correctly, as 0 actually stands for no rights at all - nsfw_allowed: true, // TODO: depending on age - public_flags: "0", - flags: "0", // TODO: generate data: { hash: password, valid_tokens_since: new Date(), }, - settings: { ...defaultSettings, locale: language }, - extended_settings: {}, - fingerprints: [], - notes: {}, + settings: { ...new UserSettings(), locale: language } }); + //await (user.settings as UserSettings).save(); await user.save(); setImmediate(async () => { @@ -300,85 +296,6 @@ export class User extends BaseClass { } } -export const defaultSettings: UserSettings = { - afk_timeout: 3600, - allow_accessibility_detection: true, - animate_emoji: true, - animate_stickers: 0, - contact_sync_enabled: false, - convert_emoticons: false, - custom_status: null, - default_guilds_restricted: false, - detect_platform_accounts: false, - developer_mode: true, - disable_games_tab: true, - enable_tts_command: false, - explicit_content_filter: 0, - friend_source_flags: { all: true }, - gateway_connected: false, - gif_auto_play: true, - guild_folders: [], - guild_positions: [], - inline_attachment_media: true, - inline_embed_media: true, - locale: "en-US", - message_display_compact: true, - native_phone_integration_enabled: true, - render_embeds: true, - render_reactions: true, - restricted_guilds: [], - show_current_game: true, - status: "online", - stream_notifications_enabled: false, - theme: "dark", - timezone_offset: 0, // TODO: timezone from request -}; - -export interface UserSettings { - afk_timeout: number; - allow_accessibility_detection: boolean; - animate_emoji: boolean; - animate_stickers: number; - contact_sync_enabled: boolean; - convert_emoticons: boolean; - custom_status: { - emoji_id?: string; - emoji_name?: string; - expires_at?: number; - text?: string; - } | null; - default_guilds_restricted: boolean; - detect_platform_accounts: boolean; - developer_mode: boolean; - disable_games_tab: boolean; - enable_tts_command: boolean; - explicit_content_filter: number; - friend_source_flags: { all: boolean }; - gateway_connected: boolean; - gif_auto_play: boolean; - // every top guild is displayed as a "folder" - guild_folders: { - color: number; - guild_ids: string[]; - id: number; - name: string; - }[]; - guild_positions: string[]; // guild ids ordered by position - inline_attachment_media: boolean; - inline_embed_media: boolean; - locale: string; // en_US - message_display_compact: boolean; - native_phone_integration_enabled: boolean; - render_embeds: boolean; - render_reactions: boolean; - restricted_guilds: string[]; - show_current_game: boolean; - status: "online" | "offline" | "dnd" | "idle" | "invisible"; - stream_notifications_enabled: boolean; - theme: "dark" | "white"; // dark - timezone_offset: number; // e.g -60 -} - export const CUSTOM_USER_FLAG_OFFSET = BigInt(1) << BigInt(32); export class UserFlags extends BitField { diff --git a/util/src/entities/UserGroup.ts b/src/util/entities/UserGroup.ts
index 709b9d0b..709b9d0b 100644 --- a/util/src/entities/UserGroup.ts +++ b/src/util/entities/UserGroup.ts
diff --git a/util/src/entities/VoiceState.ts b/src/util/entities/VoiceState.ts
index 75748a01..75748a01 100644 --- a/util/src/entities/VoiceState.ts +++ b/src/util/entities/VoiceState.ts
diff --git a/util/src/entities/Webhook.ts b/src/util/entities/Webhook.ts
index 89538417..89538417 100644 --- a/util/src/entities/Webhook.ts +++ b/src/util/entities/Webhook.ts
diff --git a/util/src/entities/index.ts b/src/util/entities/index.ts
index c439a4b7..c6f12022 100644 --- a/util/src/entities/index.ts +++ b/src/util/entities/index.ts
@@ -30,3 +30,4 @@ export * from "./Webhook"; export * from "./ClientRelease"; export * from "./BackupCodes"; export * from "./Note"; +export * from "./UserSettings"; diff --git a/util/src/entities/BaseClass.ts b/util/src/entities/BaseClass.ts deleted file mode 100644
index aabca016..00000000 --- a/util/src/entities/BaseClass.ts +++ /dev/null
@@ -1,75 +0,0 @@ -import "reflect-metadata"; -import { BaseEntity, EntityMetadata, FindConditions, ObjectIdColumn, PrimaryColumn } from "typeorm"; -import { Snowflake } from "../util/Snowflake"; -import "missing-native-js-functions"; - -export class BaseClassWithoutId extends BaseEntity { - constructor(props?: any) { - super(); - this.assign(props); - } - - private get construct(): any { - return this.constructor; - } - - private get metadata() { - return this.construct.getRepository().metadata as EntityMetadata; - } - - assign(props: any = {}) { - delete props.opts; - delete props.props; - - const properties = new Set( - this.metadata.columns - .map((x: any) => x.propertyName) - .concat(this.metadata.relations.map((x) => x.propertyName)) - ); - // will not include relational properties - - for (const key in props) { - if (!properties.has(key)) continue; - // @ts-ignore - const setter = this[`set${key.capitalize()}`]; // use setter function if it exists - - if (setter) { - setter.call(this, props[key]); - } else { - // @ts-ignore - this[key] = props[key]; - } - } - } - - toJSON(): any { - return Object.fromEntries( - this.metadata.columns // @ts-ignore - .map((x) => [x.propertyName, this[x.propertyName]]) // @ts-ignore - .concat(this.metadata.relations.map((x) => [x.propertyName, this[x.propertyName]])) - ); - } - - static increment<T extends BaseClass>(conditions: FindConditions<T>, propertyPath: string, value: number | string) { - const repository = this.getRepository(); - return repository.increment(conditions as T, propertyPath, value); - } - - static decrement<T extends BaseClass>(conditions: FindConditions<T>, propertyPath: string, value: number | string) { - const repository = this.getRepository(); - return repository.decrement(conditions as T, propertyPath, value); - } -} - -export const PrimaryIdColumn = process.env.DATABASE?.startsWith("mongodb") ? ObjectIdColumn : PrimaryColumn; - -export class BaseClass extends BaseClassWithoutId { - @PrimaryIdColumn() - id: string; - - assign(props: any = {}) { - super.assign(props); - if (!this.id) this.id = Snowflake.generate(); - return this; - } -} diff --git a/util/src/entities/Config.ts b/util/src/entities/Config.ts deleted file mode 100644
index c84ea4aa..00000000 --- a/util/src/entities/Config.ts +++ /dev/null
@@ -1,413 +0,0 @@ -import { Column, Entity } from "typeorm"; -import { BaseClassWithoutId, PrimaryIdColumn } from "./BaseClass"; -import crypto from "crypto"; -import { Snowflake } from "../util/Snowflake"; -import { SessionsReplace } from ".."; -import { hostname } from "os"; - -@Entity("config") -export class ConfigEntity extends BaseClassWithoutId { - @PrimaryIdColumn() - key: string; - - @Column({ type: "simple-json", nullable: true }) - value: number | boolean | null | string | undefined; -} - -export interface RateLimitOptions { - bot?: number; - count: number; - window: number; - onyIp?: boolean; -} - -export interface Region { - id: string; - name: string; - endpoint: string; - location?: { - latitude: number; - longitude: number; - }; - vip: boolean; - custom: boolean; - deprecated: boolean; -} - -export interface KafkaBroker { - ip: string; - port: number; -} - -export interface ConfigValue { - gateway: { - endpointClient: string | null; - endpointPrivate: string | null; - endpointPublic: string | null; - }; - cdn: { - endpointClient: string | null; - endpointPublic: string | null; - endpointPrivate: string | null; - }; - api: { - defaultVersion: string; - activeVersions: string[]; - useFosscordEnhancements: boolean; - }; - general: { - instanceName: string; - instanceDescription: string | null; - frontPage: string | null; - tosPage: string | null; - correspondenceEmail: string | null; - correspondenceUserID: string | null; - image: string | null; - instanceId: string; - }; - limits: { - user: { - maxGuilds: number; - maxUsername: number; - maxFriends: number; - }; - guild: { - maxRoles: number; - maxEmojis: number; - maxMembers: number; - maxChannels: number; - maxChannelsInCategory: number; - hideOfflineMember: number; - }; - message: { - maxCharacters: number; - maxTTSCharacters: number; - maxReactions: number; - maxAttachmentSize: number; - maxBulkDelete: number; - maxEmbedDownloadSize: number; - }; - channel: { - maxPins: number; - maxTopic: number; - maxWebhooks: number; - }; - rate: { - disabled: boolean; - ip: Omit<RateLimitOptions, "bot_count">; - global: RateLimitOptions; - error: RateLimitOptions; - routes: { - guild: RateLimitOptions; - webhook: RateLimitOptions; - channel: RateLimitOptions; - auth: { - login: RateLimitOptions; - register: RateLimitOptions; - }; - // TODO: rate limit configuration for all routes - }; - }; - }; - security: { - autoUpdate: boolean | number; - requestSignature: string; - jwtSecret: string; - forwadedFor: string | null; // header to get the real user ip address - captcha: { - enabled: boolean; - service: "recaptcha" | "hcaptcha" | null; // TODO: hcaptcha, custom - sitekey: string | null; - secret: string | null; - }; - ipdataApiKey: string | null; - twoFactor: { - generateBackupCodes: boolean; - }; - }; - login: { - requireCaptcha: boolean; - }; - register: { - email: { - required: boolean; - allowlist: boolean; - blocklist: boolean; - domains: string[]; - }; - dateOfBirth: { - required: boolean; - minimum: number; // in years - }; - disabled: boolean; - requireCaptcha: boolean; - requireInvite: boolean; - guestsRequireInvite: boolean; - allowNewRegistration: boolean; - allowMultipleAccounts: boolean; - blockProxies: boolean; - password: { - required: boolean; - minLength: number; - minNumbers: number; - minUpperCase: number; - minSymbols: number; - }; - incrementingDiscriminators: boolean; // random otherwise - }; - regions: { - default: string; - useDefaultAsOptimal: boolean; - available: Region[]; - }; - guild: { - discovery: { - showAllGuilds: boolean; - useRecommendation: boolean; // TODO: Recommendation, privacy concern? - offset: number; - limit: number; - }; - autoJoin: { - enabled: boolean; - guilds: string[]; - canLeave: boolean; - }; - }; - gif: { - enabled: boolean; - provider: "tenor"; // more coming soon - apiKey?: string; - }; - rabbitmq: { - host: string | null; - }; - kafka: { - brokers: KafkaBroker[] | null; - }; - templates: { - enabled: Boolean; - allowTemplateCreation: Boolean; - allowDiscordTemplates: Boolean; - allowRaws: Boolean; - }, - client: { - useTestClient: Boolean; - releases: { - useLocalRelease: Boolean; //TODO - upstreamVersion: string; - } - }, - metrics: { - timeout: number; - }, - sentry: { - enabled: boolean; - endpoint: string; - traceSampleRate: number; - environment: string; - } -} - -export const DefaultConfigOptions: ConfigValue = { - gateway: { - endpointClient: null, - endpointPrivate: null, - endpointPublic: null, - }, - cdn: { - endpointClient: null, - endpointPrivate: null, - endpointPublic: null, - }, - api: { - defaultVersion: "9", - activeVersions: ["6", "7", "8", "9"], - useFosscordEnhancements: true, - }, - general: { - instanceName: "Fosscord Instance", - instanceDescription: "This is a Fosscord instance made in pre-release days", - frontPage: null, - tosPage: null, - correspondenceEmail: "noreply@localhost.local", - correspondenceUserID: null, - image: null, - instanceId: Snowflake.generate(), - }, - limits: { - user: { - maxGuilds: 1048576, - maxUsername: 127, - maxFriends: 5000, - }, - guild: { - maxRoles: 1000, - maxEmojis: 2000, - maxMembers: 25000000, - maxChannels: 65535, - maxChannelsInCategory: 65535, - hideOfflineMember: 3, - }, - message: { - maxCharacters: 1048576, - maxTTSCharacters: 160, - maxReactions: 2048, - maxAttachmentSize: 1024 * 1024 * 1024, - maxEmbedDownloadSize: 1024 * 1024 * 5, - maxBulkDelete: 1000, - }, - channel: { - maxPins: 500, - maxTopic: 1024, - maxWebhooks: 100, - }, - rate: { - disabled: true, - ip: { - count: 500, - window: 5, - }, - global: { - count: 250, - window: 5, - }, - error: { - count: 10, - window: 5, - }, - routes: { - guild: { - count: 5, - window: 5, - }, - webhook: { - count: 10, - window: 5, - }, - channel: { - count: 10, - window: 5, - }, - auth: { - login: { - count: 5, - window: 60, - }, - register: { - count: 2, - window: 60 * 60 * 12, - }, - }, - }, - }, - }, - security: { - autoUpdate: true, - requestSignature: crypto.randomBytes(32).toString("base64"), - jwtSecret: crypto.randomBytes(256).toString("base64"), - forwadedFor: null, - // forwadedFor: "X-Forwarded-For" // nginx/reverse proxy - // forwadedFor: "CF-Connecting-IP" // cloudflare: - captcha: { - enabled: false, - service: null, - sitekey: null, - secret: null, - }, - ipdataApiKey: "eca677b284b3bac29eb72f5e496aa9047f26543605efe99ff2ce35c9", - twoFactor: { - generateBackupCodes: true, - }, - }, - login: { - requireCaptcha: false, - }, - register: { - email: { - required: false, - allowlist: false, - blocklist: true, - domains: [], // TODO: efficiently save domain blocklist in database - // domains: fs.readFileSync(__dirname + "/blockedEmailDomains.txt", { encoding: "utf8" }).split("\n"), - }, - dateOfBirth: { - required: true, - minimum: 13, - }, - disabled: false, - requireInvite: false, - guestsRequireInvite: true, - requireCaptcha: true, - allowNewRegistration: true, - allowMultipleAccounts: true, - blockProxies: true, - password: { - required: false, - minLength: 8, - minNumbers: 2, - minUpperCase: 2, - minSymbols: 0, - }, - incrementingDiscriminators: false, - }, - regions: { - default: "fosscord", - useDefaultAsOptimal: true, - available: [ - { - id: "fosscord", - name: "Fosscord", - endpoint: "127.0.0.1:3004", - vip: false, - custom: false, - deprecated: false, - }, - ], - }, - guild: { - discovery: { - showAllGuilds: false, - useRecommendation: false, - offset: 0, - limit: 24, - }, - autoJoin: { - enabled: true, - canLeave: true, - guilds: [], - }, - }, - gif: { - enabled: true, - provider: "tenor", - apiKey: "LIVDSRZULELA", - }, - rabbitmq: { - host: null, - }, - kafka: { - brokers: null, - }, - templates: { - enabled: true, - allowTemplateCreation: true, - allowDiscordTemplates: true, - allowRaws: false - }, - client: { - useTestClient: true, - releases: { - useLocalRelease: true, - upstreamVersion: "0.0.264" - } - }, - metrics: { - timeout: 30000 - }, - sentry: { - enabled: false, - endpoint: "https://05e8e3d005f34b7d97e920ae5870a5e5@sentry.thearcanebrony.net/6", - traceSampleRate: 1.0, - environment: hostname() - } -};