Skip to content
This repository has been archived by the owner on Oct 12, 2024. It is now read-only.

Commit

Permalink
Send a dm of the case to the banned user
Browse files Browse the repository at this point in the history
Closes #17
  • Loading branch information
RealEthanPlayzDev committed Jan 21, 2024
1 parent 2cb87ad commit 90ec36d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 15 deletions.
19 changes: 14 additions & 5 deletions src/commands/Moderation/Ban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export const Command: MeteoriumCommand = {
const GuildUser = await interaction.guild.members.fetch(User).catch(() => null);
const GuildSchema = (await client.Database.guild.findUnique({ where: { GuildId: interaction.guildId } }))!;

await interaction.deferReply({ ephemeral: GuildSchema?.PublicModLogChannelId != "" });

if (User.id == interaction.user.id)
return await interaction.reply({ content: "You can't ban yourself!", ephemeral: true });
if (User.bot)
Expand Down Expand Up @@ -69,9 +71,6 @@ export const Command: MeteoriumCommand = {
NotAppealable: NotAppealable,
},
});
await interaction.guild.members.ban(User, {
reason: `Case ${CaseResult.CaseId} by ${interaction.user.username} (${interaction.user.id}): ${Reason}`,
});

const LogEmbed = new MeteoriumEmbedBuilder(undefined, interaction.user)
.setAuthor({
Expand All @@ -92,6 +91,17 @@ export const Command: MeteoriumCommand = {
.setTimestamp()
.setColor("Red");

try {
const DirectMessageChannnel = await User.createDM();
await DirectMessageChannnel.send({ embeds: [LogEmbed] });
} catch (err) {
client.Logging.GetNamespace("Moderation/Ban").warn(`Could not dm ${User.id}\n${err}`);
}

await interaction.guild.members.ban(User, {
reason: `Case ${CaseResult.CaseId} by ${interaction.user.username} (${interaction.user.id}): ${Reason}`,
});

const PublicModLogChannel = await interaction.guild.channels
.fetch(GuildSchema.PublicModLogChannelId)
.catch(() => null);
Expand Down Expand Up @@ -132,13 +142,12 @@ export const Command: MeteoriumCommand = {
})
.catch(() => null);

return await interaction.reply({
return await interaction.editReply({
content:
PublicModLogChannel != null && PublicModLogChannel.isTextBased()
? undefined
: "(Warning: could not send log message to the public mod log channel)",
embeds: [LogEmbed],
ephemeral: GuildSchema?.PublicModLogChannelId != "",
});
},
};
30 changes: 20 additions & 10 deletions src/commands/Moderation/TempBan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export const Command: MeteoriumCommand = {
const GuildUser = await interaction.guild.members.fetch(User).catch(() => null);
const GuildSchema = (await client.Database.guild.findUnique({ where: { GuildId: interaction.guildId } }))!;

await interaction.deferReply({ ephemeral: GuildSchema?.PublicModLogChannelId != "" });

if (User.id == interaction.user.id)
return await interaction.reply({ content: "You can't ban yourself!", ephemeral: true });
if (User.bot)
Expand Down Expand Up @@ -75,14 +77,6 @@ export const Command: MeteoriumCommand = {
ModeratorNote: ModeratorNote,
},
});
await client.Database.activeTempBans.create({
data: {
GlobalCaseId: CaseResult.GlobalCaseId,
},
});
await interaction.guild.members.ban(User, {
reason: `Case ${CaseResult.CaseId} by ${interaction.user.username} (${interaction.user.id}): ${Reason}`,
});

const LogEmbed = new MeteoriumEmbedBuilder(undefined, interaction.user)
.setAuthor({
Expand All @@ -103,6 +97,23 @@ export const Command: MeteoriumCommand = {
.setTimestamp()
.setColor("Red");

try {
const DirectMessageChannnel = await User.createDM();
await DirectMessageChannnel.send({ embeds: [LogEmbed] });
} catch (err) {
client.Logging.GetNamespace("Moderation/TempBan").warn(`Could not dm ${User.id}\n${err}`);
}

await interaction.guild.members.ban(User, {
reason: `Case ${CaseResult.CaseId} by ${interaction.user.username} (${interaction.user.id}): ${Reason}`,
});

await client.Database.activeTempBans.create({
data: {
GlobalCaseId: CaseResult.GlobalCaseId,
},
});

const PublicModLogChannel = await interaction.guild.channels
.fetch(GuildSchema.PublicModLogChannelId)
.catch(() => null);
Expand Down Expand Up @@ -143,13 +154,12 @@ export const Command: MeteoriumCommand = {
})
.catch(() => null);

return await interaction.reply({
return await interaction.editReply({
content:
PublicModLogChannel != null && PublicModLogChannel.isTextBased()
? undefined
: "(Warning: could not send log message to the public mod log channel)",
embeds: [LogEmbed],
ephemeral: GuildSchema?.PublicModLogChannelId != "",
});
},
Init(client) {
Expand Down

0 comments on commit 90ec36d

Please sign in to comment.