diff options
Diffstat (limited to 'src/lib/models')
-rw-r--r-- | src/lib/models/Ban.ts | 13 | ||||
-rw-r--r-- | src/lib/models/Global.ts | 2 | ||||
-rw-r--r-- | src/lib/models/Guild.ts | 22 | ||||
-rw-r--r-- | src/lib/models/Level.ts | 1 | ||||
-rw-r--r-- | src/lib/models/Modlog.ts | 38 | ||||
-rw-r--r-- | src/lib/models/Mute.ts | 90 | ||||
-rw-r--r-- | src/lib/models/PunishmentRole.ts | 93 | ||||
-rw-r--r-- | src/lib/models/index.ts | 4 |
8 files changed, 232 insertions, 31 deletions
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<BanModel, BanModelCreationAttributes> impleme type: DataTypes.STRING, allowNull: false, references: { - model: Models.Guild, + model: 'Guilds', key: 'id' } }, @@ -78,11 +77,11 @@ export class Ban extends BaseModel<BanModel, BanModelCreationAttributes> 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<GlobalModel, GlobalModelCreationAttributes allowNull: true } }, - { sequelize } + { sequelize: sequelize } ); } } diff --git a/src/lib/models/Guild.ts b/src/lib/models/Guild.ts index c4ae53e..480cc60 100644 --- a/src/lib/models/Guild.ts +++ b/src/lib/models/Guild.ts @@ -8,16 +8,24 @@ export interface GuildModel { prefix: string; autoPublishChannels: string[]; blacklistedChannels: Snowflake[]; + welcomeChannel: Snowflake; + muteRole: Snowflake; } -export type GuildModelCreationAttributes = Optional<GuildModel, 'prefix' | 'autoPublishChannels' | 'blacklistedChannels'>; +export type GuildModelCreationAttributes = Optional< + GuildModel, + 'prefix' | 'autoPublishChannels' | 'blacklistedChannels' | 'welcomeChannel' | 'muteRole' +>; export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> 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<GuildModel, GuildModelCreationAttributes> 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<LevelModel, LevelModelCreationAttributes> { 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<ModlogModel, ModlogModelCreationAttributes> implements ModlogModel { +export class ModLog extends BaseModel<ModLogModel, ModLogModelCreationAttributes> implements ModLogModel { id: string; - type: ModlogType; + type: ModLogType; user: string; moderator: string; guild: string; @@ -41,7 +43,7 @@ export class Modlog extends BaseModel<ModlogModel, ModlogModelCreationAttributes duration: number | null; static initModel(sequelize: Sequelize): void { - Modlog.init( + ModLog.init( { id: { type: DataTypes.STRING, @@ -50,7 +52,7 @@ export class Modlog extends BaseModel<ModlogModel, ModlogModelCreationAttributes defaultValue: uuidv4 }, type: { - type: new DataTypes.ENUM('BAN', 'TEMPBAN', 'MUTE', 'TEMPMUTE', 'KICK', 'WARN'), + type: DataTypes.STRING, //# This is not an enum because of a sequelize issue: https://github.com/sequelize/sequelize/issues/2554 allowNull: false }, user: { @@ -70,14 +72,14 @@ export class Modlog extends BaseModel<ModlogModel, ModlogModelCreationAttributes allowNull: true }, guild: { - type: DataTypes.STRING - // references: { - // model: Models.Guild, - // key: 'id' - // } + type: DataTypes.STRING, + references: { + model: 'Guilds', + key: 'id' + } } }, - { sequelize } + { sequelize: sequelize } ); } } diff --git a/src/lib/models/Mute.ts b/src/lib/models/Mute.ts new file mode 100644 index 0000000..273d5b1 --- /dev/null +++ b/src/lib/models/Mute.ts @@ -0,0 +1,90 @@ +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: string; + guild: string; + reason: string; + expires: Date; + modlog: string; +} +export interface MuteModelCreationAttributes { + id?: string; + user: string; + guild: string; + reason?: string; + expires?: Date; + modlog: string; +} + +export class Mute extends BaseModel<MuteModel, MuteModelCreationAttributes> 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<PunishmentRoleModel, PunishmentRoleModelCreationAttributes> + 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'; |