Skip to content

Commit d29acc8

Browse files
committed
Move dm punishment to special column
1 parent b39a91f commit d29acc8

File tree

11 files changed

+180
-67
lines changed

11 files changed

+180
-67
lines changed

src/automod/AutoModManager.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Collection, PermissionFlagsBits, RESTJSONErrorCodes, ThreadChannel, userMention} from 'discord.js';
1+
import {bold, Collection, PermissionFlagsBits, RESTJSONErrorCodes, ThreadChannel, userMention} from 'discord.js';
22
import GuildSettings from '../settings/GuildSettings.js';
33
import bot from '../bot/Bot.js';
44
import MemberWrapper from '../discord/MemberWrapper.js';
@@ -217,13 +217,17 @@ export class AutoModManager {
217217
const reason = 'Using forbidden words or phrases';
218218
const comment = `(Filter ID: ${word.id})`;
219219
await bot.delete(message, reason + ' ' + comment);
220-
if (word.response !== 'disabled' && word.punishment.action.toLowerCase() !== 'dm') {
220+
if (word.response !== 'disabled') {
221221
await this.#sendWarning(message, word.getResponse());
222222
}
223+
224+
const member = new Member(message.author, message.guild);
223225
if (word.punishment.action !== 'none') {
224-
const member = new Member(message.author, message.guild);
225226
await member.executePunishment(word.punishment, reason, comment);
226227
}
228+
if (word.dm) {
229+
await member.guild.sendDM(member.user, `Your message in ${bold(message.guild.name)} was removed: ` + word.dm);
230+
}
227231
}
228232

229233
/**

src/bot/Database.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import CommentFieldMigration from '../database/migrations/CommentFieldMigration.
55
import {asyncFilter} from '../util/util.js';
66
import BadWordVisionMigration from '../database/migrations/BadWordVisionMigration.js';
77
import AutoResponseVisionMigration from '../database/migrations/AutoResponseVisionMigration.js';
8+
import DMMigration from '../database/migrations/DMMigration.js';
89

910
export class Database {
1011
/**
@@ -103,7 +104,7 @@ export class Database {
103104
await this.query('CREATE TABLE IF NOT EXISTS `guilds` (`id` VARCHAR(20) NOT NULL, `config` TEXT NOT NULL, PRIMARY KEY (`id`))');
104105
await this.query('CREATE TABLE IF NOT EXISTS `users` (`id` VARCHAR(20) NOT NULL, `config` TEXT NOT NULL, PRIMARY KEY (`id`))');
105106
await this.query('CREATE TABLE IF NOT EXISTS `responses` (`id` int PRIMARY KEY AUTO_INCREMENT, `guildid` VARCHAR(20) NOT NULL, `trigger` TEXT NOT NULL, `response` TEXT NOT NULL, `global` BOOLEAN NOT NULL, `channels` TEXT NULL DEFAULT NULL, `enableVision` BOOLEAN DEFAULT FALSE)');
106-
await this.query('CREATE TABLE IF NOT EXISTS `badWords` (`id` int PRIMARY KEY AUTO_INCREMENT, `guildid` VARCHAR(20) NOT NULL, `trigger` TEXT NOT NULL, `punishment` TEXT NOT NULL, `response` TEXT NOT NULL, `global` BOOLEAN NOT NULL, `channels` TEXT NULL DEFAULT NULL, `priority` int NULL, `enableVision` BOOLEAN DEFAULT FALSE)');
107+
await this.query('CREATE TABLE IF NOT EXISTS `badWords` (`id` int PRIMARY KEY AUTO_INCREMENT, `guildid` VARCHAR(20) NOT NULL, `trigger` TEXT NOT NULL, `punishment` TEXT NOT NULL, `response` TEXT NOT NULL, `global` BOOLEAN NOT NULL, `channels` TEXT NULL DEFAULT NULL, `priority` int NULL, `dm` TEXT NULL DEFAULT NULL, `enableVision` BOOLEAN DEFAULT FALSE)');
107108
await this.query('CREATE TABLE IF NOT EXISTS `moderations` (`id` int PRIMARY KEY AUTO_INCREMENT, `guildid` VARCHAR(20) NOT NULL, `userid` VARCHAR(20) NOT NULL, `action` VARCHAR(10) NOT NULL, `created` bigint NOT NULL, `value` int DEFAULT 0, `expireTime` bigint NULL DEFAULT NULL, `reason` TEXT, `comment` TEXT NULL DEFAULT NULL, `moderator` VARCHAR(20) NULL DEFAULT NULL, `active` BOOLEAN DEFAULT TRUE)');
108109
await this.query('CREATE TABLE IF NOT EXISTS `confirmations` (`id` int PRIMARY KEY AUTO_INCREMENT, `data` TEXT NOT NULL, `expires` bigint NOT NULL)');
109110
await this.query('CREATE TABLE IF NOT EXISTS `safeSearch` (`hash` CHAR(64) PRIMARY KEY, `data` TEXT NOT NULL)');
@@ -114,6 +115,7 @@ export class Database {
114115
new CommentFieldMigration(this),
115116
new BadWordVisionMigration(this),
116117
new AutoResponseVisionMigration(this),
118+
new DMMigration(this),
117119
], async migration => await migration.check());
118120
}
119121

src/commands/settings/bad-word/AddBadWordCommand.js

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ export default class AddBadWordCommand extends AddAutoResponseCommand {
4040
}, {
4141
name: 'Strike user',
4242
value: 'strike'
43-
}, {
44-
name: 'Send direct message',
45-
value: 'DM'
4643
}
4744
)
4845
);
@@ -93,12 +90,25 @@ export default class AddBadWordCommand extends AddAutoResponseCommand {
9390
new TextInputBuilder()
9491
.setRequired(false)
9592
.setCustomId('priority')
96-
.setStyle(TextInputStyle.Paragraph)
93+
.setStyle(TextInputStyle.Short)
9794
.setPlaceholder('0')
9895
.setLabel('Priority')
9996
.setMinLength(1)
10097
.setMaxLength(10)
101-
)
98+
),
99+
/** @type {*} */
100+
new ActionRowBuilder()
101+
.addComponents(
102+
/** @type {*} */
103+
new TextInputBuilder()
104+
.setRequired(false)
105+
.setCustomId('dm')
106+
.setStyle(TextInputStyle.Paragraph)
107+
.setPlaceholder('This is a direct message sent to the user when their message was deleted')
108+
.setLabel('Direct Message')
109+
.setMinLength(1)
110+
.setMaxLength(3000)
111+
),
102112
);
103113

