aboutsummaryrefslogtreecommitdiff
path: root/lib/models/shared
diff options
context:
space:
mode:
Diffstat (limited to 'lib/models/shared')
-rw-r--r--lib/models/shared/Global.ts67
-rw-r--r--lib/models/shared/GuildCount.ts38
-rw-r--r--lib/models/shared/MemberCount.ts37
-rw-r--r--lib/models/shared/Shared.ts84
-rw-r--r--lib/models/shared/Stat.ts72
5 files changed, 298 insertions, 0 deletions
diff --git a/lib/models/shared/Global.ts b/lib/models/shared/Global.ts
new file mode 100644
index 0000000..b1aa0cc
--- /dev/null
+++ b/lib/models/shared/Global.ts
@@ -0,0 +1,67 @@
+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[];
+}
+
+/**
+ * Data specific to a certain instance of the bot.
+ */
+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/lib/models/shared/GuildCount.ts b/lib/models/shared/GuildCount.ts
new file mode 100644
index 0000000..7afef56
--- /dev/null
+++ b/lib/models/shared/GuildCount.ts
@@ -0,0 +1,38 @@
+import { DataTypes, Model, type Sequelize } from 'sequelize';
+import { Environment } from '../../../config/Config.js';
+
+export interface GuildCountModel {
+ timestamp: Date;
+ environment: Environment;
+ guildCount: number;
+}
+
+export interface GuildCountCreationAttributes {
+ timestamp?: Date;
+ environment: Environment;
+ guildCount: number;
+}
+
+/**
+ * The number of guilds that the bot is in for each environment.
+ */
+export class GuildCount extends Model<GuildCountModel, GuildCountCreationAttributes> implements GuildCountModel {
+ public declare timestamp: Date;
+ public declare environment: Environment;
+ public declare guildCount: number;
+
+ /**
+ * Initializes the model.
+ * @param sequelize The sequelize instance.
+ */
+ public static initModel(sequelize: Sequelize): void {
+ GuildCount.init(
+ {
+ timestamp: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW },
+ environment: { type: DataTypes.STRING, allowNull: false },
+ guildCount: { type: DataTypes.BIGINT, allowNull: false }
+ },
+ { sequelize, timestamps: false }
+ );
+ }
+}
diff --git a/lib/models/shared/MemberCount.ts b/lib/models/shared/MemberCount.ts
new file mode 100644
index 0000000..200a58e
--- /dev/null
+++ b/lib/models/shared/MemberCount.ts
@@ -0,0 +1,37 @@
+import { DataTypes, Model, type Sequelize } from 'sequelize';
+
+export interface MemberCountModel {
+ timestamp: Date;
+ guildId: string;
+ memberCount: number;
+}
+
+export interface MemberCountCreationAttributes {
+ timestamp?: Date;
+ guildId: string;
+ memberCount: number;
+}
+
+/**
+ * The member count of each guild that the bot is in that have over 100 members.
+ */
+export class MemberCount extends Model<MemberCountModel, MemberCountCreationAttributes> implements MemberCountModel {
+ public declare timestamp: Date;
+ public declare guildId: string;
+ public declare memberCount: number;
+
+ /**
+ * Initializes the model.
+ * @param sequelize The sequelize instance.
+ */
+ public static initModel(sequelize: Sequelize): void {
+ MemberCount.init(
+ {
+ timestamp: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW },
+ guildId: { type: DataTypes.STRING, allowNull: false },
+ memberCount: { type: DataTypes.BIGINT, allowNull: false }
+ },
+ { sequelize, timestamps: false }
+ );
+ }
+}
diff --git a/lib/models/shared/Shared.ts b/lib/models/shared/Shared.ts
new file mode 100644
index 0000000..dec77d1
--- /dev/null
+++ b/lib/models/shared/Shared.ts
@@ -0,0 +1,84 @@
+import { Snowflake } from 'discord.js';
+import type { Sequelize } from 'sequelize';
+import { BadWords } from '../../automod/AutomodShared.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;
+}
+
+/**
+ * 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 }
+ );
+ }
+}
diff --git a/lib/models/shared/Stat.ts b/lib/models/shared/Stat.ts
new file mode 100644
index 0000000..8e2e0b3
--- /dev/null
+++ b/lib/models/shared/Stat.ts
@@ -0,0 +1,72 @@
+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;
+ slashCommandsUsed: bigint;
+}
+
+export interface StatModelCreationAttributes {
+ environment: Environment;
+ commandsUsed?: bigint;
+ slashCommandsUsed?: bigint;
+}
+
+/**
+ * Statistics for each instance of the bot.
+ */
+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;
+
+ /**
+ * The number of slash commands used
+ */
+ public declare slashCommandsUsed: 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}`
+ },
+ slashCommandsUsed: {
+ type: DataTypes.TEXT,
+ get: function (): bigint {
+ return BigInt(this.getDataValue('slashCommandsUsed'));
+ },
+ set: function (val: bigint) {
+ return this.setDataValue('slashCommandsUsed', <any>`${val}`);
+ },
+ allowNull: false,
+ defaultValue: `${0n}`
+ }
+ },
+ { sequelize }
+ );
+ }
+}