From 2356d2c44736fb83021dacb551625852111c8ce6 Mon Sep 17 00:00:00 2001
From: IRONM00N <64110067+IRONM00N@users.noreply.github.com>
Date: Thu, 18 Aug 2022 22:42:12 -0400
Subject: restructure, experimental presence and member automod, fixed bugs
probably made some more bugs
---
src/lib/models/BaseModel.ts | 13 -
src/lib/models/instance/ActivePunishment.ts | 94 -------
src/lib/models/instance/Guild.ts | 422 ----------------------------
src/lib/models/instance/Highlight.ts | 81 ------
src/lib/models/instance/Level.ts | 70 -----
src/lib/models/instance/ModLog.ts | 127 ---------
src/lib/models/instance/Reminder.ts | 84 ------
src/lib/models/instance/StickyRole.ts | 58 ----
src/lib/models/shared/Global.ts | 67 -----
src/lib/models/shared/GuildCount.ts | 39 ---
src/lib/models/shared/MemberCount.ts | 38 ---
src/lib/models/shared/Shared.ts | 84 ------
src/lib/models/shared/Stat.ts | 72 -----
13 files changed, 1249 deletions(-)
delete mode 100644 src/lib/models/BaseModel.ts
delete mode 100644 src/lib/models/instance/ActivePunishment.ts
delete mode 100644 src/lib/models/instance/Guild.ts
delete mode 100644 src/lib/models/instance/Highlight.ts
delete mode 100644 src/lib/models/instance/Level.ts
delete mode 100644 src/lib/models/instance/ModLog.ts
delete mode 100644 src/lib/models/instance/Reminder.ts
delete mode 100644 src/lib/models/instance/StickyRole.ts
delete mode 100644 src/lib/models/shared/Global.ts
delete mode 100644 src/lib/models/shared/GuildCount.ts
delete mode 100644 src/lib/models/shared/MemberCount.ts
delete mode 100644 src/lib/models/shared/Shared.ts
delete mode 100644 src/lib/models/shared/Stat.ts
(limited to 'src/lib/models')
diff --git a/src/lib/models/BaseModel.ts b/src/lib/models/BaseModel.ts
deleted file mode 100644
index e503317..0000000
--- a/src/lib/models/BaseModel.ts
+++ /dev/null
@@ -1,13 +0,0 @@
-const { Model } = (await import('sequelize')).default;
-
-export abstract class BaseModel extends Model {
- /**
- * The date when the row was created.
- */
- public declare readonly createdAt: Date;
-
- /**
- * The date when the row was last updated.
- */
- public declare readonly updatedAt: Date;
-}
diff --git a/src/lib/models/instance/ActivePunishment.ts b/src/lib/models/instance/ActivePunishment.ts
deleted file mode 100644
index 38012ca..0000000
--- a/src/lib/models/instance/ActivePunishment.ts
+++ /dev/null
@@ -1,94 +0,0 @@
-import { type Snowflake } from 'discord.js';
-import { nanoid } from 'nanoid';
-import { type Sequelize } from 'sequelize';
-import { BaseModel } from '../BaseModel.js';
-const { DataTypes } = (await import('sequelize')).default;
-
-export enum ActivePunishmentType {
- BAN = 'BAN',
- MUTE = 'MUTE',
- ROLE = 'ROLE',
- BLOCK = 'BLOCK'
-}
-
-export interface ActivePunishmentModel {
- id: string;
- type: ActivePunishmentType;
- user: Snowflake;
- guild: Snowflake;
- extraInfo: Snowflake;
- expires: Date | null;
- modlog: string;
-}
-
-export interface ActivePunishmentModelCreationAttributes {
- id?: string;
- type: ActivePunishmentType;
- user: Snowflake;
- guild: Snowflake;
- extraInfo?: Snowflake;
- expires?: Date;
- modlog: string;
-}
-
-/**
- * Keeps track of active punishments so they can be removed later.
- */
-export class ActivePunishment
- extends BaseModel
- implements ActivePunishmentModel
-{
- /**
- * The ID of this punishment (no real use just for a primary key)
- */
- public declare id: string;
-
- /**
- * The type of punishment.
- */
- public declare type: ActivePunishmentType;
-
- /**
- * The user who is punished.
- */
- public declare user: Snowflake;
-
- /**
- * The guild they are punished in.
- */
- public declare guild: Snowflake;
-
- /**
- * Additional info about the punishment if applicable. The channel id for channel blocks and role for punishment roles.
- */
- public declare extraInfo: Snowflake;
-
- /**
- * The date when this punishment expires (optional).
- */
- public declare expires: Date | null;
-
- /**
- * The reference to the modlog entry.
- */
- public declare modlog: string;
-
- /**
- * Initializes the model.
- * @param sequelize The sequelize instance.
- */
- public static initModel(sequelize: Sequelize): void {
- ActivePunishment.init(
- {
- id: { type: DataTypes.STRING, primaryKey: true, defaultValue: nanoid },
- type: { type: DataTypes.STRING, allowNull: false },
- user: { type: DataTypes.STRING, allowNull: false },
- guild: { type: DataTypes.STRING, allowNull: false, references: { model: 'Guilds', key: 'id' } },
- extraInfo: { type: DataTypes.STRING, allowNull: true },
- expires: { type: DataTypes.DATE, allowNull: true },
- modlog: { type: DataTypes.STRING, allowNull: true, references: { model: 'ModLogs', key: 'id' } }
- },
- { sequelize }
- );
- }
-}
diff --git a/src/lib/models/instance/Guild.ts b/src/lib/models/instance/Guild.ts
deleted file mode 100644
index f0cac74..0000000
--- a/src/lib/models/instance/Guild.ts
+++ /dev/null
@@ -1,422 +0,0 @@
-import { ChannelType, Constants, type Snowflake } from 'discord.js';
-import { type Sequelize } from 'sequelize';
-import { BadWordDetails } from '../../common/AutoMod.js';
-import { type BushClient } from '../../extensions/discord-akairo/BushClient.js';
-import { BaseModel } from '../BaseModel.js';
-const { DataTypes } = (await import('sequelize')).default;
-
-export interface GuildModel {
- id: Snowflake;
- prefix: string;
- autoPublishChannels: Snowflake[];
- blacklistedChannels: Snowflake[];
- blacklistedUsers: Snowflake[];
- welcomeChannel: Snowflake | null;
- muteRole: Snowflake | null;
- punishmentEnding: string | null;
- disabledCommands: string[];
- lockdownChannels: Snowflake[];
- autoModPhases: BadWordDetails[];
- enabledFeatures: GuildFeatures[];
- joinRoles: Snowflake[];
- logChannels: LogChannelDB;
- bypassChannelBlacklist: Snowflake[];
- noXpChannels: Snowflake[];
- levelRoles: { [level: number]: Snowflake };
- levelUpChannel: Snowflake | null;
-}
-
-export interface GuildModelCreationAttributes {
- id: Snowflake;
- prefix?: string;
- autoPublishChannels?: Snowflake[];
- blacklistedChannels?: Snowflake[];
- blacklistedUsers?: Snowflake[];
- welcomeChannel?: Snowflake;
- muteRole?: Snowflake;
- punishmentEnding?: string;
- disabledCommands?: string[];
- lockdownChannels?: Snowflake[];
- autoModPhases?: BadWordDetails[];
- enabledFeatures?: GuildFeatures[];
- joinRoles?: Snowflake[];
- logChannels?: LogChannelDB;
- bypassChannelBlacklist?: Snowflake[];
- noXpChannels?: Snowflake[];
- levelRoles?: { [level: number]: Snowflake };
- levelUpChannel?: Snowflake;
-}
-
-/**
- * Settings for a guild.
- */
-export class Guild extends BaseModel implements GuildModel {
- /**
- * The ID of the guild
- */
- public declare id: Snowflake;
-
- /**
- * The bot's prefix for the guild
- */
- public declare prefix: string;
-
- /**
- * Channels that will have their messages automatically published
- */
- public declare autoPublishChannels: Snowflake[];
-
- /**
- * Channels where the bot won't respond in.
- */
- public declare blacklistedChannels: Snowflake[];
-
- /**
- * Users that the bot ignores in this guild
- */
- public declare blacklistedUsers: Snowflake[];
-
- /**
- * The channels where the welcome messages are sent
- */
- public declare welcomeChannel: Snowflake | null;
-
- /**
- * The role given out when muting someone
- */
- public declare muteRole: Snowflake | null;
-
- /**
- * The message that gets sent after someone gets a punishment dm
- */
- public declare punishmentEnding: string | null;
-
- /**
- * Guild specific disabled commands
- */
- public declare disabledCommands: string[];
-
- /**
- * Channels that should get locked down when the lockdown command gets used.
- */
- public declare lockdownChannels: Snowflake[];
-
- /**
- * Custom automod phases
- */
- public declare autoModPhases: BadWordDetails[];
-
- /**
- * The features enabled in a guild
- */
- public declare enabledFeatures: GuildFeatures[];
-
- /**
- * The roles to assign to a user if they are not assigned sticky roles
- */
- public declare joinRoles: Snowflake[];
-
- /**
- * The channels where logging messages will be sent.
- */
- public declare logChannels: LogChannelDB;
-
- /**
- * These users will be able to use commands in channels blacklisted
- */
- public declare bypassChannelBlacklist: Snowflake[];
-
- /**
- * Channels where users will not earn xp for leveling.
- */
- public declare noXpChannels: Snowflake[];
-
- /**
- * What roles get given to users when they reach certain levels.
- */
- public declare levelRoles: { [level: number]: Snowflake };
-
- /**
- * The channel to send level up messages in instead of last channel.
- */
- public declare levelUpChannel: Snowflake | null;
-
- /**
- * Initializes the model.
- * @param sequelize The sequelize instance.
- */
- public static initModel(sequelize: Sequelize, client: BushClient): void {
- Guild.init(
- {
- id: { type: DataTypes.STRING, primaryKey: true },
- prefix: { type: DataTypes.TEXT, allowNull: false, defaultValue: client.config.prefix },
- autoPublishChannels: { type: DataTypes.JSONB, allowNull: false, defaultValue: [] },
- blacklistedChannels: { type: DataTypes.JSONB, allowNull: false, defaultValue: [] },
- blacklistedUsers: { type: DataTypes.JSONB, allowNull: false, defaultValue: [] },
- welcomeChannel: { type: DataTypes.STRING, allowNull: true },
- muteRole: { type: DataTypes.STRING, allowNull: true },
- punishmentEnding: { type: DataTypes.TEXT, allowNull: true },
- disabledCommands: { type: DataTypes.JSONB, allowNull: false, defaultValue: [] },
- lockdownChannels: { type: DataTypes.JSONB, allowNull: false, defaultValue: [] },
- autoModPhases: { type: DataTypes.JSONB, allowNull: false, defaultValue: [] },
- enabledFeatures: {
- type: DataTypes.JSONB,
- allowNull: false,
- defaultValue: Object.keys(guildFeaturesObj).filter(
- (key) => guildFeaturesObj[key as keyof typeof guildFeaturesObj].default
- )
- },
- joinRoles: { type: DataTypes.JSONB, allowNull: false, defaultValue: [] },
- logChannels: { type: DataTypes.JSONB, allowNull: false, defaultValue: {} },
- bypassChannelBlacklist: { type: DataTypes.JSONB, allowNull: false, defaultValue: [] },
- noXpChannels: { type: DataTypes.JSONB, allowNull: false, defaultValue: [] },
- levelRoles: { type: DataTypes.JSONB, allowNull: false, defaultValue: {} },
- levelUpChannel: { type: DataTypes.STRING, allowNull: true }
- },
- { sequelize }
- );
- }
-}
-
-export type BaseGuildSetting = 'channel' | 'role' | 'user';
-export type GuildNoArraySetting = 'string' | 'custom' | BaseGuildSetting;
-export type GuildSettingType = GuildNoArraySetting | `${BaseGuildSetting}-array`;
-
-export interface GuildSetting {
- name: string;
- description: string;
- type: GuildSettingType;
- subType: ChannelType[] | undefined;
- configurable: boolean;
- replaceNullWith: () => string | null;
-}
-const asGuildSetting = (et: { [K in keyof T]: PartialBy }) => {
- for (const key in et) {
- et[key].subType ??= undefined;
- et[key].configurable ??= true;
- et[key].replaceNullWith ??= () => null;
- }
- return et as { [K in keyof T]: GuildSetting };
-};
-
-const { default: config } = await import('../../../../config/options.js');
-
-export const guildSettingsObj = asGuildSetting({
- prefix: {
- name: 'Prefix',
- description: 'The phrase required to trigger text commands in this server.',
- type: 'string',
- replaceNullWith: () => config.prefix
- },
- autoPublishChannels: {
- name: 'Auto Publish Channels',
- description: 'Channels were every message is automatically published.',
- type: 'channel-array',
- subType: [ChannelType.GuildNews]
- },
- welcomeChannel: {
- name: 'Welcome Channel',
- description: 'The channel where the bot will send join and leave message.',
- type: 'channel',
- subType: [
- ChannelType.GuildText,
- ChannelType.GuildNews,
- ChannelType.GuildNewsThread,
- ChannelType.GuildPublicThread,
- ChannelType.GuildPrivateThread
- ]
- },
- muteRole: {
- name: 'Mute Role',
- description: 'The role assigned when muting someone.',
- type: 'role'
- },
- punishmentEnding: {
- name: 'Punishment Ending',
- description: 'The message after punishment information to a user in a dm.',
- type: 'string'
- },
- lockdownChannels: {
- name: 'Lockdown Channels',
- description: 'Channels that are locked down when a mass lockdown is specified.',
- type: 'channel-array',
- subType: [ChannelType.GuildText]
- },
- joinRoles: {
- name: 'Join Roles',
- description: 'Roles assigned to users on join who do not have sticky role information.',
- type: 'role-array'
- },
- bypassChannelBlacklist: {
- name: 'Bypass Channel Blacklist',
- description: 'These users will be able to use commands in channels blacklisted.',
- type: 'user-array'
- },
- logChannels: {
- name: 'Log Channels',
- description: 'The channel were logs are sent.',
- type: 'custom',
- subType: [ChannelType.GuildText],
- configurable: false
- },
- autoModPhases: {
- name: 'Automod Phases',
- description: 'Custom phrases to be detected by automod.',
- type: 'custom',
- configurable: false
- },
- noXpChannels: {
- name: 'No Xp Channels',
- description: 'Channels where users will not earn xp for leveling.',
- type: 'channel-array',
- subType: Constants.TextBasedChannelTypes.filter((type) => type !== ChannelType.DM)
- },
- levelRoles: {
- name: 'Level Roles',
- description: 'What roles get given to users when they reach certain levels.',
- type: 'custom',
- configurable: false
- },
- levelUpChannel: {
- name: 'Level Up Channel',
- description: 'The channel to send level up messages in instead of last channel.',
- type: 'channel',
- subType: Constants.TextBasedChannelTypes.filter((type) => type !== ChannelType.DM)
- }
-});
-
-export type GuildSettings = keyof typeof guildSettingsObj;
-export const settingsArr = Object.keys(guildSettingsObj).filter(
- (s) => guildSettingsObj[s as GuildSettings].configurable
-) as GuildSettings[];
-
-interface GuildFeature {
- name: string;
- description: string;
- default: boolean;
- hidden: boolean;
-}
-
-type PartialBy = Omit & Partial>;
-
-const asGuildFeature = (gf: { [K in keyof T]: PartialBy }): {
- [K in keyof T]: GuildFeature;
-} => {
- for (const key in gf) {
- gf[key].hidden ??= false;
- gf[key].default ??= false;
- }
- return gf as { [K in keyof T]: GuildFeature };
-};
-
-export const guildFeaturesObj = asGuildFeature({
- automod: {
- name: 'Automod',
- description: 'Deletes offensive content as well as phishing links.'
- },
- excludeDefaultAutomod: {
- name: 'Exclude Default Automod',
- description: 'Opt out of using the default automod options.'
- },
- excludeAutomodScamLinks: {
- name: 'Exclude Automod Scam Links',
- description: 'Opt out of having automod delete scam links.'
- },
- delScamMentions: {
- name: 'Delete Scam Mentions',
- description: 'Deletes messages with @everyone and @here mentions that have common scam phrases.'
- },
- blacklistedFile: {
- name: 'Blacklisted File',
- description: 'Automatically deletes malicious files.'
- },
- autoPublish: {
- name: 'Auto Publish',
- description: 'Publishes messages in configured announcement channels.'
- },
- // todo implement a better auto thread system
- autoThread: {
- name: 'Auto Thread',
- description: 'Creates a new thread for messages in configured channels.',
- hidden: true
- },
- perspectiveApi: {
- name: 'Perspective API',
- description: 'Use the Perspective API to detect toxicity.',
- hidden: true
- },
- boosterMessageReact: {
- name: 'Booster Message React',
- description: 'Reacts to booster messages with the boost emoji.'
- },
- leveling: {
- name: 'Leveling',
- description: "Tracks users' messages and assigns them xp."
- },
- sendLevelUpMessages: {
- name: 'Send Level Up Messages',
- description: 'Send a message when a user levels up.',
- default: true
- },
- stickyRoles: {
- name: 'Sticky Roles',
- description: 'Restores past roles to a user when they rejoin.'
- },
- reporting: {
- name: 'Reporting',
- description: 'Allow users to make reports.'
- },
- modsCanPunishMods: {
- name: 'Mods Can Punish Mods',
- description: 'Allow moderators to punish other moderators.'
- },
- logManualPunishments: {
- name: 'Log Manual Punishments',
- description: "Adds manual punishment to the user's modlogs and the logging channels.",
- default: true
- },
- punishmentAppeals: {
- name: 'Punishment Appeals',
- description: 'Allow users to appeal their punishments and send the appeal to the configured channel.',
- hidden: true
- },
- highlight: {
- name: 'Highlight',
- description: 'Allows the highlight command to be used.',
- default: true
- }
-});
-
-export const guildLogsObj = {
- automod: {
- description: 'Sends a message in this channel every time automod is activated.',
- configurable: true
- },
- moderation: {
- description: 'Sends a message in this channel every time a moderation action is performed.',
- configurable: true
- },
- report: {
- description: 'Logs user reports.',
- configurable: true
- },
- error: {
- description: 'Logs errors that occur with the bot.',
- configurable: true
- },
- appeals: {
- description: 'Where punishment appeals are sent.',
- configurable: false
- }
-};
-
-export type GuildLogType = keyof typeof guildLogsObj;
-export const guildLogsArr = Object.keys(guildLogsObj).filter(
- (s) => guildLogsObj[s as GuildLogType].configurable
-) as GuildLogType[];
-type LogChannelDB = { [x in keyof typeof guildLogsObj]?: Snowflake };
-
-export type GuildFeatures = keyof typeof guildFeaturesObj;
-export const guildFeaturesArr: GuildFeatures[] = Object.keys(guildFeaturesObj).filter(
- (f) => !guildFeaturesObj[f as keyof typeof guildFeaturesObj].hidden
-) as GuildFeatures[];
diff --git a/src/lib/models/instance/Highlight.ts b/src/lib/models/instance/Highlight.ts
deleted file mode 100644
index 5889fad..0000000
--- a/src/lib/models/instance/Highlight.ts
+++ /dev/null
@@ -1,81 +0,0 @@
-import { type Snowflake } from 'discord.js';
-import { nanoid } from 'nanoid';
-import { type Sequelize } from 'sequelize';
-import { BaseModel } from '../BaseModel.js';
-const { DataTypes } = (await import('sequelize')).default;
-
-export interface HighlightModel {
- pk: string;
- user: Snowflake;
- guild: Snowflake;
- words: HighlightWord[];
- blacklistedChannels: Snowflake[];
- blacklistedUsers: Snowflake[];
-}
-
-export interface HighLightCreationAttributes {
- pk?: string;
- user: Snowflake;
- guild: Snowflake;
- words?: HighlightWord[];
- blacklistedChannels?: Snowflake[];
- blacklistedUsers?: Snowflake[];
-}
-
-export interface HighlightWord {
- word: string;
- regex: boolean;
-}
-
-/**
- * List of words that should cause the user to be notified for if found in the specified guild.
- */
-export class Highlight extends BaseModel implements HighlightModel {
- /**
- * The primary key of the highlight.
- */
- public declare pk: string;
-
- /**
- * The user that the highlight is for.
- */
- public declare user: Snowflake;
-
- /**
- * The guild to look for highlights in.
- */
- public declare guild: Snowflake;
-
- /**
- * The words to look for.
- */
- public declare words: HighlightWord[];
-
- /**
- * Channels that the user choose to ignore highlights in.
- */
- public declare blacklistedChannels: Snowflake[];
-
- /**
- * Users that the user choose to ignore highlights from.
- */
- public declare blacklistedUsers: Snowflake[];
-
- /**
- * Initializes the model.
- * @param sequelize The sequelize instance.
- */
- public static initModel(sequelize: Sequelize): void {
- Highlight.init(
- {
- pk: { type: DataTypes.STRING, primaryKey: true, defaultValue: nanoid },
- user: { type: DataTypes.STRING, allowNull: false },
- guild: { type: DataTypes.STRING, allowNull: false },
- words: { type: DataTypes.JSONB, allowNull: false, defaultValue: [] },
- blacklistedChannels: { type: DataTypes.JSONB, allowNull: false, defaultValue: [] },
- blacklistedUsers: { type: DataTypes.JSONB, allowNull: false, defaultValue: [] }
- },
- { sequelize }
- );
- }
-}
diff --git a/src/lib/models/instance/Level.ts b/src/lib/models/instance/Level.ts
deleted file mode 100644
index d8d16f0..0000000
--- a/src/lib/models/instance/Level.ts
+++ /dev/null
@@ -1,70 +0,0 @@
-import { type Snowflake } from 'discord.js';
-import { type Sequelize } from 'sequelize';
-import { BaseModel } from '../BaseModel.js';
-const { DataTypes } = (await import('sequelize')).default;
-
-export interface LevelModel {
- user: Snowflake;
- guild: Snowflake;
- xp: number;
-}
-
-export interface LevelModelCreationAttributes {
- user: Snowflake;
- guild: Snowflake;
- xp?: number;
-}
-
-/**
- * Leveling information for a user in a guild.
- */
-export class Level extends BaseModel implements LevelModel {
- /**
- * The user's id.
- */
- public declare user: Snowflake;
-
- /**
- * The guild where the user is gaining xp.
- */
- public declare guild: Snowflake;
-
- /**
- * The user's xp.
- */
- public declare xp: number;
-
- /**
- * The user's level.
- */
- public get level(): number {
- return Level.convertXpToLevel(this.xp);
- }
-
- /**
- * Initializes the model.
- * @param sequelize The sequelize instance.
- */
- public static initModel(sequelize: Sequelize): void {
- Level.init(
- {
- user: { type: DataTypes.STRING, allowNull: false },
- guild: { type: DataTypes.STRING, allowNull: false },
- xp: { type: DataTypes.INTEGER, allowNull: false, defaultValue: 0 }
- },
- { sequelize }
- );
- }
-
- public static convertXpToLevel(xp: number): number {
- return Math.floor((-25 + Math.sqrt(625 + 200 * xp)) / 100);
- }
-
- public static convertLevelToXp(level: number): number {
- return 50 * level * level + 25 * level; // 50x² + 25x
- }
-
- public static genRandomizedXp(): number {
- return Math.floor(Math.random() * (40 - 15 + 1)) + 15;
- }
-}
diff --git a/src/lib/models/instance/ModLog.ts b/src/lib/models/instance/ModLog.ts
deleted file mode 100644
index c25f043..0000000
--- a/src/lib/models/instance/ModLog.ts
+++ /dev/null
@@ -1,127 +0,0 @@
-import { type Snowflake } from 'discord.js';
-import { nanoid } from 'nanoid';
-import { type Sequelize } from 'sequelize';
-import { BaseModel } from '../BaseModel.js';
-const { DataTypes } = (await import('sequelize')).default;
-
-export enum ModLogType {
- PERM_BAN = 'PERM_BAN',
- TEMP_BAN = 'TEMP_BAN',
- UNBAN = 'UNBAN',
- KICK = 'KICK',
- PERM_MUTE = 'PERM_MUTE',
- TEMP_MUTE = 'TEMP_MUTE',
- UNMUTE = 'UNMUTE',
- WARN = 'WARN',
- PERM_PUNISHMENT_ROLE = 'PERM_PUNISHMENT_ROLE',
- TEMP_PUNISHMENT_ROLE = 'TEMP_PUNISHMENT_ROLE',
- REMOVE_PUNISHMENT_ROLE = 'REMOVE_PUNISHMENT_ROLE',
- PERM_CHANNEL_BLOCK = 'PERM_CHANNEL_BLOCK',
- TEMP_CHANNEL_BLOCK = 'TEMP_CHANNEL_BLOCK',
- CHANNEL_UNBLOCK = 'CHANNEL_UNBLOCK',
- TIMEOUT = 'TIMEOUT',
- REMOVE_TIMEOUT = 'REMOVE_TIMEOUT'
-}
-
-export interface ModLogModel {
- id: string;
- type: ModLogType;
- user: Snowflake;
- moderator: Snowflake;
- reason: string | null;
- duration: number | null;
- guild: Snowflake;
- evidence: string;
- pseudo: boolean;
- hidden: boolean;
-}
-
-export interface ModLogModelCreationAttributes {
- id?: string;
- type: ModLogType;
- user: Snowflake;
- moderator: Snowflake;
- reason?: string | null;
- duration?: number;
- guild: Snowflake;
- evidence?: string;
- pseudo?: boolean;
- hidden?: boolean;
-}
-
-/**
- * A mod log case.
- */
-export class ModLog extends BaseModel implements ModLogModel {
- /**
- * The primary key of the modlog entry.
- */
- public declare id: string;
-
- /**
- * The type of punishment.
- */
- public declare type: ModLogType;
-
- /**
- * The user being punished.
- */
- public declare user: Snowflake;
-
- /**
- * The user carrying out the punishment.
- */
- public declare moderator: Snowflake;
-
- /**
- * The reason the user is getting punished.
- */
- public declare reason: string | null;
-
- /**
- * The amount of time the user is getting punished for.
- */
- public declare duration: number | null;
-
- /**
- * The guild the user is getting punished in.
- */
- public declare guild: Snowflake;
-
- /**
- * Evidence of what the user is getting punished for.
- */
- public declare evidence: string;
-
- /**
- * Not an actual modlog just used so a punishment entry can be made.
- */
- public declare pseudo: boolean;
-
- /**
- * Hides from the modlog command unless show hidden is specified.
- */
- public declare hidden: boolean;
-
- /**
- * Initializes the model.
- * @param sequelize The sequelize instance.
- */
- public static initModel(sequelize: Sequelize): void {
- ModLog.init(
- {
- id: { type: DataTypes.STRING, primaryKey: true, allowNull: false, defaultValue: nanoid },
- type: { type: DataTypes.STRING, allowNull: false }, //? This is not an enum because of a sequelize issue: https://github.com/sequelize/sequelize/issues/2554
- user: { type: DataTypes.STRING, allowNull: false },
- moderator: { type: DataTypes.STRING, allowNull: false },
- duration: { type: DataTypes.STRING, allowNull: true },
- reason: { type: DataTypes.TEXT, allowNull: true },
- guild: { type: DataTypes.STRING, references: { model: 'Guilds', key: 'id' } },
- evidence: { type: DataTypes.TEXT, allowNull: true },
- pseudo: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false },
- hidden: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false }
- },
- { sequelize }
- );
- }
-}
diff --git a/src/lib/models/instance/Reminder.ts b/src/lib/models/instance/Reminder.ts
deleted file mode 100644
index 964ea63..0000000
--- a/src/lib/models/instance/Reminder.ts
+++ /dev/null
@@ -1,84 +0,0 @@
-import { Snowflake } from 'discord.js';
-import { nanoid } from 'nanoid';
-import { type Sequelize } from 'sequelize';
-import { BaseModel } from '../BaseModel.js';
-const { DataTypes } = (await import('sequelize')).default;
-
-export interface ReminderModel {
- id: string;
- user: Snowflake;
- messageUrl: string;
- content: string;
- created: Date;
- expires: Date;
- notified: boolean;
-}
-
-export interface ReminderModelCreationAttributes {
- id?: string;
- user: Snowflake;
- messageUrl: string;
- content: string;
- created: Date;
- expires: Date;
- notified?: boolean;
-}
-
-/**
- * Represents a reminder the a user has set.
- */
-export class Reminder extends BaseModel implements ReminderModel {
- /**
- * The id of the reminder.
- */
- public declare id: string;
-
- /**
- * The user that the reminder is for.
- */
- public declare user: Snowflake;
-
- /**
- * The url of the message where the reminder was created.
- */
- public declare messageUrl: string;
-
- /**
- * The content of the reminder.
- */
- public declare content: string;
-
- /**
- * The date the reminder was created.
- */
- public declare created: Date;
-
- /**
- * The date when the reminder expires.
- */
- public declare expires: Date;
-
- /**
- * Whether the user has been notified about the reminder.
- */
- public declare notified: boolean;
-
- /**
- * Initializes the model.
- * @param sequelize The sequelize instance.
- */
- public static initModel(sequelize: Sequelize): void {
- Reminder.init(
- {
- id: { type: DataTypes.STRING, primaryKey: true, defaultValue: nanoid },
- user: { type: DataTypes.STRING, allowNull: false },
- messageUrl: { type: DataTypes.STRING, allowNull: false },
- content: { type: DataTypes.TEXT, allowNull: false },
- created: { type: DataTypes.DATE, allowNull: false },
- expires: { type: DataTypes.DATE, allowNull: false },
- notified: { type: DataTypes.BOOLEAN, allowNull: false, defaultValue: false }
- },
- { sequelize }
- );
- }
-}
diff --git a/src/lib/models/instance/StickyRole.ts b/src/lib/models/instance/StickyRole.ts
deleted file mode 100644
index 00e98ce..0000000
--- a/src/lib/models/instance/StickyRole.ts
+++ /dev/null
@@ -1,58 +0,0 @@
-import { type Snowflake } from 'discord.js';
-import { type Sequelize } from 'sequelize';
-import { BaseModel } from '../BaseModel.js';
-const { DataTypes } = (await import('sequelize')).default;
-
-export interface StickyRoleModel {
- user: Snowflake;
- guild: Snowflake;
- roles: Snowflake[];
- nickname: string;
-}
-export interface StickyRoleModelCreationAttributes {
- user: Snowflake;
- guild: Snowflake;
- roles: Snowflake[];
- nickname?: string;
-}
-
-/**
- * Information about a user's roles and nickname when they leave a guild.
- */
-export class StickyRole extends BaseModel implements StickyRoleModel {
- /**
- * The id of the user the roles belongs to.
- */
- public declare user: Snowflake;
-
- /**
- * The guild where this should happen.
- */
- public declare guild: Snowflake;
-
- /**
- * The roles that the user should have returned
- */
- public declare roles: Snowflake[];
-
- /**
- * The user's previous nickname
- */
- public declare nickname: string;
-
- /**
- * Initializes the model.
- * @param sequelize The sequelize instance.
- */
- public static initModel(sequelize: Sequelize): void {
- StickyRole.init(
- {
- user: { type: DataTypes.STRING, allowNull: false },
- guild: { type: DataTypes.STRING, allowNull: false },
- roles: { type: DataTypes.JSONB, allowNull: false, defaultValue: [] },
- nickname: { type: DataTypes.STRING, allowNull: true }
- },
- { sequelize }
- );
- }
-}
diff --git a/src/lib/models/shared/Global.ts b/src/lib/models/shared/Global.ts
deleted file mode 100644
index b1aa0cc..0000000
--- a/src/lib/models/shared/Global.ts
+++ /dev/null
@@ -1,67 +0,0 @@
-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 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/GuildCount.ts b/src/lib/models/shared/GuildCount.ts
deleted file mode 100644
index 51e571a..0000000
--- a/src/lib/models/shared/GuildCount.ts
+++ /dev/null
@@ -1,39 +0,0 @@
-import { type Sequelize } from 'sequelize';
-import { Environment } from '../../../../config/Config.js';
-const { DataTypes, Model } = (await import('sequelize')).default;
-
-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 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/src/lib/models/shared/MemberCount.ts b/src/lib/models/shared/MemberCount.ts
deleted file mode 100644
index ea8795c..0000000
--- a/src/lib/models/shared/MemberCount.ts
+++ /dev/null
@@ -1,38 +0,0 @@
-import { type Sequelize } from 'sequelize';
-const { DataTypes, Model } = (await import('sequelize')).default;
-
-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 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/src/lib/models/shared/Shared.ts b/src/lib/models/shared/Shared.ts
deleted file mode 100644
index 4d13011..0000000
--- a/src/lib/models/shared/Shared.ts
+++ /dev/null
@@ -1,84 +0,0 @@
-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;
-}
-
-/**
- * Data shared between all bot instances.
- */
-export class Shared extends BaseModel 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
deleted file mode 100644
index 8e2e0b3..0000000
--- a/src/lib/models/shared/Stat.ts
+++ /dev/null
@@ -1,72 +0,0 @@
-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 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', `${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', `${val}`);
- },
- allowNull: false,
- defaultValue: `${0n}`
- }
- },
- { sequelize }
- );
- }
-}
--
cgit