summary refs log tree commit diff
path: root/src/models/Member.ts
blob: c177c6c9eb83267f318297590caccb1360e35f55 (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
import { PublicUser, User, UserModel } from "./User";
import { Schema, Types, Document } from "mongoose";
import db from "../util/Database";

export interface Member {
	id: bigint;
	guild_id: bigint;
	nick?: string;
	roles: bigint[];
	joined_at: number;
	premium_since?: number;
	deaf: boolean;
	mute: boolean;
	pending: boolean;
	settings: UserGuildSettings;
	user?: User;
}

export interface MemberDocument extends Member, Document {
	id: bigint;
}

export interface UserGuildSettings {
	channel_overrides: {
		channel_id: bigint;
		message_notifications: number;
		mute_config: MuteConfig;
		muted: boolean;
	}[];
	message_notifications: number;
	mobile_push: boolean;
	mute_config: MuteConfig;
	muted: boolean;
	suppress_everyone: boolean;
	suppress_roles: boolean;
	version: number;
}

export interface MuteConfig {
	end_time: number;
	selected_time_window: number;
}

const MuteConfig = {
	end_time: Number,
	selected_time_window: Number,
};

export const MemberSchema = new Schema({
	id: Types.Long,
	guild_id: Types.Long,
	nick: String,
	roles: [Types.Long],
	joined_at: Number,
	premium_since: Number,
	deaf: Boolean,
	mute: Boolean,
	pending: Boolean,
	settings: {
		channel_overrides: [
			{
				channel_id: Types.Long,
				message_notifications: Number,
				mute_config: MuteConfig,
				muted: Boolean,
			},
		],
		message_notifications: Number,
		mobile_push: Boolean,
		mute_config: MuteConfig,
		muted: Boolean,
		suppress_everyone: Boolean,
		suppress_roles: Boolean,
		version: Number,
	},
});

MemberSchema.virtual("user", {
	model: UserModel,
	localField: "user",
	foreignField: "id",
});

// @ts-ignore
export const MemberModel = db.model<MemberDocument>("Member", MemberSchema, "members");

// @ts-ignore
export interface PublicMember extends Omit<Member, "settings" | "id"> {
	user: PublicUser;
}