aboutsummaryrefslogtreecommitdiff
path: root/src/lib/models
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/models')
-rw-r--r--src/lib/models/ActivePunishment.ts57
-rw-r--r--src/lib/models/BaseModel.ts18
-rw-r--r--src/lib/models/Global.ts45
-rw-r--r--src/lib/models/Guild.ts121
-rw-r--r--src/lib/models/Level.ts47
-rw-r--r--src/lib/models/ModLog.ts73
-rw-r--r--src/lib/models/Stat.ts19
-rw-r--r--src/lib/models/StickyRole.ts33
-rw-r--r--src/lib/models/__helpers.ts2
9 files changed, 244 insertions, 171 deletions
diff --git a/src/lib/models/ActivePunishment.ts b/src/lib/models/ActivePunishment.ts
index 0ad6cd8..83ada29 100644
--- a/src/lib/models/ActivePunishment.ts
+++ b/src/lib/models/ActivePunishment.ts
@@ -1,6 +1,6 @@
-import { Snowflake } from 'discord.js';
+import { type Snowflake } from 'discord.js';
import { nanoid } from 'nanoid';
-import { DataTypes, Sequelize } from 'sequelize';
+import { DataTypes, type Sequelize } from 'sequelize';
import { BaseModel } from './BaseModel';
export enum ActivePunishmentType {
@@ -30,34 +30,45 @@ export interface ActivePunishmentModelCreationAttributes {
modlog: string;
}
-// declaration merging so that the fields don't override Sequelize's getters
-export interface ActivePunishment {
- /** The ID of this punishment (no real use just for a primary key) */
- id: string;
+export class ActivePunishment
+ extends BaseModel<ActivePunishmentModel, ActivePunishmentModelCreationAttributes>
+ implements ActivePunishmentModel
+{
+ /**
+ * The ID of this punishment (no real use just for a primary key)
+ */
+ public declare id: string;
- /** The type of punishment. */
- type: ActivePunishmentType;
+ /**
+ * The type of punishment.
+ */
+ public declare type: ActivePunishmentType;
- /** The user who is punished. */
- user: Snowflake;
+ /**
+ * The user who is punished.
+ */
+ public declare user: Snowflake;
- /** The guild they are punished in. */
- guild: 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. */
- extraInfo: 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). */
- expires: Date | null;
+ /**
+ * The date when this punishment expires (optional).
+ */
+ public declare expires: Date | null;
- /** The reference to the modlog entry. */
- modlog: string;
-}
+ /**
+ * The reference to the modlog entry.
+ */
+ public declare modlog: string;
-export class ActivePunishment
- extends BaseModel<ActivePunishmentModel, ActivePunishmentModelCreationAttributes>
- implements ActivePunishmentModel
-{
public static initModel(sequelize: Sequelize): void {
ActivePunishment.init(
{
diff --git a/src/lib/models/BaseModel.ts b/src/lib/models/BaseModel.ts
index d9377d1..8fba5e5 100644
--- a/src/lib/models/BaseModel.ts
+++ b/src/lib/models/BaseModel.ts
@@ -1,13 +1,13 @@
import { Model } from 'sequelize';
-// declaration merging so that the fields don't override Sequelize's getters
-// eslint-disable-next-line @typescript-eslint/no-unused-vars
-export interface BaseModel<A, B> {
- /** The date when the row was created. */
- readonly createdAt: Date;
+export abstract class BaseModel<A, B> extends Model<A, B> {
+ /**
+ * The date when the row was created.
+ */
+ public declare readonly createdAt: Date;
- /** The date when the row was last updated. */
- readonly updatedAt: Date;
+ /**
+ * The date when the row was last updated.
+ */
+ public declare readonly updatedAt: Date;
}
-
-export abstract class BaseModel<A, B> extends Model<A, B> {}
diff --git a/src/lib/models/Global.ts b/src/lib/models/Global.ts
index c5c680d..6b6ebae 100644
--- a/src/lib/models/Global.ts
+++ b/src/lib/models/Global.ts
@@ -1,5 +1,5 @@
-import { Snowflake } from 'discord.js';
-import { DataTypes, Sequelize } from 'sequelize';
+import { type Snowflake } from 'discord.js';
+import { DataTypes, type Sequelize } from 'sequelize';
import { BaseModel } from './BaseModel';
import { jsonArray } from './__helpers';
@@ -21,28 +21,37 @@ export interface GlobalModelCreationAttributes {
blacklistedChannels?: Snowflake[];
}
-// declaration merging so that the fields don't override Sequelize's getters
-export interface Global {
- /** The bot's environment. */
- environment: 'production' | 'development' | 'beta';
+export class Global extends BaseModel<GlobalModel, GlobalModelCreationAttributes> implements GlobalModel {
+ /**
+ * The bot's environment.
+ */
+ public declare environment: 'production' | 'development' | 'beta';
- /** Trusted users. */
- superUsers: Snowflake[];
+ /**
+ * Trusted users.
+ */
+ public declare superUsers: Snowflake[];
- /** Globally disabled commands. */
- disabledCommands: string[];
+ /**
+ * Globally disabled commands.
+ */
+ public declare disabledCommands: string[];
- /** Globally blacklisted users. */
- blacklistedUsers: Snowflake[];
+ /**
+ * Globally blacklisted users.
+ */
+ public declare blacklistedUsers: Snowflake[];
- /** Guilds blacklisted from using the bot. */
- blacklistedGuilds: Snowflake[];
+ /**
+ * Guilds blacklisted from using the bot.
+ */
+ public declare blacklistedGuilds: Snowflake[];
- /** Channels where the bot is prevented from running. */
- blacklistedChannels: Snowflake[];
-}
+ /**
+ * Channels where the bot is prevented from running commands in.
+ */
+ public declare blacklistedChannels: Snowflake[];
-export class Global extends BaseModel<GlobalModel, GlobalModelCreationAttributes> implements GlobalModel {
public static initModel(sequelize: Sequelize): void {
Global.init(
{
diff --git a/src/lib/models/Guild.ts b/src/lib/models/Guild.ts
index 1fadde9..583cbd7 100644
--- a/src/lib/models/Guild.ts
+++ b/src/lib/models/Guild.ts
@@ -1,7 +1,7 @@
-import { Snowflake } from 'discord.js';
-import { DataTypes, Sequelize } from 'sequelize';
-import { BadWords } from '../common/AutoMod';
-import { BushClient } from '../extensions/discord-akairo/BushClient';
+import { type Snowflake } from 'discord.js';
+import { DataTypes, type Sequelize } from 'sequelize';
+import { type BadWords } from '../common/AutoMod';
+import { type BushClient } from '../extensions/discord-akairo/BushClient';
import { BaseModel } from './BaseModel';
import { jsonArray, jsonObject } from './__helpers';
@@ -47,64 +47,97 @@ export interface GuildModelCreationAttributes {
levelUpChannel?: Snowflake;
}
-// declaration merging so that the fields don't override Sequelize's getters
-export interface Guild {
- /** The ID of the guild */
- id: Snowflake;
+export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> implements GuildModel {
+ /**
+ * The ID of the guild
+ */
+ public declare id: Snowflake;
- /** The bot's prefix for the guild */
- prefix: string;
+ /**
+ * The bot's prefix for the guild
+ */
+ public declare prefix: string;
- /** Channels that will have their messages automatically published */
- autoPublishChannels: Snowflake[];
+ /**
+ * Channels that will have their messages automatically published
+ */
+ public declare autoPublishChannels: Snowflake[];
- /** Channels where the bot won't respond in. */
- blacklistedChannels: Snowflake[];
+ /**
+ * Channels where the bot won't respond in.
+ */
+ public declare blacklistedChannels: Snowflake[];
- /** Users that the bot ignores in this guild */
- blacklistedUsers: Snowflake[];
+ /**
+ * Users that the bot ignores in this guild
+ */
+ public declare blacklistedUsers: Snowflake[];
- /** The channels where the welcome messages are sent */
- welcomeChannel: Snowflake;
+ /**
+ * The channels where the welcome messages are sent
+ */
+ public declare welcomeChannel: Snowflake;
- /** The role given out when muting someone */
- muteRole: Snowflake;
+ /**
+ * The role given out when muting someone
+ */
+ public declare muteRole: Snowflake;
- /** The message that gets sent after someone gets a punishment dm */
- punishmentEnding: string;
+ /**
+ * The message that gets sent after someone gets a punishment dm
+ */
+ public declare punishmentEnding: string;
- /** Guild specific disabled commands */
- disabledCommands: string[];
+ /**
+ * Guild specific disabled commands
+ */
+ public declare disabledCommands: string[];
- /** Channels that should get locked down when the lockdown command gets used. */
- lockdownChannels: Snowflake[];
+ /**
+ * Channels that should get locked down when the lockdown command gets used.
+ */
+ public declare lockdownChannels: Snowflake[];
- /** Custom automod phases */
- autoModPhases: BadWords;
+ /**
+ * Custom automod phases
+ */
+ public declare autoModPhases: BadWords;
- /** The features enabled in a guild */
- enabledFeatures: GuildFeatures[];
+ /**
+ * The features enabled in a guild
+ */
+ public declare enabledFeatures: GuildFeatures[];
- /** The roles to assign to a user if they are not assigned sticky roles */
- joinRoles: Snowflake[];
+ /**
+ * 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. */
- logChannels: LogChannelDB;
+ /**
+ * The channels where logging messages will be sent.
+ */
+ public declare logChannels: LogChannelDB;
- /** These users will be able to use commands in channels blacklisted */
- bypassChannelBlacklist: Snowflake[];
+ /**
+ * These users will be able to use commands in channels blacklisted
+ */
+ public declare bypassChannelBlacklist: Snowflake[];
- /** Channels where users will not earn xp for leveling. */
- noXpChannels: 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. */
- levelRoles: { [level: number]: 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. */
- levelUpChannel: Snowflake;
-}
+ /**
+ * The channel to send level up messages in instead of last channel.
+ */
+ public declare levelUpChannel: Snowflake;
-export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> implements GuildModel {
public static initModel(sequelize: Sequelize, client: BushClient): void {
Guild.init(
{
diff --git a/src/lib/models/Level.ts b/src/lib/models/Level.ts
index 7f418fd..6499bff 100644
--- a/src/lib/models/Level.ts
+++ b/src/lib/models/Level.ts
@@ -1,5 +1,5 @@
-import { Snowflake } from 'discord.js';
-import { DataTypes, Sequelize } from 'sequelize';
+import { type Snowflake } from 'discord.js';
+import { DataTypes, type Sequelize } from 'sequelize';
import { BaseModel } from './BaseModel';
export interface LevelModel {
@@ -14,20 +14,25 @@ export interface LevelModelCreationAttributes {
xp?: number;
}
-// declaration merging so that the fields don't override Sequelize's getters
-export interface Level {
- /** The user's id. */
- user: Snowflake;
+export class Level extends BaseModel<LevelModel, LevelModelCreationAttributes> implements LevelModel {
+ /**
+ * The user's id.
+ */
+ public declare user: Snowflake;
- /** The guild where the user is gaining xp. */
- guild: Snowflake;
+ /**
+ * The guild where the user is gaining xp.
+ */
+ public declare guild: Snowflake;
- /**The user's xp.*/
- xp: number;
-}
+ /**
+ * The user's xp.
+ */
+ public declare xp: number;
-export class Level extends BaseModel<LevelModel, LevelModelCreationAttributes> implements LevelModel {
- /** The user's level. */
+ /**
+ * The user's level.
+ */
public get level(): number {
return Level.convertXpToLevel(this.xp);
}
@@ -44,19 +49,11 @@ export class Level extends BaseModel<LevelModel, LevelModelCreationAttributes> i
}
public static convertXpToLevel(xp: number): number {
- let i = 1;
- let lvl: number;
- // eslint-disable-next-line no-constant-condition
- while (true) {
- const neededXp = Level.convertLevelToXp(i);
- if (neededXp > xp) {
- lvl = i;
- break;
- } else {
- i++;
- }
+ let i = 0;
+ while (Level.convertLevelToXp(i + 1) < xp) {
+ i++;
}
- return lvl - 1; // I have to do this don't question it ok
+ return i;
}
public static convertLevelToXp(level: number): number {
diff --git a/src/lib/models/ModLog.ts b/src/lib/models/ModLog.ts
index 0151cf6..b2351b9 100644
--- a/src/lib/models/ModLog.ts
+++ b/src/lib/models/ModLog.ts
@@ -1,6 +1,6 @@
-import { Snowflake } from 'discord.js';
+import { type Snowflake } from 'discord.js';
import { nanoid } from 'nanoid';
-import { DataTypes, Sequelize } from 'sequelize';
+import { DataTypes, type Sequelize } from 'sequelize';
import { BaseModel } from './BaseModel';
import { jsonBoolean } from './__helpers';
@@ -47,45 +47,62 @@ export interface ModLogModelCreationAttributes {
hidden?: boolean;
}
-// declaration merging so that the fields don't override Sequelize's getters
-export interface ModLog {
- /** The primary key of the modlog entry. */
- id: string;
+export class ModLog extends BaseModel<ModLogModel, ModLogModelCreationAttributes> implements ModLogModel {
+ /**
+ * The primary key of the modlog entry.
+ */
+ public declare id: string;
+
+ /**
+ * The type of punishment.
+ */
+ public declare type: ModLogType;
- /** The type of punishment. */
- type: ModLogType;
+ /**
+ * The user being punished.
+ */
+ public declare user: Snowflake;
- /** The user being punished. */
- user: Snowflake;
+ /**
+ * The user carrying out the punishment.
+ */
+ public declare moderator: Snowflake;
- /** The user carrying out the punishment. */
- moderator: Snowflake;
-
- /** The reason the user is getting punished. */
- reason: string | null;
+ /**
+ * The reason the user is getting punished.
+ */
+ public declare reason: string | null;
- /** The amount of time the user is getting punished for. */
- duration: number | null;
+ /**
+ * The amount of time the user is getting punished for.
+ */
+ public declare duration: number | null;
- /** The guild the user is getting punished in. */
- guild: Snowflake;
+ /**
+ * The guild the user is getting punished in.
+ */
+ public declare guild: Snowflake;
- /** Evidence of what the user is getting punished for. */
- evidence: string;
+ /**
+ * 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. */
- pseudo: boolean;
+ /**
+ * 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. */
- hidden: boolean;
-}
+ /**
+ * Hides from the modlog command unless show hidden is specified.
+ */
+ public declare hidden: boolean;
-export class ModLog extends BaseModel<ModLogModel, ModLogModelCreationAttributes> implements ModLogModel {
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
+ 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 },
diff --git a/src/lib/models/Stat.ts b/src/lib/models/Stat.ts
index 89fc00f..a6e8f19 100644
--- a/src/lib/models/Stat.ts
+++ b/src/lib/models/Stat.ts
@@ -1,4 +1,4 @@
-import { DataTypes, Sequelize } from 'sequelize';
+import { DataTypes, type Sequelize } from 'sequelize';
import { BaseModel } from './BaseModel';
import { jsonBigint } from './__helpers';
@@ -14,16 +14,17 @@ export interface StatModelCreationAttributes {
commandsUsed?: bigint;
}
-// declaration merging so that the fields don't override Sequelize's getters
-export interface Stat {
- /** The bot's environment. */
- environment: Environment;
+export class Stat extends BaseModel<StatModel, StatModelCreationAttributes> implements StatModel {
+ /**
+ * The bot's environment.
+ */
+ public declare environment: Environment;
- /** The number of commands used */
- commandsUsed: bigint;
-}
+ /**
+ * The number of commands used
+ */
+ public declare commandsUsed: bigint;
-export class Stat extends BaseModel<StatModel, StatModelCreationAttributes> implements StatModel {
public static initModel(sequelize: Sequelize): void {
Stat.init(
{
diff --git a/src/lib/models/StickyRole.ts b/src/lib/models/StickyRole.ts
index 77e1889..657bac6 100644
--- a/src/lib/models/StickyRole.ts
+++ b/src/lib/models/StickyRole.ts
@@ -1,5 +1,5 @@
-import { Snowflake } from 'discord.js';
-import { DataTypes, Sequelize } from 'sequelize';
+import { type Snowflake } from 'discord.js';
+import { DataTypes, type Sequelize } from 'sequelize';
import { BaseModel } from './BaseModel';
import { jsonArray } from './__helpers';
@@ -16,22 +16,27 @@ export interface StickyRoleModelCreationAttributes {
nickname?: string;
}
-// declaration merging so that the fields don't override Sequelize's getters
-export interface StickyRole {
- /** The id of the user the roles belongs to. */
- user: Snowflake;
+export class StickyRole extends BaseModel<StickyRoleModel, StickyRoleModelCreationAttributes> implements StickyRoleModel {
+ /**
+ * The id of the user the roles belongs to.
+ */
+ public declare user: Snowflake;
- /** The guild where this should happen. */
- guild: Snowflake;
+ /**
+ * The guild where this should happen.
+ */
+ public declare guild: Snowflake;
- /** The roles that the user should have returned */
- roles: Snowflake[];
+ /**
+ * The roles that the user should have returned
+ */
+ public declare roles: Snowflake[];
- /** The user's previous nickname */
- nickname: string;
-}
+ /**
+ * The user's previous nickname
+ */
+ public declare nickname: string;
-export class StickyRole extends BaseModel<StickyRoleModel, StickyRoleModelCreationAttributes> implements StickyRoleModel {
public static initModel(sequelize: Sequelize): void {
StickyRole.init(
{
diff --git a/src/lib/models/__helpers.ts b/src/lib/models/__helpers.ts
index dafbd84..3a958b9 100644
--- a/src/lib/models/__helpers.ts
+++ b/src/lib/models/__helpers.ts
@@ -1,4 +1,4 @@
-import { DataTypes, Model } from 'sequelize';
+import { DataTypes, type Model } from 'sequelize';
export function jsonParseGet(this: Model, key: string): any {
return JSON.parse(this.getDataValue(key));