summary refs log tree commit diff
path: root/src/util/entities/Member.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/entities/Member.ts')
-rw-r--r--src/util/entities/Member.ts116
1 files changed, 45 insertions, 71 deletions
diff --git a/src/util/entities/Member.ts b/src/util/entities/Member.ts
index baac58ed..42a014d4 100644
--- a/src/util/entities/Member.ts
+++ b/src/util/entities/Member.ts
@@ -1,31 +1,14 @@
-import { PublicUser, User } from "./User";
-import { BaseClass } from "./BaseClass";
-import {
-	Column,
-	Entity,
-	Index,
-	JoinColumn,
-	JoinTable,
-	ManyToMany,
-	ManyToOne,
-	PrimaryGeneratedColumn,
-	RelationId,
-} from "typeorm";
-import { Guild } from "./Guild";
-import { Config, emitEvent } from "../util";
-import {
-	GuildCreateEvent,
-	GuildDeleteEvent,
-	GuildMemberAddEvent,
-	GuildMemberRemoveEvent,
-	GuildMemberUpdateEvent,
-} from "../interfaces";
-import { HTTPError } from "../util/imports/HTTPError";
-import { Role } from "./Role";
-import { BaseClassWithoutId } from "./BaseClass";
+import { Column, Entity, Index, JoinColumn, JoinTable, ManyToMany, ManyToOne, PrimaryGeneratedColumn, RelationId } from "typeorm";
 import { Ban, PublicGuildRelations } from ".";
+import { GuildCreateEvent, GuildDeleteEvent, GuildMemberAddEvent, GuildMemberRemoveEvent, GuildMemberUpdateEvent } from "../interfaces";
+import { Config, emitEvent } from "../util";
 import { DiscordApiErrors } from "../util/Constants";
+import { HTTPError } from "../util/imports/HTTPError";
 import { OrmUtils } from "../util/imports/OrmUtils";
+import { BaseClassWithoutId } from "./BaseClass";
+import { Guild } from "./Guild";
+import { Role } from "./Role";
+import { PublicUser, User } from "./User";
 
 export const MemberPrivateProjection: (keyof Member)[] = [
 	"id",
@@ -40,7 +23,7 @@ export const MemberPrivateProjection: (keyof Member)[] = [
 	"premium_since",
 	"roles",
 	"settings",
-	"user",
+	"user"
 ];
 
 @Entity("members")
@@ -55,7 +38,7 @@ export class Member extends BaseClassWithoutId {
 
 	@JoinColumn({ name: "id" })
 	@ManyToOne(() => User, {
-		onDelete: "CASCADE",
+		onDelete: "CASCADE"
 	})
 	user: User;
 
@@ -65,7 +48,7 @@ export class Member extends BaseClassWithoutId {
 
 	@JoinColumn({ name: "guild_id" })
 	@ManyToOne(() => Guild, {
-		onDelete: "CASCADE",
+		onDelete: "CASCADE"
 	})
 	guild: Guild;
 
@@ -77,8 +60,8 @@ export class Member extends BaseClassWithoutId {
 		joinColumn: { name: "index", referencedColumnName: "index" },
 		inverseJoinColumn: {
 			name: "role_id",
-			referencedColumnName: "id",
-		},
+			referencedColumnName: "id"
+		}
 	})
 	@ManyToMany(() => Role, { cascade: true })
 	roles: Role[];
@@ -133,22 +116,22 @@ export class Member extends BaseClassWithoutId {
 		return Promise.all([
 			Member.delete({
 				id: user_id,
-				guild_id,
+				guild_id
 			}),
 			//Guild.decrement({ id: guild_id }, "member_count", -1),
 
 			emitEvent({
 				event: "GUILD_DELETE",
 				data: {
-					id: guild_id,
+					id: guild_id
 				},
-				user_id: user_id,
+				user_id: user_id
 			} as GuildDeleteEvent),
 			emitEvent({
 				event: "GUILD_MEMBER_REMOVE",
 				data: { guild_id, user: member.user },
-				guild_id,
-			} as GuildMemberRemoveEvent),
+				guild_id
+			} as GuildMemberRemoveEvent)
 		]);
 	}
 
@@ -158,9 +141,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: ["index"],
+				select: ["index"]
 			}),
-			Role.findOneOrFail({ where: { id: role_id, guild_id }, select: ["id"] }),
+			Role.findOneOrFail({ where: { id: role_id, guild_id }, select: ["id"] })
 		]);
 		member.roles.push(OrmUtils.mergeDeep(new Role(), { id: role_id }));
 
