diff options
-rw-r--r-- | api/src/routes/guilds/#guild_id/index.ts | 16 | ||||
-rw-r--r-- | api/src/routes/guilds/index.ts | 2 | ||||
-rw-r--r-- | api/src/schema/Guild.ts | 2 | ||||
-rw-r--r-- | gateway/src/opcodes/Identify.ts | 7 | ||||
-rw-r--r-- | util/src/entities/Guild.ts | 14 | ||||
-rw-r--r-- | util/src/entities/Member.ts | 10 | ||||
-rw-r--r-- | util/src/entities/Template.ts | 4 | ||||
-rw-r--r-- | util/src/interfaces/Event.ts | 7 |
8 files changed, 34 insertions, 28 deletions
diff --git a/api/src/routes/guilds/#guild_id/index.ts b/api/src/routes/guilds/#guild_id/index.ts index 567898dd..9d302a48 100644 --- a/api/src/routes/guilds/#guild_id/index.ts +++ b/api/src/routes/guilds/#guild_id/index.ts @@ -37,12 +37,22 @@ router.patch("/", check(GuildUpdateSchema), async (req: Request, res: Response) if (body.banner) body.banner = await handleFile(`/banners/${guild_id}`, body.banner); if (body.splash) body.splash = await handleFile(`/splashes/${guild_id}`, body.splash); - const guild = await Guild.findOneOrFail({ id: guild_id }); + var guild = await Guild.findOneOrFail({ + where: { id: guild_id }, + relations: ["emojis", "roles", "stickers"] + }); + // TODO: check if body ids are valid guild.assign(body); - await Promise.all([guild.save(), emitEvent({ event: "GUILD_UPDATE", data: guild, guild_id } as GuildUpdateEvent)]); + const data = guild.toJSON(); + // TODO: guild hashes + // TODO: fix vanity_url_code, template_id + delete data.vanity_url_code; + delete data.template_id; - return res.json(guild); + await Promise.all([guild.save(), emitEvent({ event: "GUILD_UPDATE", data, guild_id } as GuildUpdateEvent)]); + + return res.json(data); }); export default router; diff --git a/api/src/routes/guilds/index.ts b/api/src/routes/guilds/index.ts index b4f6b3d2..7c0b7abc 100644 --- a/api/src/routes/guilds/index.ts +++ b/api/src/routes/guilds/index.ts @@ -40,6 +40,8 @@ router.post("/", check(GuildCreateSchema), async (req: Request, res: Response) = premium_tier: 0, system_channel_flags: 0, unavailable: false, + nsfw: false, + nsfw_level: 0, verification_level: 0, welcome_screen: { enabled: false, diff --git a/api/src/schema/Guild.ts b/api/src/schema/Guild.ts index 0f9fd884..7c96905e 100644 --- a/api/src/schema/Guild.ts +++ b/api/src/schema/Guild.ts @@ -33,7 +33,7 @@ export const GuildUpdateSchema = { $icon: String, $verification_level: Number, $default_message_notifications: Number, - $system_channel_flags: String, + $system_channel_flags: Number, $system_channel_id: String, $explicit_content_filter: Number, $public_updates_channel_id: String, diff --git a/gateway/src/opcodes/Identify.ts b/gateway/src/opcodes/Identify.ts index 2b2c31c5..cd09653f 100644 --- a/gateway/src/opcodes/Identify.ts +++ b/gateway/src/opcodes/Identify.ts @@ -138,12 +138,7 @@ export async function onIdentify(this: WebSocket, data: Payload) { // @ts-ignore guilds: guilds.map((x) => { // @ts-ignore - x.guild_hashes = { - channels: { omitted: false, hash: "y4PV2fZ0gmo" }, - metadata: { omitted: false, hash: "bs1/ckvud3Y" }, - roles: { omitted: false, hash: "SxA+c5CaYpo" }, - version: 1, - }; + x.guild_hashes = {}; return x; }), guild_experiments: [], // TODO diff --git a/util/src/entities/Guild.ts b/util/src/entities/Guild.ts index 032a9415..434699ac 100644 --- a/util/src/entities/Guild.ts +++ b/util/src/entities/Guild.ts @@ -17,6 +17,8 @@ import { Webhook } from "./Webhook"; // TODO: stage_instances // TODO: threads +export const PublicGuildRelations = ["channels", "emojis", "members", "roles", "stickers", "voice_states"]; + @Entity("guilds") export class Guild extends BaseClass { @Column({ nullable: true }) @@ -91,9 +93,9 @@ export class Guild extends BaseClass { @Column({ nullable: true }) @RelationId((guild: Guild) => guild.template) - template_id: string; + template_id?: string; - @JoinColumn({ name: "template_id" }) + @JoinColumn({ name: "template_id", referencedColumnName: "id" }) @ManyToOne(() => Template) template: Template; @@ -127,7 +129,7 @@ export class Guild extends BaseClass { @RelationId((guild: Guild) => guild.owner) owner_id: string; - @JoinColumn([{ name: "owner_id", referencedColumnName: "id" }]) + @JoinColumn({ name: "owner_id", referencedColumnName: "id" }) @ManyToOne(() => User) owner: User; @@ -209,4 +211,10 @@ export class Guild extends BaseClass { @Column({ nullable: true }) widget_enabled?: boolean; + + @Column({ nullable: true }) + nsfw_level?: number; + + @Column({ nullable: true }) + nsfw?: boolean; } diff --git a/util/src/entities/Member.ts b/util/src/entities/Member.ts index 76febb50..4cdd3421 100644 --- a/util/src/entities/Member.ts +++ b/util/src/entities/Member.ts @@ -26,6 +26,7 @@ import { HTTPError } from "lambert-server"; import { Role } from "./Role"; import { Snowflake } from "../util/Snowflake"; import { BaseClassWithoutId } from "./BaseClass"; +import { PublicGuildRelations } from "."; @Entity("members") @Index(["id", "guild_id"], { unique: true }) @@ -209,7 +210,7 @@ export class Member extends BaseClassWithoutId { where: { id: guild_id, }, - relations: ["channels", "emojis", "members", "roles", "stickers", "voice_states"], + relations: PublicGuildRelations, }); if (await Member.count({ id: user.id, guild: { id: guild_id } })) @@ -259,12 +260,7 @@ export class Member extends BaseClassWithoutId { ...guild, members: [...guild.members, { ...member, user }], member_count: (guild.member_count || 0) + 1, - guild_hashes: { - channels: { omitted: false, hash: "nkMQJ5nl5Cg" }, - metadata: { omitted: false, hash: "+5ybMfcb8iw" }, - roles: { omitted: false, hash: "Idhc6P9ktfM" }, - version: 1, - }, + guild_hashes: {}, guild_scheduled_events: [], joined_at: member.joined_at, presences: [], diff --git a/util/src/entities/Template.ts b/util/src/entities/Template.ts index 76f77ba6..c9c32f42 100644 --- a/util/src/entities/Template.ts +++ b/util/src/entities/Template.ts @@ -1,11 +1,11 @@ -import { Column, Entity, JoinColumn, ManyToOne, PrimaryColumn, RelationId } from "typeorm"; +import { Column, Entity, Index, JoinColumn, ManyToOne, PrimaryColumn, RelationId } from "typeorm"; import { BaseClass } from "./BaseClass"; import { Guild } from "./Guild"; import { User } from "./User"; @Entity("templates") export class Template extends BaseClass { - @PrimaryColumn() + @Column({ unique: true }) code: string; @Column() diff --git a/util/src/interfaces/Event.ts b/util/src/interfaces/Event.ts index acaa822e..2885d62a 100644 --- a/util/src/interfaces/Event.ts +++ b/util/src/interfaces/Event.ts @@ -127,12 +127,7 @@ export interface GuildCreateEvent extends Event { joined_at: Date; // TODO: add them to guild guild_scheduled_events: never[]; - guild_hashes: { - channels: { omitted: boolean; hash: string }; - metadata: { omitted: boolean; hash: string }; - roles: { omitted: boolean; hash: string }; - version: number; - }; + guild_hashes: {}; presences: never[]; stage_instances: never[]; threads: never[]; |