summary refs log tree commit diff
path: root/src/util/entities
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/entities')
-rw-r--r--src/util/entities/Application.ts14
-rw-r--r--src/util/entities/AuditLog.ts4
-rw-r--r--src/util/entities/BackupCodes.ts4
-rw-r--r--src/util/entities/BaseClass.ts9
-rw-r--r--src/util/entities/Channel.ts14
-rw-r--r--src/util/entities/ConnectedAccount.ts6
-rw-r--r--src/util/entities/Emoji.ts1
-rw-r--r--src/util/entities/Encryption.ts26
-rw-r--r--src/util/entities/Guild.ts8
-rw-r--r--src/util/entities/Member.ts25
-rw-r--r--src/util/entities/ReadState.ts1
-rw-r--r--src/util/entities/StickerPack.ts1
-rw-r--r--src/util/entities/Team.ts1
-rw-r--r--src/util/entities/User.ts19
14 files changed, 56 insertions, 77 deletions
diff --git a/src/util/entities/Application.ts b/src/util/entities/Application.ts
index 94a015e9..94709320 100644
--- a/src/util/entities/Application.ts
+++ b/src/util/entities/Application.ts
@@ -16,16 +16,8 @@
 	along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
 
-import {
-	Column,
-	Entity,
-	JoinColumn,
-	ManyToOne,
-	OneToOne,
-	RelationId,
-} from "typeorm";
+import { Column, Entity, JoinColumn, ManyToOne, OneToOne } from "typeorm";
 import { BaseClass } from "./BaseClass";
-import { Guild } from "./Guild";
 import { Team } from "./Team";
 import { User } from "./User";
 
