From b015bec7f66526ec5e959ae99865845f4db4b181 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Fri, 23 Jul 2021 22:02:44 -0400 Subject: feat: some shit - fix breaking changes - refactored active punishments into one table - made listeners args have stricter types --- src/lib/models/ActivePunishment.ts | 110 +++++++++++++++++++++++++++++++++++++ src/lib/models/Ban.ts | 80 --------------------------- src/lib/models/ModLog.ts | 5 +- src/lib/models/Mute.ts | 80 --------------------------- src/lib/models/PunishmentRole.ts | 93 ------------------------------- 5 files changed, 114 insertions(+), 254 deletions(-) create mode 100644 src/lib/models/ActivePunishment.ts delete mode 100644 src/lib/models/Ban.ts delete mode 100644 src/lib/models/Mute.ts delete mode 100644 src/lib/models/PunishmentRole.ts (limited to 'src/lib/models') diff --git a/src/lib/models/ActivePunishment.ts b/src/lib/models/ActivePunishment.ts new file mode 100644 index 0000000..9fcafbe --- /dev/null +++ b/src/lib/models/ActivePunishment.ts @@ -0,0 +1,110 @@ +import { Snowflake } from 'discord.js'; +import { DataTypes, Sequelize } from 'sequelize'; +import { v4 as uuidv4 } from 'uuid'; +import { BaseModel } from './BaseModel'; + +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; + modlog: string; +} +export interface ActivePunishmentModelCreationAttributes { + id?: string; + type: ActivePunishmentType; + user: Snowflake; + guild: Snowflake; + extraInfo?: Snowflake; + expires?: Date; + modlog: string; +} + +export class ActivePunishment + extends BaseModel + implements ActivePunishmentModel +{ + /** + * The ID of this punishment (no real use just for a primary key) + */ + id: string; + /** + * The type of punishment. + */ + type: ActivePunishmentType; + /** + * The user who is punished. + */ + user: Snowflake; + /** + * The guild they are punished in. + */ + guild: Snowflake; + /** + * Additional info about the punishment if applicable. The channel id for channel blocks and role for punishment roles. + */ + extraInfo: Snowflake; + /** + * The date when this punishment expires (optional). + */ + expires: Date | null; + /** + * The reference to the modlog entry. + */ + modlog: string; + + static initModel(sequelize: Sequelize): void { + ActivePunishment.init( + { + id: { + type: DataTypes.STRING, + primaryKey: true, + allowNull: false, + defaultValue: uuidv4 + }, + 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.DATE, + allowNull: true + }, + expires: { + type: DataTypes.DATE, + allowNull: true + }, + modlog: { + type: DataTypes.STRING, + allowNull: false, + references: { + model: 'ModLogs', + key: 'id' + } + } + }, + { sequelize: sequelize } + ); + } +} diff --git a/src/lib/models/Ban.ts b/src/lib/models/Ban.ts deleted file mode 100644 index 1bdda6f..0000000 --- a/src/lib/models/Ban.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { Snowflake } from 'discord.js'; -import { DataTypes, Sequelize } from 'sequelize'; -import { v4 as uuidv4 } from 'uuid'; -import { BaseModel } from './BaseModel'; - -export interface BanModel { - id: string; - user: Snowflake; - guild: Snowflake; - expires: Date; - modlog: string; -} -export interface BanModelCreationAttributes { - id?: string; - user: Snowflake; - guild: Snowflake; - expires?: Date; - modlog: string; -} - -export class Ban extends BaseModel implements BanModel { - /** - * The ID of this ban (no real use just for a primary key) - */ - id: string; - /** - * The user who is banned - */ - user: Snowflake; - /** - * The guild they are banned from - */ - guild: Snowflake; - /** - * The date at which this ban expires and should be unbanned (optional) - */ - expires: Date | null; - /** - * The ref to the modlog entry - */ - modlog: string; - - static initModel(sequelize: Sequelize): void { - Ban.init( - { - id: { - type: DataTypes.STRING, - primaryKey: true, - allowNull: false, - defaultValue: uuidv4 - }, - user: { - type: DataTypes.STRING, - allowNull: false - }, - guild: { - type: DataTypes.STRING, - allowNull: false, - references: { - model: 'Guilds', - key: 'id' - } - }, - expires: { - type: DataTypes.DATE, - allowNull: true - }, - modlog: { - type: DataTypes.STRING, - allowNull: false, - references: { - model: 'ModLogs', - key: 'id' - } - } - }, - { sequelize: sequelize } - ); - } -} diff --git a/src/lib/models/ModLog.ts b/src/lib/models/ModLog.ts index 40dc86d..3375751 100644 --- a/src/lib/models/ModLog.ts +++ b/src/lib/models/ModLog.ts @@ -14,7 +14,10 @@ export enum ModLogType { WARN = 'WARN', PERM_PUNISHMENT_ROLE = 'PERM_PUNISHMENT_ROLE', TEMP_PUNISHMENT_ROLE = 'TEMP_PUNISHMENT_ROLE', - REMOVE_PUNISHMENT_ROLE = 'REMOVE_PUNISHMENT_ROLE' + REMOVE_PUNISHMENT_ROLE = 'REMOVE_PUNISHMENT_ROLE', + PERM_CHANNEL_BLOCK = 'PERM_CHANNEL_BLOCK', + TEMP_CHANNEL_BLOCK = 'TEMP_CHANNEL_BLOCK', + CHANNEL_UNBLOCK = 'CHANNEL_UNBLOCK' } export interface ModLogModel { diff --git a/src/lib/models/Mute.ts b/src/lib/models/Mute.ts deleted file mode 100644 index 4208d02..0000000 --- a/src/lib/models/Mute.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { Snowflake } from 'discord.js'; -import { DataTypes, Sequelize } from 'sequelize'; -import { v4 as uuidv4 } from 'uuid'; -import { BaseModel } from './BaseModel'; - -export interface MuteModel { - id: string; - user: Snowflake; - guild: Snowflake; - expires: Date; - modlog: string; -} -export interface MuteModelCreationAttributes { - id?: string; - user: Snowflake; - guild: Snowflake; - expires?: Date; - modlog: string; -} - -export class Mute extends BaseModel implements MuteModel { - /** - * The ID of this mute (no real use just for a primary key) - */ - id: string; - /** - * The user who is muted - */ - user: Snowflake; - /** - * The guild they are muted in - */ - guild: Snowflake; - /** - * The date at which this Mute expires and should be unmuted (optional) - */ - expires: Date | null; - /** - * The ref to the modlog entry - */ - modlog: string; - - static initModel(sequelize: Sequelize): void { - Mute.init( - { - id: { - type: DataTypes.STRING, - primaryKey: true, - allowNull: false, - defaultValue: uuidv4 - }, - user: { - type: DataTypes.STRING, - allowNull: false - }, - guild: { - type: DataTypes.STRING, - allowNull: false, - references: { - model: 'Guilds', - key: 'id' - } - }, - expires: { - type: DataTypes.DATE, - allowNull: true - }, - modlog: { - type: DataTypes.STRING, - allowNull: false, - references: { - model: 'ModLogs', - key: 'id' - } - } - }, - { sequelize: sequelize } - ); - } -} diff --git a/src/lib/models/PunishmentRole.ts b/src/lib/models/PunishmentRole.ts deleted file mode 100644 index 0b54f31..0000000 --- a/src/lib/models/PunishmentRole.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { Snowflake } from 'discord.js'; -import { DataTypes, Sequelize } from 'sequelize'; -import { v4 as uuidv4 } from 'uuid'; -import { BaseModel } from './BaseModel'; - -export interface PunishmentRoleModel { - id: string; - user: Snowflake; - role: Snowflake; - guild: Snowflake; - expires: Date; - modlog: string; -} -export interface PunishmentRoleModelCreationAttributes { - id?: string; - user: Snowflake; - role?: Snowflake; - guild: Snowflake; - expires?: Date; - modlog: string; -} - -export class PunishmentRole - extends BaseModel - implements PunishmentRoleModel -{ - /** - * The ID of this punishment role (no real use just for a primary key) - */ - id: string; - /** - * The user who received a role - */ - user: Snowflake; - /** - * The role added to the user. - */ - role: Snowflake; - /** - * The guild they received a role in - */ - guild: Snowflake; - /** - * The date at which this role expires and should be removed (optional) - */ - expires: Date | null; - /** - * The ref to the modlog entry - */ - modlog: string; - - static initModel(sequelize: Sequelize): void { - PunishmentRole.init( - { - id: { - type: DataTypes.STRING, - primaryKey: true, - allowNull: false, - defaultValue: uuidv4 - }, - user: { - type: DataTypes.STRING, - allowNull: false - }, - role: { - type: DataTypes.STRING, - allowNull: false - }, - guild: { - type: DataTypes.STRING, - allowNull: false, - references: { - model: 'Guilds', - key: 'id' - } - }, - expires: { - type: DataTypes.DATE, - allowNull: true - }, - modlog: { - type: DataTypes.STRING, - allowNull: false, - references: { - model: 'ModLogs', - key: 'id' - } - } - }, - { sequelize: sequelize } - ); - } -} -- cgit