2024-10-12 16:04:54 -04:00
|
|
|
/*
|
|
|
|
* Confoss: Anonymous confessions for Discord, free as in freedom and price!
|
|
|
|
* Copyright (C) 2024 powermaker450
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published
|
|
|
|
* by the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2024-10-12 18:51:09 -04:00
|
|
|
*/
|
2024-10-12 16:04:54 -04:00
|
|
|
|
2024-10-12 18:51:09 -04:00
|
|
|
import {
|
2024-10-13 18:31:41 -04:00
|
|
|
ChatInputCommandInteraction,
|
2024-10-12 18:51:09 -04:00
|
|
|
CommandInteraction,
|
|
|
|
EmbedBuilder,
|
|
|
|
SlashCommandBuilder,
|
2024-10-13 11:06:08 -04:00
|
|
|
TextChannel
|
2024-10-12 18:51:09 -04:00
|
|
|
} from "discord.js";
|
2024-10-12 16:04:54 -04:00
|
|
|
import { dt } from "../main";
|
|
|
|
import { BotClient } from "../bot";
|
2024-10-12 18:34:30 -04:00
|
|
|
import getRandomColor from "../utils/getRandomColor";
|
2024-10-12 18:50:34 -04:00
|
|
|
import Logger from "../utils/Logger";
|
|
|
|
|
|
|
|
const logger = new Logger("(/) confessdel");
|
2024-10-12 16:04:54 -04:00
|
|
|
|
|
|
|
export const data = new SlashCommandBuilder()
|
|
|
|
.setName("confessdel")
|
|
|
|
.setDescription("Deletes a confession")
|
2024-10-13 11:06:08 -04:00
|
|
|
.addStringOption(option =>
|
|
|
|
option.setName("id").setDescription("The confession id").setRequired(true)
|
2024-10-12 18:51:09 -04:00
|
|
|
);
|
2024-10-12 16:04:54 -04:00
|
|
|
|
2024-10-13 18:31:41 -04:00
|
|
|
export async function execute(interaction: ChatInputCommandInteraction) {
|
2024-10-12 16:04:54 -04:00
|
|
|
if (!dt.getGuildInfo(interaction.guild?.id!)) {
|
|
|
|
return interaction.reply({
|
|
|
|
content:
|
|
|
|
"The bot hasn't been set up yet! Ask the server admins to set it up.",
|
2024-10-13 11:06:08 -04:00
|
|
|
ephemeral: true
|
2024-10-12 16:04:54 -04:00
|
|
|
});
|
|
|
|
}
|
2024-10-12 18:51:09 -04:00
|
|
|
|
2024-10-13 18:31:41 -04:00
|
|
|
const idVal = interaction.options.getString("id")!;
|
2024-10-12 18:34:30 -04:00
|
|
|
const result = dt.getConfession(interaction.guild?.id!, idVal);
|
2024-10-12 16:04:54 -04:00
|
|
|
|
|
|
|
if (result) {
|
2024-10-12 18:50:34 -04:00
|
|
|
try {
|
2024-10-12 18:51:09 -04:00
|
|
|
const confession = dt.getConfession(
|
|
|
|
interaction.guild?.id!,
|
2024-10-13 11:06:08 -04:00
|
|
|
idVal
|
2024-10-12 18:51:09 -04:00
|
|
|
)?.messageId;
|
|
|
|
const channelId = dt.getGuildInfo(interaction.guild?.id!)?.settings
|
|
|
|
.confessChannel!;
|
2024-10-12 18:50:34 -04:00
|
|
|
const emptyEmbed = new EmbedBuilder()
|
|
|
|
.setColor(getRandomColor())
|
|
|
|
.setTitle("Confession Deleted")
|
|
|
|
// @ts-ignore
|
|
|
|
.setDescription("[Confession Deleted]");
|
2024-10-12 16:04:54 -04:00
|
|
|
|
2024-10-12 18:51:09 -04:00
|
|
|
await (BotClient.channels.cache.get(channelId) as TextChannel).messages
|
|
|
|
.fetch(confession!)
|
2024-10-13 11:06:08 -04:00
|
|
|
.then(e => {
|
2024-10-12 18:51:09 -04:00
|
|
|
e.edit({
|
2024-10-13 11:06:08 -04:00
|
|
|
embeds: [emptyEmbed]
|
2024-10-12 18:51:09 -04:00
|
|
|
});
|
|
|
|
});
|
2024-10-12 16:04:54 -04:00
|
|
|
|
2024-10-12 18:50:34 -04:00
|
|
|
return interaction.reply({
|
|
|
|
content: "Confession removed.",
|
2024-10-13 11:06:08 -04:00
|
|
|
ephemeral: true
|
2024-10-12 18:50:34 -04:00
|
|
|
});
|
|
|
|
} catch (err) {
|
|
|
|
logger.error("An error occured:", err);
|
|
|
|
}
|
2024-10-12 16:04:54 -04:00
|
|
|
} else {
|
|
|
|
return interaction.reply({
|
2024-10-12 18:51:09 -04:00
|
|
|
content:
|
|
|
|
"Either the confession wasn't found or you may not be allowed to remove it.",
|
2024-10-13 11:06:08 -04:00
|
|
|
ephemeral: true
|
2024-10-12 16:04:54 -04:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|