aboutsummaryrefslogtreecommitdiff
path: root/src/lib/models
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/models')
-rw-r--r--src/lib/models/ActivePunishment.ts2
-rw-r--r--src/lib/models/BaseModel.ts3
-rw-r--r--src/lib/models/Global.ts65
-rw-r--r--src/lib/models/Guild.ts140
-rw-r--r--src/lib/models/Level.ts3
-rw-r--r--src/lib/models/ModLog.ts3
-rw-r--r--src/lib/models/StickyRole.ts14
-rw-r--r--src/lib/models/__helpers.ts23
8 files changed, 81 insertions, 172 deletions
diff --git a/src/lib/models/ActivePunishment.ts b/src/lib/models/ActivePunishment.ts
index 62bb73e..10ae766 100644
--- a/src/lib/models/ActivePunishment.ts
+++ b/src/lib/models/ActivePunishment.ts
@@ -147,7 +147,7 @@ export class ActivePunishment
}
}
},
- { sequelize: sequelize }
+ { sequelize }
);
}
}
diff --git a/src/lib/models/BaseModel.ts b/src/lib/models/BaseModel.ts
index 8ed5ed3..555bf7d 100644
--- a/src/lib/models/BaseModel.ts
+++ b/src/lib/models/BaseModel.ts
@@ -1,6 +1,5 @@
import { Model } from 'sequelize';
-
-const NEVER_USED = 'This should never be executed';
+import { NEVER_USED } from './__helpers';
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 36c72d8..17bd570 100644
--- a/src/lib/models/Global.ts
+++ b/src/lib/models/Global.ts
@@ -1,6 +1,7 @@
import { Snowflake } from 'discord.js';
import { DataTypes, Sequelize } from 'sequelize';
import { BaseModel } from './BaseModel';
+import { jsonArrayInit, NEVER_USED } from './__helpers';
export interface GlobalModel {
environment: 'production' | 'development' | 'beta';
@@ -20,8 +21,6 @@ export interface GlobalModelCreationAttributes {
blacklistedChannels?: Snowflake[];
}
-const NEVER_USED = 'This should never be executed';
-
export class Global extends BaseModel<GlobalModel, GlobalModelCreationAttributes> implements GlobalModel {
/**
* The bot's environment.
@@ -90,63 +89,13 @@ export class Global extends BaseModel<GlobalModel, GlobalModelCreationAttributes
type: DataTypes.STRING,
primaryKey: true
},
- superUsers: {
- type: DataTypes.TEXT,
- get: function () {
- return JSON.parse(this.getDataValue('superUsers') as unknown as string);
- },
- set: function (val: Snowflake[]) {
- return this.setDataValue('superUsers', JSON.stringify(val) as unknown as Snowflake[]);
- },
- allowNull: false,
- defaultValue: '[]'
- },
- disabledCommands: {
- type: DataTypes.TEXT,
- get: function () {
- return JSON.parse(this.getDataValue('disabledCommands') as unknown as string);
- },
- set: function (val: Snowflake[]) {
- return this.setDataValue('disabledCommands', JSON.stringify(val) as unknown as string[]);
- },
- allowNull: false,
- defaultValue: '[]'
- },
- blacklistedUsers: {
- type: DataTypes.TEXT,
- get: function () {
- return JSON.parse(this.getDataValue('blacklistedUsers') as unknown as string);
- },
- set: function (val: Snowflake[]) {
- return this.setDataValue('blacklistedUsers', JSON.stringify(val) as unknown as Snowflake[]);
- },
- allowNull: false,
- defaultValue: '[]'
- },
- blacklistedGuilds: {
- type: DataTypes.TEXT,
- get: function () {
- return JSON.parse(this.getDataValue('blacklistedGuilds') as unknown as string);
- },
- set: function (val: Snowflake[]) {
- return this.setDataValue('blacklistedGuilds', JSON.stringify(val) as unknown as Snowflake[]);
- },
- allowNull: false,
- defaultValue: '[]'
- },
- blacklistedChannels: {
- type: DataTypes.TEXT,
- get: function () {
- return JSON.parse(this.getDataValue('blacklistedChannels') as unknown as string);
- },
- set: function (val: Snowflake[]) {
- return this.setDataValue('blacklistedChannels', JSON.stringify(val) as unknown as Snowflake[]);
- },
- allowNull: false,
- defaultValue: '[]'
- }
+ superUsers: jsonArrayInit('superUsers'),
+ disabledCommands: jsonArrayInit('disabledCommands'),
+ blacklistedUsers: jsonArrayInit('blacklistedUsers'),
+ blacklistedGuilds: jsonArrayInit('blacklistedGuilds'),
+ blacklistedChannels: jsonArrayInit('blacklistedChannels')
},
- { sequelize: sequelize }
+ { sequelize }
);
}
}
diff --git a/src/lib/models/Guild.ts b/src/lib/models/Guild.ts
index 41ded9d..614bf15 100644
--- a/src/lib/models/Guild.ts
+++ b/src/lib/models/Guild.ts
@@ -2,6 +2,7 @@ import { Snowflake } from 'discord.js';
import { DataTypes, Sequelize } from 'sequelize';
import { BushClient } from '../extensions/discord-akairo/BushClient';
import { BaseModel } from './BaseModel';
+import { jsonArrayInit, NEVER_USED } from './__helpers';
export interface GuildModel {
id: Snowflake;
@@ -15,7 +16,7 @@ export interface GuildModel {
disabledCommands: string[];
lockdownChannels: Snowflake[];
autoModPhases: string[];
- enabledFeatures: string[];
+ enabledFeatures: GuildFeatures[];
joinRoles: Snowflake[];
}
@@ -31,7 +32,7 @@ export interface GuildModelCreationAttributes {
disabledCommands?: string[];
lockdownChannels?: Snowflake[];
autoModPhases?: string[];
- enabledFeatures?: string[];
+ enabledFeatures?: GuildFeatures[];
joinRoles?: Snowflake[];
}
@@ -45,10 +46,39 @@ export const guildSettings = {
joinRoles: { type: 'role-array' }
};
-export const guildFeatures = ['automodEnabled', 'supportThreads', 'stickyRoles'];
-export type GuildFeatures = 'automodEnabled' | 'supportThreads' | 'stickyRoles';
+export const guildFeaturesObj = {
+ automod: {
+ name: 'Automod',
+ description: 'Deletes offensive content as well as phishing links.'
+ },
+ autoPublish: {
+ name: 'Auto Publish',
+ description: 'Auto publishes all messages in configured announcement channels.'
+ },
+ autoThread: {
+ name: 'Auto Thread',
+ description: 'Automatically creates a new thread for every message in configured channels.'
+ },
+ blacklistedFile: {
+ name: 'Blacklisted File',
+ description: 'Automatically deletes malicious files.'
+ },
+ boosterMessageReact: {
+ name: 'Booster Message React',
+ description: 'Reacts to booster messages with the boost emoji.'
+ },
+ leveling: {
+ name: 'Leveling',
+ description: "Tracks users' messages and assigns them xp."
+ },
+ stickyRoles: {
+ name: 'Sticky Roles',
+ description: "Stores users' roles when they leave the server and returns them when they rejoin."
+ }
+};
-const NEVER_USED = 'This should never be executed';
+export type GuildFeatures = keyof typeof guildFeaturesObj;
+export const guildFeaturesArr: GuildFeatures[] = Object.keys(guildFeaturesObj) as GuildFeatures[];
export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> implements GuildModel {
/**
@@ -164,10 +194,10 @@ export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> i
/**
* The features enabled in a guild
*/
- public get enabledFeatures(): string[] {
+ public get enabledFeatures(): GuildFeatures[] {
throw new Error(NEVER_USED);
}
- public set enabledFeatures(_: string[]) {
+ public set enabledFeatures(_: GuildFeatures[]) {
throw new Error(NEVER_USED);
}
@@ -193,39 +223,9 @@ export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> i
allowNull: false,
defaultValue: client.config.prefix
},
- autoPublishChannels: {
- type: DataTypes.TEXT,
- get: function () {
- return JSON.parse(this.getDataValue('autoPublishChannels') as unknown as string);
- },
- set: function (val: Snowflake[]) {
- return this.setDataValue('autoPublishChannels', JSON.stringify(val) as unknown as Snowflake[]);
- },
- allowNull: false,
- defaultValue: '[]'
- },
- blacklistedChannels: {
- type: DataTypes.TEXT,
- get: function () {
- return JSON.parse(this.getDataValue('blacklistedChannels') as unknown as string);
- },
- set: function (val: Snowflake[]) {
- return this.setDataValue('blacklistedChannels', JSON.stringify(val) as unknown as Snowflake[]);
- },
- allowNull: false,
- defaultValue: '[]'
- },
- blacklistedUsers: {
- type: DataTypes.TEXT,
- get: function () {
- return JSON.parse(this.getDataValue('blacklistedUsers') as unknown as string);
- },
- set: function (val: Snowflake[]) {
- return this.setDataValue('blacklistedUsers', JSON.stringify(val) as unknown as Snowflake[]);
- },
- allowNull: false,
- defaultValue: '[]'
- },
+ autoPublishChannels: jsonArrayInit('autoPublishChannels'),
+ blacklistedChannels: jsonArrayInit('blacklistedChannels'),
+ blacklistedUsers: jsonArrayInit('blacklistedChannels'),
welcomeChannel: {
type: DataTypes.STRING,
allowNull: true
@@ -238,61 +238,11 @@ export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> i
type: DataTypes.TEXT,
allowNull: true
},
- disabledCommands: {
- type: DataTypes.TEXT,
- get: function () {
- return JSON.parse(this.getDataValue('disabledCommands') as unknown as string);
- },
- set: function (val: string[]) {
- return this.setDataValue('disabledCommands', JSON.stringify(val) as unknown as string[]);
- },
- allowNull: false,
- defaultValue: '[]'
- },
- lockdownChannels: {
- type: DataTypes.TEXT,
- get: function () {
- return JSON.parse(this.getDataValue('lockdownChannels') as unknown as string);
- },
- set: function (val: Snowflake[]) {
- return this.setDataValue('lockdownChannels', JSON.stringify(val) as unknown as Snowflake[]);
- },
- allowNull: false,
- defaultValue: '[]'
- },
- autoModPhases: {
- type: DataTypes.TEXT,
- get: function () {
- return JSON.parse(this.getDataValue('autoModPhases') as unknown as string);
- },
- set: function (val: string[]) {
- return this.setDataValue('autoModPhases', JSON.stringify(val) as unknown as string[]);
- },
- allowNull: false,
- defaultValue: '[]'
- },
- enabledFeatures: {
- type: DataTypes.TEXT,
- get: function () {
- return JSON.parse(this.getDataValue('enabledFeatures') as unknown as string);
- },
- set: function (val: string[]) {
- return this.setDataValue('enabledFeatures', JSON.stringify(val) as unknown as string[]);
- },
- allowNull: false,
- defaultValue: '[]'
- },
- joinRoles: {
- type: DataTypes.TEXT,
- get: function () {
- return JSON.parse(this.getDataValue('joinRoles') as unknown as string);
- },
- set: function (val: string[]) {
- return this.setDataValue('joinRoles', JSON.stringify(val) as unknown as string[]);
- },
- allowNull: false,
- defaultValue: '[]'
- }
+ disabledCommands: jsonArrayInit('disabledCommands'),
+ lockdownChannels: jsonArrayInit('lockdownChannels'),
+ autoModPhases: jsonArrayInit('autoModPhases'),
+ enabledFeatures: jsonArrayInit('enabledFeatures'),
+ joinRoles: jsonArrayInit('joinRoles')
},
{ sequelize: sequelize }
);
diff --git a/src/lib/models/Level.ts b/src/lib/models/Level.ts
index ad64747..0960d4f 100644
--- a/src/lib/models/Level.ts
+++ b/src/lib/models/Level.ts
@@ -1,6 +1,7 @@
import { Snowflake } from 'discord.js';
import { DataTypes, Sequelize } from 'sequelize';
import { BaseModel } from './BaseModel';
+import { NEVER_USED } from './__helpers';
export interface LevelModel {
user: Snowflake;
@@ -14,8 +15,6 @@ export interface LevelModelCreationAttributes {
xp?: number;
}
-const NEVER_USED = 'This should never be executed';
-
export class Level extends BaseModel<LevelModel, LevelModelCreationAttributes> {
/**
* The user's id.
diff --git a/src/lib/models/ModLog.ts b/src/lib/models/ModLog.ts
index 50d142a..7787375 100644
--- a/src/lib/models/ModLog.ts
+++ b/src/lib/models/ModLog.ts
@@ -2,6 +2,7 @@ import { Snowflake } from 'discord.js';
import { DataTypes, Sequelize } from 'sequelize';
import { v4 as uuidv4 } from 'uuid';
import { BaseModel } from './BaseModel';
+import { NEVER_USED } from './__helpers';
export enum ModLogType {
PERM_BAN = 'PERM_BAN',
@@ -42,8 +43,6 @@ export interface ModLogModelCreationAttributes {
evidence?: string;
}
-const NEVER_USED = 'This should never be executed';
-
export class ModLog extends BaseModel<ModLogModel, ModLogModelCreationAttributes> implements ModLogModel {
/**
* The primary key of the modlog entry.
diff --git a/src/lib/models/StickyRole.ts b/src/lib/models/StickyRole.ts
index d304370..4c06b32 100644
--- a/src/lib/models/StickyRole.ts
+++ b/src/lib/models/StickyRole.ts
@@ -1,6 +1,7 @@
import { Snowflake } from 'discord.js';
import { DataTypes, Sequelize } from 'sequelize';
import { BaseModel } from './BaseModel';
+import { jsonArrayInit, NEVER_USED } from './__helpers';
export interface StickyRoleModel {
user: Snowflake;
@@ -15,8 +16,6 @@ export interface StickyRoleModelCreationAttributes {
nickname?: string;
}
-const NEVER_USED = 'This should never be executed';
-
export class StickyRole extends BaseModel<StickyRoleModel, StickyRoleModelCreationAttributes> implements StickyRoleModel {
/**
* The id of the user the roles belongs to
@@ -69,16 +68,7 @@ export class StickyRole extends BaseModel<StickyRoleModel, StickyRoleModelCreati
type: DataTypes.STRING,
allowNull: false
},
- roles: {
- type: DataTypes.STRING,
- get: function () {
- return JSON.parse(this.getDataValue('roles') as unknown as string);
- },
- set: function (val: Snowflake[]) {
- return this.setDataValue('roles', JSON.stringify(val) as unknown as Snowflake[]);
- },
- allowNull: true
- },
+ roles: jsonArrayInit('roles'),
nickname: {
type: DataTypes.STRING,
allowNull: true
diff --git a/src/lib/models/__helpers.ts b/src/lib/models/__helpers.ts
new file mode 100644
index 0000000..f558ecb
--- /dev/null
+++ b/src/lib/models/__helpers.ts
@@ -0,0 +1,23 @@
+import { DataTypes, Model } from 'sequelize';
+
+export const NEVER_USED = 'This should never be executed';
+function jsonParseGet(key: string, that: Model): any {
+ return JSON.parse(that.getDataValue(key));
+}
+function jsonParseSet(key: string, that: Model, value: any): any {
+ return that.setDataValue(key, JSON.stringify(value));
+}
+
+export function jsonArrayInit(key: string): any {
+ return {
+ type: DataTypes.TEXT,
+ get: function () {
+ return jsonParseGet(key, this);
+ },
+ set: function (val: string[]) {
+ return jsonParseSet(key, this, val);
+ },
+ allowNull: false,
+ defaultValue: '[]'
+ };
+}