summary refs log tree commit diff
path: root/src/models/User.ts
blob: eb6a4182d52ab8861e84ecf48d4a2bf0e6607993 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
import { Activity } from "./Activity";
import { ClientStatus, Status } from "./Status";
import { Schema, Types, Document } from "mongoose";
import db from "../util/Database";

export interface User {
	id: bigint;
	username: string; // username max length 32, min 2
	discriminator: string; // #0001 4 digit long string from #0001 - #9999
	avatar: string | null; // hash of the user avatar
	phone?: string; // phone number of the user
	desktop: boolean; // if the user has desktop app installed
	mobile: boolean; // if the user has mobile app installed
	premium: boolean; // if user bought nitro
	premium_type: number; // nitro level
	bot: boolean; // if user is bot
	system: boolean; // shouldn't be used, the api sents this field type true, if the genetaed message comes from a system generated author
	nsfw_allowed: boolean; // if the user is older than 18 (resp. Config)
	mfa_enabled: boolean; // if multi factor authentication is enabled
	created_at: Date; // registration date
	verified: boolean; // if the user is offically verified
	email?: string; // email of the user
	flags: bigint; // UserFlags
	public_flags: bigint;
	user_settings: UserSettings;
	guilds: bigint[]; // array of guild ids the user is part of
	user_data: UserData;
	presence: {
		status: Status;
		activities: Activity[];
		client_status: ClientStatus;
	};
}

// Privat user data:
export interface UserData {
	valid_tokens_since: Date; // all tokens with a previous issue date are invalid
	relationships: Relationship[];
	connected_accounts: ConnectedAccount[];
	hash: string; // hash of the password, salt is saved in password (bcrypt)
	fingerprints: string[]; // array of fingerprints -> used to prevent multiple accounts
}

export interface UserDocument extends User, Document {
	id: bigint;
}

export interface PublicUser {
	id: bigint;
	discriminator: string;
	username: string;
	avatar?: string;
	public_flags: bigint;
}

export interface ConnectedAccount {
	access_token: string;
	friend_sync: boolean;
	id: string;
	name: string;
	revoked: boolean;
	show_activity: boolean;
	type: string;
	verifie: boolean;
	visibility: number;
}

export interface Relationship {
	id: bigint;
	nickname?: string;
	type: number;
	user_id: bigint;
}

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: bigint | null;
		emoji_name: string | null;
		expires_at: number | null;
		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;
	guild_folders: // every top guild is displayed as a "folder"
	{
		color: number;
		guild_ids: bigint[];
		id: number;
		name: string;
	}[];
	guild_positions: bigint[]; // 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: bigint[];
	show_current_game: boolean;
	status: "online" | "offline" | "dnd" | "idle";
	stream_notifications_enabled: boolean;
	theme: "dark" | "white"; // dark
	timezone_offset: number; // e.g -60
}

export const UserSchema = new Schema({
	id: Types.Long,
	username: String,
	discriminator: String,
	avatar: String,
	phone: String,
	desktop: Boolean,
	mobile: Boolean,
	premium: Boolean,
	premium_type: Number,
	bot: Boolean,
	system: Boolean,
	nsfw_allowed: Boolean,
	mfa_enabled: Boolean,
	created_at: Date,
	verified: Boolean,
	email: String,
	flags: Types.Long, // TODO: automatically convert Types.Long to BitField of UserFlags
	public_flags: Types.Long,
	user_data: {
		fingerprints: [String],
		hash: String, // hash of the password, salt is saved in password (bcrypt)
		guilds: [Types.Long], // array of guild ids the user is part of
		valid_tokens_since: Date, // all tokens with a previous issue date are invalid
		relationships: [
			{
				id: Types.Long,
				nickname: String,
				type: Number,
				user_id: Types.Long,
			},
		],
		connected_accounts: [
			{
				access_token: String,
				friend_sync: Boolean,
				id: String,
				name: String,
				revoked: Boolean,
				show_activity: Boolean,
				type: String,
				verifie: Boolean,
				visibility: Number,
			},
		],
	},
	user_settings: {
		afk_timeout: Number,
		allow_accessibility_detection: Boolean,
		animate_emoji: Boolean,
		animate_stickers: Number,
		contact_sync_enabled: Boolean,
		convert_emoticons: Boolean,
		custom_status: {
			emoji_id: Types.Long,
			emoji_name: String,
			expires_at: Number,
			text: String,
		},
		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: [Types.Long],
				id: Number,
				name: String,
			},
		],
		guild_positions: [Types.Long], // 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: [Types.Long],
		show_current_game: Boolean,
		status: String,
		stream_notifications_enabled: Boolean,
		theme: String, // dark
		timezone_offset: Number, // e.g -60,
	},

	presence: {
		status: String,
		activities: [Activity],
		client_status: ClientStatus,
	},
});

// @ts-ignore
export const UserModel = db.model<UserDocument>("User", UserSchema, "users");