@@ -44,7 +36,7 @@ export class Application extends BaseClass {
 	summary: string = "";
 
 	@Column({ type: "simple-json", nullable: true })
-	type?: any;
+	type?: object; // TODO: this type is bad
 
 	@Column()
 	hook: boolean = true;
@@ -176,6 +168,6 @@ export interface ApplicationCommandInteractionData {
 
 export interface ApplicationCommandInteractionDataOption {
 	name: string;
-	value?: any;
+	value?: unknown;
 	options?: ApplicationCommandInteractionDataOption[];
 }
diff --git a/src/util/entities/AuditLog.ts b/src/util/entities/AuditLog.ts
index 68893ea8..0cc2fc04 100644
--- a/src/util/entities/AuditLog.ts
+++ b/src/util/entities/AuditLog.ts
@@ -173,8 +173,8 @@ export interface AuditLogChangeValue {
 	explicit_content_filter?: number;
 	default_message_notifications?: number;
 	vanity_url_code?: string;
-	$add?: {}[];
-	$remove?: {}[];
+	$add?: object[]; // TODO: These types are bad.
+	$remove?: object[];
 	prune_delete_days?: number;
 	widget_enabled?: boolean;
 	widget_channel_id?: string;
diff --git a/src/util/entities/BackupCodes.ts b/src/util/entities/BackupCodes.ts
index 1245ecd1..467e1fe3 100644
--- a/src/util/entities/BackupCodes.ts
+++ b/src/util/entities/BackupCodes.ts
@@ -16,7 +16,7 @@
 	along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
 
-import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
+import { Column, Entity, JoinColumn, ManyToOne } from "typeorm";
 import { BaseClass } from "./BaseClass";
 import { User } from "./User";
 import crypto from "crypto";
@@ -38,7 +38,7 @@ export class BackupCode extends BaseClass {
 }
 
 export function generateMfaBackupCodes(user_id: string) {
-	let backup_codes: BackupCode[] = [];
+	const backup_codes: BackupCode[] = [];
 	for (let i = 0; i < 10; i++) {
 		const code = BackupCode.create({
 			user: { id: user_id },
diff --git a/src/util/entities/BaseClass.ts b/src/util/entities/BaseClass.ts
index e3df5ad4..445b3fc9 100644
--- a/src/util/entities/BaseClass.ts
+++ b/src/util/entities/BaseClass.ts
@@ -29,7 +29,7 @@ import { getDatabase } from "../util/Database";
 import { OrmUtils } from "../imports/OrmUtils";
 
 export class BaseClassWithoutId extends BaseEntity {
-	private get construct(): any {
+	private get construct() {
 		return this.constructor;
 	}
 
@@ -37,19 +37,24 @@ export class BaseClassWithoutId extends BaseEntity {
 		return getDatabase()?.getMetadata(this.construct);
 	}
 
-	assign(props: any) {
+	assign(props: object) {
 		OrmUtils.mergeDeep(this, props);
 		return this;
 	}
 
+	// TODO: fix eslint
+	// eslint-disable-next-line @typescript-eslint/no-explicit-any
 	toJSON(): any {
 		return Object.fromEntries(
+			// eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/no-non-null-assertion
 			this.metadata!.columns // @ts-ignore
 				.map((x) => [x.propertyName, this[x.propertyName]])
 				.concat(
+					// eslint-disable-next-line @typescript-eslint/ban-ts-comment
 					// @ts-ignore
 					this.metadata.relations.map((x) => [
 						x.propertyName,
+						// eslint-disable-next-line @typescript-eslint/ban-ts-comment
 						// @ts-ignore
 						this[x.propertyName],
 					]),
diff --git a/src/util/entities/Channel.ts b/src/util/entities/Channel.ts
index 2e5f030c..1f128713 100644
--- a/src/util/entities/Channel.ts
+++ b/src/util/entities/Channel.ts
@@ -35,7 +35,6 @@ import {
 	Snowflake,
 	trimSpecial,
 	InvisibleCharacters,
-	ChannelTypes,
 } from "../util";
 import { ChannelCreateEvent, ChannelRecipientRemoveEvent } from "../interfaces";
 import { Recipient } from "./Recipient";
@@ -219,7 +218,7 @@ export class Channel extends BaseClass {
 				!guild.features.includes("ALLOW_INVALID_CHANNEL_NAMES") &&
 				channel.name
 			) {
-				for (var character of InvisibleCharacters)
+				for (const character of InvisibleCharacters)
 					if (channel.name.includes(character))
 						throw new HTTPError(
 							"Channel name cannot include invalid characters",
@@ -237,7 +236,7 @@ export class Channel extends BaseClass {
 							403,
 						);
 
-					if (channel.name.match(/\-\-+/g))
+					if (channel.name.match(/--+/g))
 						throw new HTTPError(
 							"Channel name cannot include multiple adjacent dashes.",
 							403,
@@ -344,8 +343,9 @@ export class Channel extends BaseClass {
 			relations: ["channel", "channel.recipients"],
 		});
 
-		for (let ur of userRecipients) {
-			let re = ur.channel.recipients!.map((r) => r.user_id);
+		for (const ur of userRecipients) {
+			if (!ur.channel.recipients) continue;
+			const re = ur.channel.recipients.map((r) => r.user_id);
 			if (re.length === channelRecipients.length) {
 				if (containsAll(re, channelRecipients)) {
 					if (channel == null) {
@@ -380,8 +380,8 @@ export class Channel extends BaseClass {
 
 		const channel_dto = await DmChannelDTO.from(channel);
 
-		if (type === ChannelType.GROUP_DM) {
-			for (let recipient of channel.recipients!) {
+		if (type === ChannelType.GROUP_DM && channel.recipients) {
+			for (const recipient of channel.recipients) {
 				await emitEvent({
 					event: "CHANNEL_CREATE",
 					data: channel_dto.excludedRecipients([recipient.user_id]),
diff --git a/src/util/entities/ConnectedAccount.ts b/src/util/entities/ConnectedAccount.ts
index 1d0d0586..9f0ce35e 100644
--- a/src/util/entities/ConnectedAccount.ts
+++ b/src/util/entities/ConnectedAccount.ts
@@ -20,8 +20,10 @@ import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
 import { BaseClass } from "./BaseClass";
 import { User } from "./User";
 
-export interface PublicConnectedAccount
-	extends Pick<ConnectedAccount, "name" | "type" | "verified"> {}
+export type PublicConnectedAccount = Pick<
+	ConnectedAccount,
+	"name" | "type" | "verified"
+>;
 
 @Entity("connected_accounts")
 export class ConnectedAccount extends BaseClass {
diff --git a/src/util/entities/Emoji.ts b/src/util/entities/Emoji.ts
index 95a641f1..94ce3d54 100644
--- a/src/util/entities/Emoji.ts
+++ b/src/util/entities/Emoji.ts
@@ -20,7 +20,6 @@ import { Column, Entity, JoinColumn, ManyToOne, RelationId } from "typeorm";
 import { User } from ".";
 import { BaseClass } from "./BaseClass";
 import { Guild } from "./Guild";
-import { Role } from "./Role";
 
 @Entity("emojis")
 export class Emoji extends BaseClass {
diff --git a/src/util/entities/Encryption.ts b/src/util/entities/Encryption.ts
index db9d0983..016b4331 100644
--- a/src/util/entities/Encryption.ts
+++ b/src/util/entities/Encryption.ts
@@ -16,32 +16,8 @@
 	along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */
 
-import {
-	Column,
-	Entity,
-	JoinColumn,
-	ManyToOne,
-	OneToMany,
-	RelationId,
-} from "typeorm";
+import { Column, Entity } from "typeorm";
 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 { BitField, BitFieldResolvable, BitFlag } from "../util/BitField";
-import { Recipient } from "./Recipient";
-import { Message } from "./Message";
-import { ReadState } from "./ReadState";
-import { Invite } from "./Invite";
-import { DmChannelDTO } from "../dtos";
 
 @Entity("security_settings")
 export class SecuritySettings extends BaseClass {
diff --git a/src/util/entities/Guild.ts b/src/util/entities/Guild.ts
index 9f300334..c835f5fc 100644
--- a/src/util/entities/Guild.ts
+++ b/src/util/entities/Guild.ts
@@ -20,10 +20,8 @@ import {
 	Column,
 	Entity,
 	JoinColumn,
-	ManyToMany,
 	ManyToOne,
 	OneToMany,
-	OneToOne,
 	RelationId,
 } from "typeorm";
 import { Config, handleFile, Snowflake } from "..";
@@ -370,12 +368,12 @@ export class Guild extends BaseClass {
 			}
 		});
 
-		for (const channel of body.channels?.sort((a, b) =>
+		for (const channel of body.channels.sort((a) =>
 			a.parent_id ? 1 : -1,
 		)) {
-			var id = ids.get(channel.id) || Snowflake.generate();
+			const id = ids.get(channel.id) || Snowflake.generate();
 
-			var parent_id = ids.get(channel.parent_id);
+			const parent_id = ids.get(channel.parent_id);
 
 			await Channel.createChannel(
 				{ ...channel, guild_id, id, parent_id },
diff --git a/src/util/entities/Member.ts b/src/util/entities/Member.ts
index 801b5738..c68fe215 100644
--- a/src/util/entities/Member.ts
+++ b/src/util/entities/Member.ts
@@ -33,7 +33,7 @@ import {
 	RelationId,
 } from "typeorm";
 import { Guild } from "./Guild";
-import { Config, emitEvent, FieldErrors } from "../util";
+import { Config, emitEvent } from "../util";
 import {
 	GuildCreateEvent,
 	GuildDeleteEvent,
@@ -212,12 +212,16 @@ export class Member extends BaseClassWithoutId {
 	}
 
 	static async addRole(user_id: string, guild_id: string, role_id: string) {
-		const [member, role] = await Promise.all([
+		const [member] = await Promise.all([
 			Member.findOneOrFail({
 				where: { id: user_id, guild_id },
 				relations: ["user", "roles"], // we don't want to load  the role objects just the ids
-				//@ts-ignore
-				select: ["index", "roles.id"], // TODO fix type
+				select: {
+					index: true,
+					roles: {
+						id: true,
+					},
+				},
 			}),
 			Role.findOneOrFail({
 				where: { id: role_id, guild_id },
@@ -249,8 +253,12 @@ 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
-				//@ts-ignore
-				select: ["roles.id", "index"], // TODO: fix type
+				select: {
+					index: true,
+					roles: {
+						id: true,
+					},
+				},
 			}),
 			await Role.findOneOrFail({ where: { id: role_id, guild_id } }),
 		]);
@@ -327,7 +335,7 @@ export class Member extends BaseClassWithoutId {
 				guild_id,
 				user: {
 					sessions: {
-						status: Not("invisible" as "invisible"), // lol typescript?
+						status: Not("invisible" as const), // lol typescript?
 					},
 				},
 			},
@@ -506,8 +514,7 @@ export const PublicMemberProjection: PublicMemberKeys[] = [
 	"premium_since",
 ];
 
-// @ts-ignore
-export type PublicMember = Pick<Member, Omit<PublicMemberKeys, "roles">> & {
+export type PublicMember = Omit<Pick<Member, PublicMemberKeys>, "roles"> & {
 	user: PublicUser;
 	roles: string[]; // only role ids not objects
 };
diff --git a/src/util/entities/ReadState.ts b/src/util/entities/ReadState.ts
index a907b701..825beb03 100644
--- a/src/util/entities/ReadState.ts
+++ b/src/util/entities/ReadState.ts
@@ -26,7 +26,6 @@ import {
 } from "typeorm";
 import { BaseClass } from "./BaseClass";
 import { Channel } from "./Channel";
-import { Message } from "./Message";
 import { User } from "./User";
 
 // for read receipts
diff --git a/src/util/entities/StickerPack.ts b/src/util/entities/StickerPack.ts
index 911d8d05..ce8d5e87 100644
--- a/src/util/entities/StickerPack.ts
+++ b/src/util/entities/StickerPack.ts
@@ -22,7 +22,6 @@ import {
 	JoinColumn,
 	ManyToOne,
 	OneToMany,
-	OneToOne,
 	RelationId,
 } from "typeorm";
 import { Sticker } from ".";
diff --git a/src/util/entities/Team.ts b/src/util/entities/Team.ts
index 730ff75f..82859409 100644
--- a/src/util/entities/Team.ts
+++ b/src/util/entities/Team.ts
@@ -20,7 +20,6 @@ import {
 	Column,
 	Entity,
 	JoinColumn,
-	ManyToMany,
 	ManyToOne,
 	OneToMany,
 	RelationId,
diff --git a/src/util/entities/User.ts b/src/util/entities/User.ts
index ed9e3884..658584c3 100644
--- a/src/util/entities/User.ts
+++ b/src/util/entities/User.ts
@@ -17,8 +17,6 @@
 */
 
 import {
-	BeforeInsert,
-	BeforeUpdate,
 	Column,
 	Entity,
 	FindOneOptions,
@@ -34,6 +32,7 @@ import { Member } from "./Member";
 import { UserSettings } from "./UserSettings";
 import { Session } from "./Session";
 import { Config, FieldErrors, Snowflake, trimSpecial, adjustEmail } from "..";
+import { Request } from "express";
 
 export enum PublicUserEnum {
 	username,
@@ -80,7 +79,7 @@ export const PrivateUserProjection = [
 // Private user data that should never get sent to the client
 export type PublicUser = Pick<User, PublicUserKeys>;
 
-export interface UserPublic extends Pick<User, PublicUserKeys> {}
+export type UserPublic = Pick<User, PublicUserKeys>;
 
 export interface UserPrivate extends Pick<User, PrivateUserKeys> {
 	locale: string;
@@ -266,6 +265,7 @@ export class User extends BaseClass {
 	}
 
 	toPublicUser() {
+		// eslint-disable-next-line @typescript-eslint/no-explicit-any
 		const user: any = {};
 		PublicUserProjection.forEach((x) => {
 			user[x] = this[x];
@@ -277,6 +277,7 @@ export class User extends BaseClass {
 		return await User.findOneOrFail({
 			where: { id: user_id },
 			...opts,
+			// eslint-disable-next-line @typescript-eslint/ban-ts-comment
 			//@ts-ignore
 			select: [...PublicUserProjection, ...(opts?.select || [])], // TODO: fix
 		});
@@ -328,7 +329,6 @@ export class User extends BaseClass {
 		email,
 		username,
 		password,
-		date_of_birth,
 		id,
 		req,
 	}: {
@@ -337,7 +337,7 @@ export class User extends BaseClass {
 		email?: string;
 		date_of_birth?: Date; // "2000-04-03"
 		id?: string;
-		req?: any;
+		req?: Request;
 	}) {
 		// trim special uf8 control characters -> Backspace, Newline, ...
 		username = trimSpecial(username);
@@ -348,7 +348,8 @@ 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") || "",
 				},
 			});
 		}
@@ -357,7 +358,7 @@ export class User extends BaseClass {
 		// 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";
+			req?.language === "en" ? "en-US" : req?.language || "en-US";
 
 		const settings = UserSettings.create({
 			locale: language,
@@ -386,7 +387,9 @@ export class User extends BaseClass {
 		setImmediate(async () => {
 			if (Config.get().guild.autoJoin.enabled) {
 				for (const guild of Config.get().guild.autoJoin.guilds || []) {
-					await Member.addToGuild(user.id, guild).catch((e) => {});
+					await Member.addToGuild(user.id, guild).catch((e) =>
+						console.error("[Autojoin]", e),
+					);
 				}
 			}
 		});