Skip to content

Commit

Permalink
Add comment field to remaining places
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianVennen committed Jun 3, 2024
1 parent c254e5f commit 5d9d4a1
Show file tree
Hide file tree
Showing 14 changed files with 312 additions and 171 deletions.
9 changes: 5 additions & 4 deletions src/automod/AutoModManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export class AutoModManager {
await this.#deleteAndWarn(message, `Detected ${likelihood.type} image`, 'You can\'t post such images here!');
if (likelihood.value === 2 && guildSettings.safeSearch.strikes) {
const member = new MemberWrapper(message.author, message.guild);
await member.strike(`Posting images containing ${likelihood.type} content`, bot.client.user, guildSettings.safeSearch.strikes);
await member.strike(`Posting images containing ${likelihood.type} content`, null, bot.client.user, guildSettings.safeSearch.strikes);
}

return true;
Expand All @@ -164,14 +164,15 @@ export class AutoModManager {
.sort((a, b) => b.priority - a.priority);
for (let word of words.values()) {
if (word.matches(message)) {
const reason = `Using forbidden words or phrases (Filter ID: ${word.id})`;
await bot.delete(message, reason);
const reason = 'Using forbidden words or phrases';
const comment = `(Filter ID: ${word.id})`;
await bot.delete(message, reason + ' ' + comment);
if (word.response !== 'disabled') {
await this.#sendWarning(message, word.getResponse());
}
if (word.punishment.action !== 'none') {
const member = new Member(message.author, message.guild);
await member.executePunishment(word.punishment, reason);
await member.executePunishment(word.punishment, reason, comment);
}
return true;
}
Expand Down
48 changes: 35 additions & 13 deletions src/commands/user/BanCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default class BanCommand extends UserCommand {
await this.ban(interaction,
new MemberWrapper(interaction.options.getUser('user', true), interaction.guild),
interaction.options.getString('reason'),
interaction.options.getString('comment'),
parseTime(interaction.options.getString('duration')),
parseTime(interaction.options.getString('delete'))
);
Expand All @@ -62,20 +63,26 @@ export default class BanCommand extends UserCommand {
* @param {import('discord.js').Interaction} interaction
* @param {?MemberWrapper} member
* @param {?string} reason
* @param {?string} comment
* @param {?number} duration
* @param {?number} deleteMessageTime
* @return {Promise<void>}
*/
async ban(interaction, member, reason, duration, deleteMessageTime) {
async ban(interaction, member, reason, comment, duration, deleteMessageTime) {
reason = reason || 'No reason provided';
await deferReplyOnce(interaction);

if (!await this.checkPermissions(interaction, member) ||
!await this.preventDuplicateModeration(interaction, member, {reason, duration, deleteMessageTime})) {
!await this.preventDuplicateModeration(interaction, member, {
reason,
comment,
duration,
deleteMessageTime
})) {
return;
}

await member.ban(reason, interaction.user, duration, deleteMessageTime);
await member.ban(reason, comment, interaction.user, duration, deleteMessageTime);
await replyOrEdit(
interaction,
new UserActionEmbed(member.user, reason, 'banned', colors.RED, config.data.emoji.ban, duration)
Expand All @@ -85,7 +92,7 @@ export default class BanCommand extends UserCommand {
async executeButton(interaction) {
const parts = interaction.customId.split(':');
if (parts[1] === 'confirm') {
/** @type {Confirmation<{reason: ?string, duration: ?number, deleteMessageTime: ?number, user: import('discord.js').Snowflake}>}*/
/** @type {Confirmation<{reason: ?string, comment: ?string, duration: ?number, deleteMessageTime: ?number, user: import('discord.js').Snowflake}>}*/
const data = await Confirmation.get(parts[2]);
if (!data) {
await interaction.update({content: 'This confirmation has expired.', embeds: [], components: []});
Expand All @@ -96,6 +103,7 @@ export default class BanCommand extends UserCommand {
interaction,
await MemberWrapper.getMember(interaction, data.data.user),
data.data.reason,
data.data.comment,
data.data.duration,
data.data.deleteMessageTime,
);
Expand Down Expand Up @@ -133,6 +141,14 @@ export default class BanCommand extends UserCommand {
.setStyle(TextInputStyle.Paragraph)
.setPlaceholder('No reason provided')),
/** @type {*} */
new ActionRowBuilder()
.addComponents(/** @type {*} */ new TextInputBuilder()
.setRequired(false)
.setLabel('Comment')
.setCustomId('comment')
.setStyle(TextInputStyle.Paragraph)
.setPlaceholder('No internal comment')),
/** @type {*} */
new ActionRowBuilder()
.addComponents(/** @type {*} */ new TextInputBuilder()
.setRequired(false)
Expand All @@ -151,17 +167,22 @@ export default class BanCommand extends UserCommand {
}

async executeModal(interaction) {
let reason, duration, deleteMessageTime;
let reason, duration, deleteMessageTime, comment;
for (const row of interaction.components) {
for (const component of row.components) {
if (component.customId === 'reason') {
reason = component.value || 'No reason provided';
}
else if (component.customId === 'duration') {
duration = parseTime(component.value);
}
else if (component.customId === 'delete') {
deleteMessageTime = parseTime(component.value);
switch (component.customId) {
case 'reason':
reason = component.value || 'No reason provided';
break;
case 'comment':
comment = component.value || null;
break;
case 'duration':
duration = parseTime(component.value);
break;
case 'delete':
deleteMessageTime = parseTime(component.value);
break;
}
}
}
Expand All @@ -170,6 +191,7 @@ export default class BanCommand extends UserCommand {
interaction,
await MemberWrapper.getMemberFromCustomId(interaction),
reason,
comment,
duration,
deleteMessageTime
);
Expand Down
36 changes: 29 additions & 7 deletions src/commands/user/KickCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export default class KickCommand extends UserCommand {
await this.kick(interaction,
new MemberWrapper(interaction.options.getUser('user', true), interaction.guild),
interaction.options.getString('reason'),
interaction.options.getString('comment'),
);
}

Expand All @@ -43,18 +44,19 @@ export default class KickCommand extends UserCommand {
* @param {import('discord.js').Interaction} interaction
* @param {?MemberWrapper} member
* @param {?string} reason
* @param {?string} comment
* @return {Promise<void>}
*/
async kick(interaction, member, reason) {
async kick(interaction, member, reason, comment) {
await deferReplyOnce(interaction);
reason = reason || 'No reason provided';

if (!await this.checkPermissions(interaction, member) ||
!await this.preventDuplicateModeration(interaction, member, {reason})) {
!await this.preventDuplicateModeration(interaction, member, {reason, comment})) {
return;
}

await member.kick(reason, interaction.user);
await member.kick(reason, comment, interaction.user);
await replyOrEdit(interaction,
new UserActionEmbed(member.user, reason, 'kicked', colors.ORANGE, config.data.emoji.kick)
.toMessage());
Expand All @@ -63,7 +65,7 @@ export default class KickCommand extends UserCommand {
async executeButton(interaction) {
const parts = interaction.customId.split(':');
if (parts[1] === 'confirm') {
/** @type {Confirmation<{reason: ?string, user: import('discord.js').Snowflake}>}*/
/** @type {Confirmation<{reason: ?string, comment: ?string, user: import('discord.js').Snowflake}>}*/
const data = await Confirmation.get(parts[2]);
if (!data) {
await interaction.update({content: 'This confirmation has expired.', embeds: [], components: []});
Expand All @@ -74,6 +76,7 @@ export default class KickCommand extends UserCommand {
interaction,
await MemberWrapper.getMember(interaction, data.data.user),
data.data.reason,
data.data.comment,
);
return;
}
Expand Down Expand Up @@ -108,14 +111,33 @@ export default class KickCommand extends UserCommand {
.setCustomId('reason')
.setStyle(TextInputStyle.Paragraph)
.setPlaceholder('No reason provided')),
/** @type {*} */
new ActionRowBuilder()
.addComponents(/** @type {*} */ new TextInputBuilder()
.setRequired(false)
.setLabel('Comment')
.setCustomId('comment')
.setStyle(TextInputStyle.Paragraph)
.setPlaceholder('No internal comment')),
));
}

async executeModal(interaction) {
const reason = interaction.components[0].components.find(component => component.customId === 'reason').value
|| 'No reason provided';
let reason, comment;
for (const row of interaction.components) {
for (const component of row.components) {
switch (component.customId) {
case 'reason':
reason = component.value || 'No reason provided';
break;
case 'comment':
comment = component.value || null;
break;
}
}
}

await this.kick(interaction, await MemberWrapper.getMemberFromCustomId(interaction), reason);
await this.kick(interaction, await MemberWrapper.getMemberFromCustomId(interaction), reason, comment);
}

getDescription() {
Expand Down
37 changes: 27 additions & 10 deletions src/commands/user/MuteCommand.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export default class MuteCommand extends UserCommand {
await this.mute(interaction,
new MemberWrapper(interaction.options.getUser('user', true), interaction.guild),
interaction.options.getString('reason'),
interaction.options.getString('comment'),
parseTime(interaction.options.getString('duration')),
);
}
Expand All @@ -58,15 +59,16 @@ export default class MuteCommand extends UserCommand {
* @param {import('discord.js').Interaction} interaction
* @param {?MemberWrapper} member
* @param {?string} reason
* @param {?string} comment
* @param {?number} duration
* @return {Promise<void>}
*/
async mute(interaction, member, reason, duration) {
async mute(interaction, member, reason, comment, duration) {
await deferReplyOnce(interaction);
reason = reason || 'No reason provided';

if (!await this.checkPermissions(interaction, member) ||
!await this.preventDuplicateModeration(interaction, member, {reason, duration})) {
!await this.preventDuplicateModeration(interaction, member, {reason, comment, duration})) {
return;
}

Expand All @@ -86,7 +88,7 @@ export default class MuteCommand extends UserCommand {
}
}

await member.mute(reason, interaction.user, duration);
await member.mute(reason, comment, interaction.user, duration);
await replyOrEdit(interaction,
new UserActionEmbed(member.user, reason, 'muted', colors.ORANGE, config.data.emoji.mute, duration)
.toMessage());
Expand All @@ -95,7 +97,7 @@ export default class MuteCommand extends UserCommand {
async executeButton(interaction) {
const parts = interaction.customId.split(':');
if (parts[1] === 'confirm') {
/** @type {Confirmation<{reason: ?string, duration: ?number, user: import('discord.js').Snowflake}>}*/
/** @type {Confirmation<{reason: ?string, comment: ?string, duration: ?number, user: import('discord.js').Snowflake}>}*/
const data = await Confirmation.get(parts[2]);
if (!data) {
await interaction.update({content: 'This confirmation has expired.', embeds: [], components: []});
Expand All @@ -106,6 +108,7 @@ export default class MuteCommand extends UserCommand {
interaction,
await MemberWrapper.getMember(interaction, data.data.user),
data.data.reason,
data.data.comment,
data.data.duration,
);
return;
Expand Down Expand Up @@ -143,6 +146,14 @@ export default class MuteCommand extends UserCommand {
.setStyle(TextInputStyle.Paragraph)
.setPlaceholder('No reason provided')),
/** @type {*} */
new ActionRowBuilder()
.addComponents(/** @type {*} */ new TextInputBuilder()
.setRequired(false)
.setLabel('Comment')
.setCustomId('comment')
.setStyle(TextInputStyle.Paragraph)
.setPlaceholder('No internal comment')),
/** @type {*} */
new ActionRowBuilder()
.addComponents(/** @type {*} */ new TextInputBuilder()
.setRequired(false)
Expand All @@ -153,14 +164,19 @@ export default class MuteCommand extends UserCommand {
}

async executeModal(interaction) {
let reason, duration;
let reason, duration, comment;
for (const row of interaction.components) {
for (const component of row.components) {
if (component.customId === 'reason') {
reason = component.value || 'No reason provided';
}
else if (component.customId === 'duration') {
duration = parseTime(component.value);
switch (component.customId) {
case 'reason':
reason = component.value || 'No reason provided';
break;
case 'comment':
comment = component.value || null;
break;
case 'duration':
duration = parseTime(component.value);
break;
}
}
}
Expand All @@ -169,6 +185,7 @@ export default class MuteCommand extends UserCommand {
interaction,
await MemberWrapper.getMemberFromCustomId(interaction),
reason,
comment,
duration
);
}
Expand Down
Loading

0 comments on commit 5d9d4a1

Please sign in to comment.