@@ -171,10 +154,10 @@ export class Member extends BaseClassWithoutId {
 				data: {
 					guild_id,
 					user: member.user,
-					roles: member.roles.map((x) => x.id),
+					roles: member.roles.map((x) => x.id)
 				},
-				guild_id,
-			} as GuildMemberUpdateEvent),
+				guild_id
+			} as GuildMemberUpdateEvent)
 		]);
 	}
 
@@ -184,9 +167,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: ["index"],
+				select: ["index"]
 			}),
-			await Role.findOneOrFail({ where: { id: role_id, guild_id } }),
+			await Role.findOneOrFail({ where: { id: role_id, guild_id } })
 		]);
 		member.roles = member.roles.filter((x) => x.id == role_id);
 
@@ -197,10 +180,10 @@ export class Member extends BaseClassWithoutId {
 				data: {
 					guild_id,
 					user: member.user,
-					roles: member.roles.map((x) => x.id),
+					roles: member.roles.map((x) => x.id)
 				},
-				guild_id,
-			} as GuildMemberUpdateEvent),
+				guild_id
+			} as GuildMemberUpdateEvent)
 		]);
 	}
 
@@ -208,9 +191,9 @@ export class Member extends BaseClassWithoutId {
 		const member = await Member.findOneOrFail({
 			where: {
 				id: user_id,
-				guild_id,
+				guild_id
 			},
-			relations: ["user"],
+			relations: ["user"]
 		});
 		member.nick = nickname;
 
@@ -222,10 +205,10 @@ export class Member extends BaseClassWithoutId {
 				data: {
 					guild_id,
 					user: member.user,
-					nick: nickname,
+					nick: nickname
 				},
-				guild_id,
-			} as GuildMemberUpdateEvent),
+				guild_id
+			} as GuildMemberUpdateEvent)
 		]);
 	}
 
@@ -243,9 +226,9 @@ export class Member extends BaseClassWithoutId {
 
 		const guild = await Guild.findOneOrFail({
 			where: {
-				id: guild_id,
+				id: guild_id
 			},
-			relations: PublicGuildRelations,
+			relations: PublicGuildRelations
 		});
 
 		if (await Member.count({ where: { id: user.id, guild: { id: guild_id } } }))
@@ -260,7 +243,7 @@ export class Member extends BaseClassWithoutId {
 			premium_since: null,
 			deaf: false,
 			mute: false,
-			pending: false,
+			pending: false
 		};
 		//TODO: check for bugs
 		if (guild.member_count) guild.member_count++;
@@ -276,8 +259,8 @@ export class Member extends BaseClassWithoutId {
 					muted: false,
 					suppress_everyone: false,
 					suppress_roles: false,
-					version: 0,
-				},
+					version: 0
+				}
 				// Member.save is needed because else the roles relations wouldn't be updated
 			}).save(),
 			//Guild.increment({ id: guild_id }, "member_count", 1),
@@ -286,9 +269,9 @@ export class Member extends BaseClassWithoutId {
 				data: {
 					...member,
 					user,
-					guild_id,
+					guild_id
 				},
-				guild_id,
+				guild_id
 			} as GuildMemberAddEvent),
 			emitEvent({
 				event: "GUILD_CREATE",
@@ -301,10 +284,10 @@ export class Member extends BaseClassWithoutId {
 					joined_at: member.joined_at,
 					presences: [],
 					stage_instances: [],
-					threads: [],
+					threads: []
 				},
-				user_id,
-			} as GuildCreateEvent),
+				user_id
+			} as GuildCreateEvent)
 		]);
 	}
 }
@@ -330,16 +313,7 @@ export interface MuteConfig {
 	selected_time_window: number;
 }
 
-export type PublicMemberKeys =
-	| "id"
-	| "guild_id"
-	| "nick"
-	| "roles"
-	| "joined_at"
-	| "pending"
-	| "deaf"
-	| "mute"
-	| "premium_since";
+export type PublicMemberKeys = "id" | "guild_id" | "nick" | "roles" | "joined_at" | "pending" | "deaf" | "mute" | "premium_since";
 
 export const PublicMemberProjection: PublicMemberKeys[] = [
 	"id",
@@ -350,7 +324,7 @@ export const PublicMemberProjection: PublicMemberKeys[] = [
 	"pending",
 	"deaf",
 	"mute",
-	"premium_since",
+	"premium_since"
 ];
 
 // @ts-ignore