From 53c0e3e4882614ee423d67f802681a13554560d4 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Sat, 17 Aug 2024 15:26:17 +0100 Subject: [PATCH] Attempt to create dms to the user a moderation action was taken on --- src/commands/ban.ts | 23 +++++++++++++- src/commands/kick.ts | 23 +++++++++++++- src/commands/timeout.ts | 66 +++++++++++++---------------------------- src/commands/warn.ts | 22 +++++++++++++- 4 files changed, 86 insertions(+), 48 deletions(-) diff --git a/src/commands/ban.ts b/src/commands/ban.ts index 46232e4..12c4278 100644 --- a/src/commands/ban.ts +++ b/src/commands/ban.ts @@ -62,7 +62,6 @@ export default class Ban extends Command { } await member.ban(); - await interaction.reply(`\`${targetUser.user.tag}\` has been banned.`); const channelName = await SettingsHelper.GetSetting('channels.logs.mod', interaction.guildId); @@ -74,7 +73,29 @@ export default class Ban extends Command { await channel.send({ embeds: [ logEmbed ]}); } + const dmEmbed = new EmbedBuilder() + .setColor(EmbedColours.Ok) + .setTitle(interaction.guild.name) + .setDescription("You have been banned by a moderator.") + .addFields([ + { + name: "Reason", + value: reason, + }, + ]); + + let replyText = "Successfully banned user."; + + try { + const dmChannel = await targetUser.user!.createDM(); + await dmChannel.send({ embeds: [ dmEmbed ] }); + } catch { + replyText += " *Note: I was unable to DM the user the reason.*"; + } + const audit = new Audit(targetUser.user.id, AuditType.Ban, reason, interaction.user.id, interaction.guildId); await audit.Save(Audit, audit); + + await interaction.reply(replyText); } } \ No newline at end of file diff --git a/src/commands/kick.ts b/src/commands/kick.ts index fefad26..a58461e 100644 --- a/src/commands/kick.ts +++ b/src/commands/kick.ts @@ -62,7 +62,6 @@ export default class Kick extends Command { } await member.kick(); - await interaction.reply(`\`${targetUser.user.tag}\` has been kicked.`); const channelName = await SettingsHelper.GetSetting('channels.logs.mod', interaction.guildId); @@ -74,7 +73,29 @@ export default class Kick extends Command { await channel.send({ embeds: [ logEmbed ]}); } + const dmEmbed = new EmbedBuilder() + .setColor(EmbedColours.Ok) + .setTitle(interaction.guild.name) + .setDescription("You have been kicked from the server.") + .addFields([ + { + name: "Reason", + value: reason, + }, + ]); + + let replyText = "Successfully kicked user."; + + try { + const dmChannel = await targetUser.user!.createDM(); + await dmChannel.send({ embeds: [ dmEmbed ] }); + } catch { + replyText += " *Note: I was unable to DM the user the reason.*"; + } + const audit = new Audit(targetUser.user.id, AuditType.Kick, reason, interaction.user.id, interaction.guildId); await audit.Save(Audit, audit); + + await interaction.reply(replyText); } } \ No newline at end of file diff --git a/src/commands/timeout.ts b/src/commands/timeout.ts index ad0ecd0..9ada281 100644 --- a/src/commands/timeout.ts +++ b/src/commands/timeout.ts @@ -104,54 +104,30 @@ export default class Timeout extends Command { await channel.send({ embeds: [ logEmbed ]}); } + const dmEmbed = new EmbedBuilder() + .setColor(EmbedColours.Ok) + .setTitle(interaction.guild.name) + .setDescription("You have been given a warning by a moderator.") + .addFields([ + { + name: "Reason", + value: reason || "*none*", + }, + ]); + + let replyText = "Successfully warned user."; + + try { + const dmChannel = await targetUser.user!.createDM(); + await dmChannel.send({ embeds: [ dmEmbed ] }); + } catch { + replyText += " *Note: I was unable to DM the user the reason.*"; + } + // Create Audit const audit = new Audit(targetUser.user.id, AuditType.Timeout, reason || "*none*", interaction.user.id, interaction.guildId); await audit.Save(Audit, audit); - // DM User, if possible - const resultEmbed = new EmbedBuilder() - .setColor(EmbedColours.Ok) - .setDescription(`<@${targetUser.user.id}> has been timed out`); - - const dmEmbed = new EmbedBuilder() - .setColor(EmbedColours.Ok) - .setDescription(`You have been timed out in ${interaction.guild.name}`) - .addFields([ - { - name: "Reason", - value: reason || "*none*" - }, - { - name: "Length", - value: timeLength.GetLengthShort(), - }, - { - name: "Until", - value: timeLength.GetDateFromNow().toString(), - }, - ]); - - try { - const dmChannel = await targetUser.user.createDM(); - - await dmChannel.send({ embeds: [ dmEmbed ]}); - - resultEmbed.addFields([ - { - name: "DM Sent", - value: "true", - }, - ]); - } catch { - resultEmbed.addFields([ - { - name: "DM Sent", - value: "false", - }, - ]); - } - - // Success Reply - await interaction.reply({ embeds: [ resultEmbed ]}); + await interaction.reply(replyText); } } \ No newline at end of file diff --git a/src/commands/warn.ts b/src/commands/warn.ts index a088187..96d9cf5 100644 --- a/src/commands/warn.ts +++ b/src/commands/warn.ts @@ -63,9 +63,29 @@ export default class Warn extends Command { await channel.send({ embeds: [ logEmbed ]}); } + const dmEmbed = new EmbedBuilder() + .setColor(EmbedColours.Ok) + .setTitle(interaction.guild.name) + .setDescription("You have been given a warning by a moderator.") + .addFields([ + { + name: "Reason", + value: reason, + }, + ]); + + let replyText = "Successfully warned user."; + + try { + const dmChannel = await targetUser.user!.createDM(); + await dmChannel.send({ embeds: [ dmEmbed ] }); + } catch { + replyText += " *Note: I was unable to DM the user the reason.*"; + } + const audit = new Audit(targetUser.user.id, AuditType.Warn, reason, interaction.user.id, interaction.guildId); await audit.Save(Audit, audit); - await interaction.reply('Successfully warned user.'); + await interaction.reply(replyText); } } \ No newline at end of file