aboutsummaryrefslogtreecommitdiff
path: root/src/lib/models/shared
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-02-04 11:05:30 -0500
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-02-04 11:05:30 -0500
commite5bc336f9586b1f5515be3f1d239d2194489e9c5 (patch)
tree5bcf124dc277f23ee5b812b9f93a385bf9180f1f /src/lib/models/shared
parent2db87acac4fe36baa93db0a8e52d7a83b3ce2998 (diff)
downloadtanzanite-e5bc336f9586b1f5515be3f1d239d2194489e9c5.tar.gz
tanzanite-e5bc336f9586b1f5515be3f1d239d2194489e9c5.tar.bz2
tanzanite-e5bc336f9586b1f5515be3f1d239d2194489e9c5.zip
refactor models
Diffstat (limited to 'src/lib/models/shared')
-rw-r--r--src/lib/models/shared/Global.ts64
-rw-r--r--src/lib/models/shared/Shared.ts81
-rw-r--r--src/lib/models/shared/Stat.ts51
3 files changed, 196 insertions, 0 deletions
diff --git a/src/lib/models/shared/Global.ts b/src/lib/models/shared/Global.ts
new file mode 100644
index 0000000..6dfc36f
--- /dev/null
+++ b/src/lib/models/shared/Global.ts
@@ -0,0 +1,64 @@
+import { type Snowflake } from 'discord.js';
+import { type Sequelize } from 'sequelize';
+import { BaseModel } from '../BaseModel.js';
+const { DataTypes } = (await import('sequelize')).default;
+
+export interface GlobalModel {
+ environment: 'production' | 'development' | 'beta';
+ disabledCommands: string[];
+ blacklistedUsers: Snowflake[];
+ blacklistedGuilds: Snowflake[];
+ blacklistedChannels: Snowflake[];
+}
+
+export interface GlobalModelCreationAttributes {
+ environment: 'production' | 'development' | 'beta';
+ disabledCommands?: string[];
+ blacklistedUsers?: Snowflake[];
+ blacklistedGuilds?: Snowflake[];
+ blacklistedChannels?: Snowflake[];
+}
+
+export class Global extends BaseModel<GlobalModel, GlobalModelCreationAttributes> implements GlobalModel {
+ /**
+ * The bot's environment.
+ */
+ public declare environment: 'production' | 'development' | 'beta';
+
+ /**
+ * Globally disabled commands.
+ */
+ public declare disabledCommands: string[];
+
+ /**
+ * Globally blacklisted users.
+ */
+ public declare blacklistedUsers: Snowflake[];
+
+ /**
+ * Guilds blacklisted from using the bot.
+ */
+ public declare blacklistedGuilds: Snowflake[];
+
+ /**
+ * Channels where the bot is prevented from running commands in.
+ */
+ public declare blacklistedChannels: Snowflake[];
+
+ /**
+ * Initializes the model.
+ * @param sequelize The sequelize instance.
+ */
+ public static initModel(sequelize: Sequelize): void {
+ Global.init(
+ {
+ environment: { type: DataTypes.STRING, primaryKey: true },
+ disabledCommands: { type: DataTypes.JSONB, allowNull: false, defaultValue: [] },
+ blacklistedUsers: { type: DataTypes.JSONB, allowNull: false, defaultValue: [] },
+ blacklistedGuilds: { type: DataTypes.JSONB, allowNull: false, defaultValue: [] },
+ blacklistedChannels: { type: DataTypes.JSONB, allowNull: false, defaultValue: [] }
+ },
+ { sequelize }
+ );
+ }
+}
diff --git a/src/lib/models/shared/Shared.ts b/src/lib/models/shared/Shared.ts
new file mode 100644
index 0000000..642ff85
--- /dev/null
+++ b/src/lib/models/shared/Shared.ts
@@ -0,0 +1,81 @@
+import { Snowflake } from 'discord.js';
+import type { Sequelize } from 'sequelize';
+import type { BadWords } from '../../common/AutoMod.js';
+import { BaseModel } from '../BaseModel.js';
+const { DataTypes } = (await import('sequelize')).default;
+
+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;
+}
+
+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 }
+ );
+ }
+}
diff --git a/src/lib/models/shared/Stat.ts b/src/lib/models/shared/Stat.ts
new file mode 100644
index 0000000..8f77b58
--- /dev/null
+++ b/src/lib/models/shared/Stat.ts
@@ -0,0 +1,51 @@
+import { type Sequelize } from 'sequelize';
+import { BaseModel } from '../BaseModel.js';
+const { DataTypes } = (await import('sequelize')).default;
+
+type Environment = 'production' | 'development' | 'beta';
+
+export interface StatModel {
+ environment: Environment;
+ commandsUsed: bigint;
+}
+
+export interface StatModelCreationAttributes {
+ environment: Environment;
+ commandsUsed?: bigint;
+}
+
+export class Stat extends BaseModel<StatModel, StatModelCreationAttributes> implements StatModel {
+ /**
+ * The bot's environment.
+ */
+ public declare environment: Environment;
+
+ /**
+ * The number of commands used
+ */
+ public declare commandsUsed: bigint;
+
+ /**
+ * Initializes the model.
+ * @param sequelize The sequelize instance.
+ */
+ public static initModel(sequelize: Sequelize): void {
+ Stat.init(
+ {
+ environment: { type: DataTypes.STRING, primaryKey: true },
+ commandsUsed: {
+ type: DataTypes.TEXT,
+ get: function (): bigint {
+ return BigInt(this.getDataValue('commandsUsed'));
+ },
+ set: function (val: bigint) {
+ return this.setDataValue('commandsUsed', <any>`${val}`);
+ },
+ allowNull: false,
+ defaultValue: `${0n}`
+ }
+ },
+ { sequelize }
+ );
+ }
+}