104114
if (['ban', 'mute'].includes(punishment)) {
@@ -131,20 +141,25 @@ export default class AddBadWordCommand extends AddAutoResponseCommand {
131141
return;
132142
}
133143

134-
let trigger, response = null, duration = null, priority = 0;
144+
let trigger, response = null, duration = null, priority = 0, dm = null;
135145
for (let component of interaction.components) {
136146
component = component.components[0];
137-
if (component.customId === 'trigger') {
138-
trigger = component.value;
139-
}
140-
else if (component.customId === 'response') {
141-
response = component.value?.substring?.(0, 4000);
142-
}
143-
else if (component.customId === 'duration') {
144-
duration = parseTime(component.value) || null;
145-
}
146-
else if (component.customId === 'priority') {
147-
priority = parseInt(component.value) || 0;
147+
switch (component.customId) {
148+
case 'trigger':
149+
trigger = component.value;
150+
break;
151+
case 'response':
152+
response = component.value?.substring?.(0, 4000);
153+
break;
154+
case 'duration':
155+
duration = parseTime(component.value) || null;
156+
break;
157+
case 'priority':
158+
priority = parseInt(component.value) || 0;
159+
break;
160+
case 'dm':
161+
dm = component.value?.substring?.(0, 3000);
162+
break;
148163
}
149164
}
150165

@@ -160,13 +175,15 @@ export default class AddBadWordCommand extends AddAutoResponseCommand {
160175
confirmation.data.punishment,
161176
duration,
162177
priority,
178+
dm,
163179
confirmation.data.vision,
164180
);
165181
} else {
166182
confirmation.data.trigger = trigger;
167183
confirmation.data.response = response;
168184
confirmation.data.duration = duration;
169185
confirmation.data.priority = priority;
186+
confirmation.data.dm = dm;
170187
confirmation.expires = timeAfter('30 min');
171188

172189
await interaction.reply({
@@ -209,6 +226,7 @@ export default class AddBadWordCommand extends AddAutoResponseCommand {
209226
confirmation.data.punishment,
210227
confirmation.data.duration,
211228
confirmation.data.priority,
229+
confirmation.data.dm,
212230
confirmation.data.vision,
213231
);
214232
}
@@ -225,6 +243,7 @@ export default class AddBadWordCommand extends AddAutoResponseCommand {
225243
* @param {?string} punishment
226244
* @param {?number} duration
227245
* @param {?number} priority
246+
* @param {?string} dm
228247
* @param {?boolean} enableVision
229248
* @return {Promise<*>}
230249
*/
@@ -238,6 +257,7 @@ export default class AddBadWordCommand extends AddAutoResponseCommand {
238257
punishment,
239258
duration,
240259
priority,
260+
dm,
241261
enableVision,
242262
) {
243263
const result = await BadWord.new(
@@ -250,6 +270,7 @@ export default class AddBadWordCommand extends AddAutoResponseCommand {
250270
punishment,
251271
duration,
252272
priority,
273+
dm,
253274
enableVision,
254275
);
255276
if (!result.success) {

src/commands/settings/bad-word/EditBadWordCommand.js

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ export default class EditBadWordCommand extends CompletingBadWordCommand {
7171
}, {
7272
name: 'Strike user',
7373
value: 'strike'
74-
}, {
75-
name: 'Send direct message',
76-
value: 'DM'
7774
}
7875
)
7976
);
@@ -186,13 +183,26 @@ export default class EditBadWordCommand extends CompletingBadWordCommand {
186183
new TextInputBuilder()
187184
.setRequired(false)
188185
.setCustomId('priority')
189-
.setStyle(TextInputStyle.Paragraph)
186+
.setStyle(TextInputStyle.Short)
190187
.setPlaceholder('0')
191188
.setLabel('Priority')
192189
.setValue(badWord.priority.toString())
193190
.setMinLength(1)
194191
.setMaxLength(10)
195-
)
192+
),
193+
/** @type {*} */
194+
new ActionRowBuilder()
195+
.addComponents(
196+
/** @type {*} */
197+
new TextInputBuilder()
198+
.setRequired(false)
199+
.setCustomId('dm')
200+
.setStyle(TextInputStyle.Paragraph)
201+
.setPlaceholder('This is a direct message sent to the user when their message was deleted')
202+
.setLabel('Direct Message')
203+
.setMinLength(1)
204+
.setMaxLength(3000)
205+
),
196206
);
197207

198208
if (['ban', 'mute'].includes(punishment)) {
@@ -234,20 +244,25 @@ export default class EditBadWordCommand extends CompletingBadWordCommand {
234244
return;
235245
}
236246

237-
let trigger, response, duration = null, priority;
247+
let trigger, response, duration = null, priority = null, dm = null;
238248
for (let component of interaction.components) {
239249
component = component.components[0];
240-
if (component.customId === 'trigger') {
241-
trigger = component.value;
242-
}
243-
else if (component.customId === 'response') {
244-
response = component.value;
245-
}
246-
else if (component.customId === 'duration') {
247-
duration = parseTime(component.value) || null;
248-
}
249-
else if (component.customId === 'priority') {
250-
priority = parseInt(component.value) || 0;
250+
switch (component.customId) {
251+
case 'trigger':
252+
trigger = component.value;
253+
break;
254+
case 'response':
255+
response = component.value?.substring?.(0, 4000);
256+
break;
257+
case 'duration':
258+
duration = parseTime(component.value) || null;
259+
break;
260+
case 'priority':
261+
priority = parseInt(component.value) || 0;
262+
break;
263+
case 'dm':
264+
dm = component.value?.substring?.(0, 3000);
265+
break;
251266
}
252267
}
253268

@@ -264,6 +279,7 @@ export default class EditBadWordCommand extends CompletingBadWordCommand {
264279
confirmation.data.punishment,
265280
duration,
266281
priority,
282+
dm,
267283
confirmation.data.vision,
268284
);
269285
} else {
@@ -331,6 +347,7 @@ export default class EditBadWordCommand extends CompletingBadWordCommand {
331347
* @param {PunishmentAction} punishment
332348
* @param {?number} duration
333349
* @param {number} priority
350+
* @param {?string} dm
334351
* @param {?boolean} vision
335352
* @return {Promise<*>}
336353
*/
@@ -345,6 +362,7 @@ export default class EditBadWordCommand extends CompletingBadWordCommand {
345362
punishment,
346363
duration,
347364
priority,
365+
dm,
348366
vision,
349367
) {
350368
const badWord = /** @type {?BadWord} */
@@ -364,6 +382,7 @@ export default class EditBadWordCommand extends CompletingBadWordCommand {
364382
}
365383
badWord.trigger = triggerResponse.trigger;
366384
badWord.response = response || 'disabled';
385+
badWord.dm = dm || 'disabled';
367386
badWord.punishment = new Punishment({action: punishment, duration});
368387
badWord.priority = priority;
369388
await badWord.save();

0 commit comments

Comments
 (0)