diff options
author | TymanWasTaken <tyman@tyman.tech> | 2021-05-16 21:40:52 -0400 |
---|---|---|
committer | TymanWasTaken <tyman@tyman.tech> | 2021-05-16 21:40:52 -0400 |
commit | 284e1d1d693486f6c50cdb8b38f01cdf74eb63d2 (patch) | |
tree | 1c05e9bb592018f82302688180e87b4bf1305ca5 /src/lib/models | |
parent | 372718e567e060cead16dde5d6d190666b4dd575 (diff) | |
download | tanzanite-284e1d1d693486f6c50cdb8b38f01cdf74eb63d2.tar.gz tanzanite-284e1d1d693486f6c50cdb8b38f01cdf74eb63d2.tar.bz2 tanzanite-284e1d1d693486f6c50cdb8b38f01cdf74eb63d2.zip |
fix logging for slash command syncing, rename a few files
Diffstat (limited to 'src/lib/models')
-rw-r--r-- | src/lib/models/Ban.ts | 44 | ||||
-rw-r--r-- | src/lib/models/Guild.ts | 19 | ||||
-rw-r--r-- | src/lib/models/Level.ts | 19 | ||||
-rw-r--r-- | src/lib/models/Modlog.ts | 50 |
4 files changed, 131 insertions, 1 deletions
diff --git a/src/lib/models/Ban.ts b/src/lib/models/Ban.ts index 032a48b..c30c4c5 100644 --- a/src/lib/models/Ban.ts +++ b/src/lib/models/Ban.ts @@ -1,4 +1,7 @@ +import { DataTypes, Sequelize } from 'sequelize'; import { BaseModel } from './BaseModel'; +import * as Models from './'; +import { v4 as uuidv4 } from 'uuid'; export interface BanModel { id: string; @@ -44,4 +47,45 @@ export class Ban * 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: Models.Guild, + key: 'id' + } + }, + expires: { + type: DataTypes.DATE, + allowNull: true + }, + reason: { + type: DataTypes.STRING, + allowNull: true + }, + modlog: { + type: DataTypes.STRING, + allowNull: false, + references: { + model: Models.Modlog + } + } + }, + { sequelize: sequelize } + ); + } } diff --git a/src/lib/models/Guild.ts b/src/lib/models/Guild.ts index 3e6c6bf..e4e317f 100644 --- a/src/lib/models/Guild.ts +++ b/src/lib/models/Guild.ts @@ -1,4 +1,5 @@ -import { Optional } from 'sequelize'; +import { DataTypes, Optional, Sequelize } from 'sequelize'; +import { BotClient } from '../extensions/BotClient'; import { BaseModel } from './BaseModel'; export interface GuildModel { @@ -12,4 +13,20 @@ export class Guild implements GuildModel { id: string; prefix: string; + static initModel(seqeulize: Sequelize, client: BotClient): void { + Guild.init( + { + id: { + type: DataTypes.STRING, + primaryKey: true + }, + prefix: { + type: DataTypes.STRING, + allowNull: false, + defaultValue: client.config.prefix + } + }, + { sequelize: seqeulize } + ); + } } diff --git a/src/lib/models/Level.ts b/src/lib/models/Level.ts index f08f29b..426ec1a 100644 --- a/src/lib/models/Level.ts +++ b/src/lib/models/Level.ts @@ -1,3 +1,4 @@ +import { DataTypes, Sequelize } from 'sequelize'; import { BaseModel } from './BaseModel'; export interface LevelModel { @@ -16,6 +17,24 @@ export class Level extends BaseModel<LevelModel, LevelModelCreationAttributes> { get level(): number { return Level.convertXpToLevel(this.xp); } + + static initModel(sequelize: Sequelize): void { + Level.init( + { + id: { + type: DataTypes.STRING, + primaryKey: true, + allowNull: false + }, + xp: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: 0 + } + }, + { sequelize: sequelize } + ); + } static convertXpToLevel(xp: number): number { let i = 1; let lvl: number; diff --git a/src/lib/models/Modlog.ts b/src/lib/models/Modlog.ts index 0a3feba..6dd5e26 100644 --- a/src/lib/models/Modlog.ts +++ b/src/lib/models/Modlog.ts @@ -1,4 +1,7 @@ +import { DataTypes, Sequelize } from 'sequelize'; import { BaseModel } from './BaseModel'; +import { v4 as uuidv4 } from 'uuid'; +import * as Models from './'; export enum ModlogType { BAN = 'BAN', @@ -39,4 +42,51 @@ export class Modlog guild: string; reason: string | null; duration: number | null; + + static initModel(sequelize: Sequelize): void { + Modlog.init( + { + id: { + type: DataTypes.STRING, + primaryKey: true, + allowNull: false, + defaultValue: uuidv4 + }, + type: { + type: new DataTypes.ENUM( + 'BAN', + 'TEMPBAN', + 'MUTE', + 'TEMPMUTE', + 'KICK', + 'WARN' + ), + allowNull: false + }, + user: { + type: DataTypes.STRING, + allowNull: false + }, + moderator: { + type: DataTypes.STRING, + allowNull: false + }, + duration: { + type: DataTypes.STRING, + allowNull: true + }, + reason: { + type: DataTypes.STRING, + allowNull: true + }, + guild: { + type: DataTypes.STRING, + references: { + model: Models.Guild + } + } + }, + { sequelize: sequelize } + ); + } } |