Attempt to create dms to the user a moderation action was taken on (#469)
All checks were successful
Deploy To Stage / build (push) Successful in 6s
Deploy To Stage / deploy (push) Successful in 14s

- Attempt to create a dm to the user a moderation action was taken on
- If unable to dm, put a message onto the reply text to say the bot couldn't

#255

Reviewed-on: #469
Reviewed-by: VylpesTester <tester@vylpes.com>
Co-authored-by: Ethan Lane <ethan@vylpes.com>
Co-committed-by: Ethan Lane <ethan@vylpes.com>
This commit is contained in:
Ethan Lane 2024-08-17 16:56:32 +01:00 committed by Vylpes
parent 674a4ac614
commit 400a3bb5a2
4 changed files with 86 additions and 48 deletions

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}