aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-09-02 19:26:10 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2021-09-02 19:26:10 -0400
commit1623beebadefa38769db134a0fbfce0c34b38846 (patch)
treef75b71cdda596acfe7bd09812f3cfa3a00a08e1a /src/lib
parent930b1a46830567fd51780f301e550dbf4a87c7f3 (diff)
downloadtanzanite-1623beebadefa38769db134a0fbfce0c34b38846.tar.gz
tanzanite-1623beebadefa38769db134a0fbfce0c34b38846.tar.bz2
tanzanite-1623beebadefa38769db134a0fbfce0c34b38846.zip
log command
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/models/Guild.ts115
-rw-r--r--src/lib/models/__helpers.ts6
2 files changed, 71 insertions, 50 deletions
diff --git a/src/lib/models/Guild.ts b/src/lib/models/Guild.ts
index 1974725..38b5127 100644
--- a/src/lib/models/Guild.ts
+++ b/src/lib/models/Guild.ts
@@ -2,41 +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;
- prefix: string;
- autoPublishChannels: Snowflake[];
- blacklistedChannels: Snowflake[];
- blacklistedUsers: Snowflake[];
- welcomeChannel: Snowflake;
- muteRole: Snowflake;
- punishmentEnding: string;
- disabledCommands: string[];
- lockdownChannels: Snowflake[];
- autoModPhases: string[];
- enabledFeatures: GuildFeatures[];
- joinRoles: Snowflake[];
- automodLogChannel: Snowflake;
-}
-
-export interface GuildModelCreationAttributes {
- id: Snowflake;
- prefix?: string;
- autoPublishChannels?: Snowflake[];
- blacklistedChannels?: Snowflake[];
- blacklistedUsers?: Snowflake[];
- welcomeChannel?: Snowflake;
- muteRole?: Snowflake;
- punishmentEnding?: string;
- disabledCommands?: string[];
- lockdownChannels?: Snowflake[];
- autoModPhases?: string[];
- enabledFeatures?: GuildFeatures[];
- joinRoles?: Snowflake[];
- automodLogChannel?: Snowflake;
-}
+import { jsonArrayInit, jsonParseGet, jsonParseSet, NEVER_USED } from './__helpers';
export const guildSettingsObj = {
prefix: {
@@ -80,12 +46,6 @@ export const guildSettingsObj = {
description: 'Roles assigned to users on join who do not have sticky role information.',
type: 'role-array',
configurable: true
- },
- automodLogChannel: {
- name: 'Automod Log Channel',
- description: 'The channel where all automod information is sent.',
- type: 'channel',
- configurable: true
}
};
export type GuildSettings = keyof typeof guildSettingsObj;
@@ -121,12 +81,66 @@ export const guildFeaturesObj = {
stickyRoles: {
name: 'Sticky Roles',
description: 'Restores past roles to a user when they rejoin.'
+ },
+ modsCanPunishMods: {
+ name: 'Mods Can Punish Mods',
+ description: 'Allow moderators to punish other moderators.'
}
};
+export const guildLogsObj = {
+ automod: {
+ description: 'Sends a message in this channel every time automod is activated.',
+ configurable: true
+ },
+ moderation: {
+ description: 'Sends a message in this channel every time a moderation action is performed.',
+ configurable: true
+ }
+};
+export type GuildLogType = keyof typeof guildLogsObj;
+export const guildLogsArr = Object.keys(guildLogsObj).filter(
+ (s) => guildLogsObj[s as GuildLogType].configurable
+) as GuildLogType[];
+type LogChannelDB = { [x in keyof typeof guildLogsObj]?: Snowflake };
+
export type GuildFeatures = keyof typeof guildFeaturesObj;
export const guildFeaturesArr: GuildFeatures[] = Object.keys(guildFeaturesObj) as GuildFeatures[];
+export interface GuildModel {
+ id: Snowflake;
+ prefix: string;
+ autoPublishChannels: Snowflake[];
+ blacklistedChannels: Snowflake[];
+ blacklistedUsers: Snowflake[];
+ welcomeChannel: Snowflake;
+ muteRole: Snowflake;
+ punishmentEnding: string;
+ disabledCommands: string[];
+ lockdownChannels: Snowflake[];
+ autoModPhases: string[];
+ enabledFeatures: GuildFeatures[];
+ joinRoles: Snowflake[];
+ logChannels: LogChannelDB;
+}
+
+export interface GuildModelCreationAttributes {
+ id: Snowflake;
+ prefix?: string;
+ autoPublishChannels?: Snowflake[];
+ blacklistedChannels?: Snowflake[];
+ blacklistedUsers?: Snowflake[];
+ welcomeChannel?: Snowflake;
+ muteRole?: Snowflake;
+ punishmentEnding?: string;
+ disabledCommands?: string[];
+ lockdownChannels?: Snowflake[];
+ autoModPhases?: string[];
+ enabledFeatures?: GuildFeatures[];
+ joinRoles?: Snowflake[];
+ logChannels?: LogChannelDB;
+}
+
export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> implements GuildModel {
/**
* The ID of the guild
@@ -259,12 +273,12 @@ export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> i
}
/**
- * The channel to send automod logs to.
+ * The channels where logging messages will be sent.
*/
- public get automodLogChannel(): Snowflake {
+ public get logChannels(): LogChannelDB {
throw new Error(NEVER_USED);
}
- public set automodLogChannel(_: Snowflake) {
+ public set logChannels(_: LogChannelDB) {
throw new Error(NEVER_USED);
}
@@ -300,9 +314,16 @@ export class Guild extends BaseModel<GuildModel, GuildModelCreationAttributes> i
autoModPhases: jsonArrayInit('autoModPhases'),
enabledFeatures: jsonArrayInit('enabledFeatures'),
joinRoles: jsonArrayInit('joinRoles'),
- automodLogChannel: {
- type: DataTypes.STRING,
- allowNull: true
+ logChannels: {
+ type: DataTypes.TEXT,
+ get: function (): LogChannelDB {
+ return jsonParseGet('logChannels', this);
+ },
+ set: function (val: LogChannelDB) {
+ return jsonParseSet('logChannels', this, val);
+ },
+ allowNull: false,
+ defaultValue: '{}'
}
},
{ sequelize: sequelize }
diff --git a/src/lib/models/__helpers.ts b/src/lib/models/__helpers.ts
index f558ecb..b65c014 100644
--- a/src/lib/models/__helpers.ts
+++ b/src/lib/models/__helpers.ts
@@ -1,17 +1,17 @@
import { DataTypes, Model } from 'sequelize';
export const NEVER_USED = 'This should never be executed';
-function jsonParseGet(key: string, that: Model): any {
+export function jsonParseGet(key: string, that: Model): any {
return JSON.parse(that.getDataValue(key));
}
-function jsonParseSet(key: string, that: Model, value: any): any {
+export 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 () {
+ get: function (): string[] {
return jsonParseGet(key, this);
},
set: function (val: string[]) {