Improve message deletion messages
This commit is contained in:
parent
025a503abb
commit
8368beca29
|
@ -32,6 +32,7 @@ import { StoreMan } from "../storeman";
|
||||||
import getRandomColor from "../utils/getRandomColor";
|
import getRandomColor from "../utils/getRandomColor";
|
||||||
import Logger from "../utils/Logger";
|
import Logger from "../utils/Logger";
|
||||||
import { submit } from "../modals";
|
import { submit } from "../modals";
|
||||||
|
import removeConfession from "../utils/removeConfession";
|
||||||
|
|
||||||
const logger = new Logger("(/) confess");
|
const logger = new Logger("(/) confess");
|
||||||
|
|
||||||
|
@ -136,8 +137,14 @@ export async function execute(interaction: ChatInputCommandInteraction) {
|
||||||
.setLabel("Submit a Confession")
|
.setLabel("Submit a Confession")
|
||||||
.setStyle(ButtonStyle.Primary);
|
.setStyle(ButtonStyle.Primary);
|
||||||
|
|
||||||
|
// const deleteConfessionButton = new ButtonBuilder()
|
||||||
|
// .setCustomId("deleteConfession")
|
||||||
|
// .setLabel("Delete")
|
||||||
|
// .setStyle(ButtonStyle.Danger);
|
||||||
|
|
||||||
const actionRow = new ActionRowBuilder<ButtonBuilder>().setComponents(
|
const actionRow = new ActionRowBuilder<ButtonBuilder>().setComponents(
|
||||||
submitConfessionButton
|
submitConfessionButton
|
||||||
|
// deleteConfessionButton
|
||||||
);
|
);
|
||||||
|
|
||||||
const message = await (
|
const message = await (
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
import {
|
import {
|
||||||
ChatInputCommandInteraction,
|
ChatInputCommandInteraction,
|
||||||
EmbedBuilder,
|
EmbedBuilder,
|
||||||
|
PermissionFlagsBits,
|
||||||
SlashCommandBuilder,
|
SlashCommandBuilder,
|
||||||
TextChannel
|
TextChannel
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
|
@ -48,11 +49,15 @@ export async function execute(interaction: ChatInputCommandInteraction) {
|
||||||
|
|
||||||
const idVal = interaction.options.getString("id")!;
|
const idVal = interaction.options.getString("id")!;
|
||||||
const result = dt.getConfession(interaction.guild?.id!, idVal);
|
const result = dt.getConfession(interaction.guild?.id!, idVal);
|
||||||
|
// If there is a result, and the user is either an author or has manage messages
|
||||||
|
const allowedByUser = result && result.authorId === interaction.user.id;
|
||||||
|
const allowedByMod =
|
||||||
|
result &&
|
||||||
|
interaction.memberPermissions?.has(PermissionFlagsBits.ManageMessages);
|
||||||
|
|
||||||
// If a confession is found with the given ID, check if the user is the one that posted it, and delete it if they are.
|
// If a confession is found with the given ID, check if the user is the one that posted it, and delete it if they are.
|
||||||
// Otherwise, don't let the user delete anything.
|
// Otherwise, don't let the user delete anything.
|
||||||
if (result) {
|
if (allowedByUser || allowedByMod) {
|
||||||
try {
|
|
||||||
const confession = dt.getConfession(
|
const confession = dt.getConfession(
|
||||||
interaction.guild?.id!,
|
interaction.guild?.id!,
|
||||||
idVal
|
idVal
|
||||||
|
@ -62,8 +67,13 @@ export async function execute(interaction: ChatInputCommandInteraction) {
|
||||||
const emptyEmbed = new EmbedBuilder()
|
const emptyEmbed = new EmbedBuilder()
|
||||||
.setColor(getRandomColor())
|
.setColor(getRandomColor())
|
||||||
.setTitle("Confession Deleted")
|
.setTitle("Confession Deleted")
|
||||||
.setDescription("[Confession Deleted]");
|
.setDescription(
|
||||||
|
allowedByUser
|
||||||
|
? "[Confession removed by user]"
|
||||||
|
: "[Confession removed by moderator]"
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
// Replace the given confession with an empty embed
|
// Replace the given confession with an empty embed
|
||||||
await (BotClient.channels.cache.get(channelId) as TextChannel).messages
|
await (BotClient.channels.cache.get(channelId) as TextChannel).messages
|
||||||
.fetch(confession!)
|
.fetch(confession!)
|
||||||
|
@ -78,13 +88,31 @@ export async function execute(interaction: ChatInputCommandInteraction) {
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error("An error occured:", err);
|
logger.error("A confession delete error occured:", err);
|
||||||
|
return interaction.reply({
|
||||||
|
content: "An error occured.",
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return interaction.reply({
|
try {
|
||||||
|
// If there was a result, the user wasn't allowed to remove it, otherwise it didn't exist.
|
||||||
|
return result
|
||||||
|
? interaction.reply({
|
||||||
|
content: "You are not allowed to remove this confession.",
|
||||||
|
ephemeral: true
|
||||||
|
})
|
||||||
|
: interaction.reply({
|
||||||
content:
|
content:
|
||||||
"Either the confession wasn't found or you may not be allowed to remove it.",
|
"Either the confession wasn't found or you may not be allowed to remove it.",
|
||||||
ephemeral: true
|
ephemeral: true
|
||||||
});
|
});
|
||||||
|
} catch (err) {
|
||||||
|
logger.error("A confession delete interaction occured:", err);
|
||||||
|
return interaction.reply({
|
||||||
|
content: "An error occured.",
|
||||||
|
ephemeral: true
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue