From 4176b6258e44e4a095376aaf0f4c687244243a69 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Thu, 24 Jun 2021 00:56:16 -0400 Subject: feat(*): Began working on other punishment commands etc --- src/lib/models/Ban.ts | 13 +++--- src/lib/models/Global.ts | 2 +- src/lib/models/Guild.ts | 22 ++++++++-- src/lib/models/Level.ts | 1 - src/lib/models/Modlog.ts | 38 ++++++++-------- src/lib/models/Mute.ts | 90 ++++++++++++++++++++++++++++++++++++++ src/lib/models/PunishmentRole.ts | 93 ++++++++++++++++++++++++++++++++++++++++ src/lib/models/index.ts | 4 +- 8 files changed, 232 insertions(+), 31 deletions(-) create mode 100644 src/lib/models/Mute.ts create mode 100644 src/lib/models/PunishmentRole.ts (limited to 'src/lib/models') diff --git a/src/lib/models/Ban.ts b/src/lib/models/Ban.ts index 8ba55ec..f4463b8 100644 --- a/src/lib/models/Ban.ts +++ b/src/lib/models/Ban.ts @@ -1,7 +1,6 @@ import { Snowflake } from 'discord.js'; import { DataTypes, Sequelize } from 'sequelize'; import { v4 as uuidv4 } from 'uuid'; -import * as Models from './'; import { BaseModel } from './BaseModel'; export interface BanModel { @@ -64,7 +63,7 @@ export class Ban extends BaseModel impleme type: DataTypes.STRING, allowNull: false, references: { - model: Models.Guild, + model: 'Guilds', key: 'id' } }, @@ -78,11 +77,11 @@ export class Ban extends BaseModel impleme }, modlog: { type: DataTypes.STRING, - allowNull: false - // references: { - // model: Models.Modlog, - // key: 'id' - // } + allowNull: false, + references: { + model: 'ModLogs', + key: 'id' + } } }, { sequelize: sequelize } diff --git a/src/lib/models/Global.ts b/src/lib/models/Global.ts index abe0ab3..842f14b 100644 --- a/src/lib/models/Global.ts +++ b/src/lib/models/Global.ts @@ -80,7 +80,7 @@ export class Global extends BaseModel; +export type GuildModelCreationAttributes = Optional< + GuildModel, + 'prefix' | 'autoPublishChannels' | 'blacklistedChannels' | 'welcomeChannel' | 'muteRole' +>; export class Guild extends BaseModel implements GuildModel { id: string; prefix: string; autoPublishChannels: string[]; blacklistedChannels: Snowflake[]; - static initModel(seqeulize: Sequelize, client: BushClient): void { + welcomeChannel: Snowflake; + muteRole: Snowflake; + + static initModel(sequelize: Sequelize, client: BushClient): void { Guild.init( { id: { @@ -48,9 +56,17 @@ export class Guild extends BaseModel i return this.setDataValue('blacklistedChannels', JSON.stringify(val) as unknown as Snowflake[]); }, allowNull: true + }, + welcomeChannel: { + type: DataTypes.STRING, + allowNull: true + }, + muteRole: { + type: DataTypes.STRING, + allowNull: true } }, - { sequelize: seqeulize } + { sequelize: sequelize } ); } } diff --git a/src/lib/models/Level.ts b/src/lib/models/Level.ts index 426ec1a..e1f30f4 100644 --- a/src/lib/models/Level.ts +++ b/src/lib/models/Level.ts @@ -46,7 +46,6 @@ export class Level extends BaseModel { break; } else { i++; - continue; } } return lvl - 1; // I have to do this don't question it ok diff --git a/src/lib/models/Modlog.ts b/src/lib/models/Modlog.ts index 15c5030..94c464d 100644 --- a/src/lib/models/Modlog.ts +++ b/src/lib/models/Modlog.ts @@ -2,18 +2,20 @@ import { DataTypes, Sequelize } from 'sequelize'; import { v4 as uuidv4 } from 'uuid'; import { BaseModel } from './BaseModel'; -export enum ModlogType { +export enum ModLogType { BAN = 'BAN', - TEMPBAN = 'TEMPBAN', + TEMP_BAN = 'TEMP_BAN', KICK = 'KICK', MUTE = 'MUTE', - TEMPMUTE = 'TEMPMUTE', - WARN = 'WARN' + TEMP_MUTE = 'TEMP_MUTE', + WARN = 'WARN', + PUNISHMENT_ROLE = 'PUNISHMENT_ROLE', + TEMP_PUNISHMENT_ROLE = 'TEMP_PUNISHMENT_ROLE' } -export interface ModlogModel { +export interface ModLogModel { id: string; - type: ModlogType; + type: ModLogType; user: string; moderator: string; reason: string; @@ -21,9 +23,9 @@ export interface ModlogModel { guild: string; } -export interface ModlogModelCreationAttributes { +export interface ModLogModelCreationAttributes { id?: string; - type: ModlogType; + type: ModLogType; user: string; moderator: string; reason?: string; @@ -31,9 +33,9 @@ export interface ModlogModelCreationAttributes { guild: string; } -export class Modlog extends BaseModel implements ModlogModel { +export class ModLog extends BaseModel implements ModLogModel { id: string; - type: ModlogType; + type: ModLogType; user: string; moderator: string; guild: string; @@ -41,7 +43,7 @@ export class Modlog 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 reason they are muted (optional) + */ + reason: string | null; + /** + * 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 + }, + reason: { + type: DataTypes.STRING, + 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 new file mode 100644 index 0000000..3326dca --- /dev/null +++ b/src/lib/models/PunishmentRole.ts @@ -0,0 +1,93 @@ +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: string; + guild: string; + reason: string; + expires: Date; + modlog: string; +} +export interface PunishmentRoleModelCreationAttributes { + id?: string; + user: string; + guild: string; + reason?: string; + 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 guild they received a role in + */ + guild: Snowflake; + /** + * The reason they received a role (optional) + */ + reason: string | null; + /** + * 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 + }, + guild: { + type: DataTypes.STRING, + allowNull: false, + references: { + model: 'Guilds', + key: 'id' + } + }, + expires: { + type: DataTypes.DATE, + allowNull: true + }, + reason: { + type: DataTypes.STRING, + allowNull: true + }, + modlog: { + type: DataTypes.STRING, + allowNull: false, + references: { + model: 'ModLogs', + key: 'id' + } + } + }, + { sequelize: sequelize } + ); + } +} diff --git a/src/lib/models/index.ts b/src/lib/models/index.ts index e38ad69..794c335 100644 --- a/src/lib/models/index.ts +++ b/src/lib/models/index.ts @@ -3,5 +3,7 @@ export * from './BaseModel'; export * from './Global'; export * from './Guild'; export * from './Level'; -export * from './Modlog'; +export * from './ModLog'; +export * from './Mute'; +export * from './PunishmentRole'; export * from './StickyRole'; -- cgit