aboutsummaryrefslogtreecommitdiff
path: root/src/lib/models/Global.ts
blob: 17bd5702eaf64efc6fa1c51e8b33f8abd497faaa (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { Snowflake } from 'discord.js';
import { DataTypes, Sequelize } from 'sequelize';
import { BaseModel } from './BaseModel';
import { jsonArrayInit, NEVER_USED } from './__helpers';

export interface GlobalModel {
	environment: 'production' | 'development' | 'beta';
	superUsers: Snowflake[];
	disabledCommands: string[];
	blacklistedUsers: Snowflake[];
	blacklistedGuilds: Snowflake[];
	blacklistedChannels: Snowflake[];
}

export interface GlobalModelCreationAttributes {
	environment: 'production' | 'development' | 'beta';
	superUsers?: Snowflake[];
	disabledCommands?: string[];
	blacklistedUsers?: Snowflake[];
	blacklistedGuilds?: Snowflake[];
	blacklistedChannels?: Snowflake[];
}

export class Global extends BaseModel<GlobalModel, GlobalModelCreationAttributes> implements GlobalModel {
	/**
	 * The bot's environment.
	 */
	public get environment(): 'production' | 'development' | 'beta' {
		throw new Error(NEVER_USED);
	}
	public set environment(_: 'production' | 'development' | 'beta') {
		throw new Error(NEVER_USED);
	}

	/**
	 * Trusted users.
	 */
	public get superUsers(): Snowflake[] {
		throw new Error(NEVER_USED);
	}
	public set superUsers(_: Snowflake[]) {
		throw new Error(NEVER_USED);
	}

	/**
	 * Globally disabled commands.
	 */
	public get disabledCommands(): string[] {
		throw new Error(NEVER_USED);
	}
	public set disabledCommands(_: string[]) {
		throw new Error(NEVER_USED);
	}

	/**
	 * Globally blacklisted users.
	 */
	public get blacklistedUsers(): Snowflake[] {
		throw new Error(NEVER_USED);
	}
	public set blacklistedUsers(_: Snowflake[]) {
		throw new Error(NEVER_USED);
	}

	/**
	 * Guilds blacklisted from using the bot.
	 */
	public get blacklistedGuilds(): Snowflake[] {
		throw new Error(NEVER_USED);
	}
	public set blacklistedGuilds(_: Snowflake[]) {
		throw new Error(NEVER_USED);
	}

	/**
	 * Channels where the bot is prevented from running.
	 */
	public get blacklistedChannels(): Snowflake[] {
		throw new Error(NEVER_USED);
	}
	public set blacklistedChannels(_: Snowflake[]) {
		throw new Error(NEVER_USED);
	}

	public static initModel(sequelize: Sequelize): void {
		Global.init(
			{
				environment: {
					type: DataTypes.STRING,
					primaryKey: true
				},
				superUsers: jsonArrayInit('superUsers'),
				disabledCommands: jsonArrayInit('disabledCommands'),
				blacklistedUsers: jsonArrayInit('blacklistedUsers'),
				blacklistedGuilds: jsonArrayInit('blacklistedGuilds'),
				blacklistedChannels: jsonArrayInit('blacklistedChannels')
			},
			{ sequelize }
		);
	}
}