aboutsummaryrefslogtreecommitdiff
path: root/lib/models/shared/Shared.ts
blob: bf8d461a52790c6d1bbe30d9df2f118bd895948c (plain)
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
import { Snowflake } from 'discord.js';
import { DataTypes, Sequelize } from 'sequelize';
import { BadWords } from '../../automod/AutomodShared.js';
import { BaseModel } from '../BaseModel.js';

export interface SharedModel {
	primaryKey: 0;
	superUsers: Snowflake[];
	privilegedUsers: Snowflake[];
	badLinksSecret: string[];
	badLinks: string[];
	badWords: BadWords;
	autoBanCode: string | null;
}

export interface SharedModelCreationAttributes {
	primaryKey?: 0;
	superUsers?: Snowflake[];
	privilegedUsers?: Snowflake[];
	badLinksSecret?: string[];
	badLinks?: string[];
	badWords?: BadWords;
	autoBanCode?: string;
}

/**
 * Data shared between all bot instances.
 */
export class Shared extends BaseModel<SharedModel, SharedModelCreationAttributes> implements SharedModel {
	/**
	 * The primary key of the shared model.
	 */
	public declare primaryKey: 0;

	/**
	 * Trusted users.
	 */
	public declare superUsers: Snowflake[];

	/**
	 * Users that have all permissions that devs have except eval.
	 */
	public declare privilegedUsers: Snowflake[];

	/**
	 * Non-public bad links.
	 */
	public declare badLinksSecret: string[];

	/**
	 * Public Bad links.
	 */
	public declare badLinks: string[];

	/**
	 * Bad words.
	 */
	public declare badWords: BadWords;

	/**
	 * Code that is used to match for auto banning users in moulberry's bush
	 */
	public declare autoBanCode: string;

	/**
	 * Initializes the model.
	 * @param sequelize The sequelize instance.
	 */
	public static initModel(sequelize: Sequelize): void {
		Shared.init(
			{
				primaryKey: { type: DataTypes.INTEGER, primaryKey: true, validate: { min: 0, max: 0 } },
				superUsers: { type: DataTypes.JSONB, allowNull: false, defaultValue: [] },
				privilegedUsers: { type: DataTypes.JSONB, allowNull: false, defaultValue: [] },
				badLinksSecret: { type: DataTypes.JSONB, allowNull: false, defaultValue: [] },
				badLinks: { type: DataTypes.JSONB, allowNull: false, defaultValue: [] },
				badWords: { type: DataTypes.JSONB, allowNull: false, defaultValue: {} },
				autoBanCode: { type: DataTypes.TEXT }
			},
			{ sequelize, freezeTableName: true }
		);
	}
}