summary refs log tree commit diff
path: root/util/src
diff options
context:
space:
mode:
authorAlTech98 <altech123159@gmail.com>2021-09-03 13:36:22 +0200
committerAlTech98 <altech123159@gmail.com>2021-09-03 13:36:22 +0200
commit2028cc8e0b6b462e59ce6e4b537324114ec2458e (patch)
treeee04a9f6978bec8b21776a988bd9ca2393056d72 /util/src
parentVoiceState fix for db update (diff)
parent:bug: fix member roles + list (diff)
downloadserver-2028cc8e0b6b462e59ce6e4b537324114ec2458e.tar.xz
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'util/src')
-rw-r--r--util/src/entities/Member.ts31
-rw-r--r--util/src/interfaces/Event.ts11
2 files changed, 34 insertions, 8 deletions
diff --git a/util/src/entities/Member.ts b/util/src/entities/Member.ts
index ae60f4e2..76febb50 100644
--- a/util/src/entities/Member.ts
+++ b/util/src/entities/Member.ts
@@ -54,13 +54,14 @@ export class Member extends BaseClassWithoutId {
 
 	@JoinTable({
 		name: "member_roles",
-		joinColumn: { name: "id", referencedColumnName: "index" },
+
+		joinColumn: { name: "index", referencedColumnName: "index" },
 		inverseJoinColumn: {
 			name: "role_id",
 			referencedColumnName: "id",
 		},
 	})
-	@ManyToMany(() => Role)
+	@ManyToMany(() => Role, { cascade: true })
 	roles: Role[];
 
 	@Column()
@@ -208,7 +209,7 @@ export class Member extends BaseClassWithoutId {
 			where: {
 				id: guild_id,
 			},
-			relations: ["channels", "emojis", "members", "roles", "stickers"],
+			relations: ["channels", "emojis", "members", "roles", "stickers", "voice_states"],
 		});
 
 		if (await Member.count({ id: user.id, guild: { id: guild_id } }))
@@ -225,11 +226,9 @@ export class Member extends BaseClassWithoutId {
 			mute: false,
 			pending: false,
 		};
-		// @ts-ignore
-		guild.joined_at = member.joined_at.toISOString();
 
 		await Promise.all([
-			Member.insert({
+			new Member({
 				...member,
 				roles: [new Role({ id: guild_id })],
 				// read_state: {},
@@ -242,7 +241,8 @@ export class Member extends BaseClassWithoutId {
 					suppress_roles: false,
 					version: 0,
 				},
-			}),
+				// Member.save is needed because else the roles relations wouldn't be updated
+			}).save(),
 			Guild.increment({ id: guild_id }, "member_count", 1),
 			emitEvent({
 				event: "GUILD_MEMBER_ADD",
@@ -255,7 +255,22 @@ export class Member extends BaseClassWithoutId {
 			} as GuildMemberAddEvent),
 			emitEvent({
 				event: "GUILD_CREATE",
-				data: { ...guild, members: [...guild.members, { ...member, user }] },
+				data: {
+					...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_scheduled_events: [],
+					joined_at: member.joined_at,
+					presences: [],
+					stage_instances: [],
+					threads: [],
+				},
 				user_id,
 			} as GuildCreateEvent),
 		]);
diff --git a/util/src/interfaces/Event.ts b/util/src/interfaces/Event.ts
index 7ea1bd49..acaa822e 100644
--- a/util/src/interfaces/Event.ts
+++ b/util/src/interfaces/Event.ts
@@ -125,6 +125,17 @@ export interface GuildCreateEvent extends Event {
 	event: "GUILD_CREATE";
 	data: Guild & {
 		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;
+		};
+		presences: never[];
+		stage_instances: never[];
+		threads: never[];
 	};
 }