Compare commits

...

4 commits

Author SHA1 Message Date
powermaker450 d808ef0f15 Add timestamp for admin confession embeds 2024-10-14 12:41:52 -04:00
powermaker450 8368beca29 Improve message deletion messages 2024-10-14 12:37:02 -04:00
powermaker450 025a503abb Check if a user is banned from confessions before displaying the modal 2024-10-14 11:52:04 -04:00
powermaker450 b45daf8fa2 Combine all the moderation commands into one 2024-10-14 11:48:00 -04:00
7 changed files with 215 additions and 208 deletions

View file

@ -104,9 +104,9 @@ export async function execute(interaction: ChatInputCommandInteraction) {
//
// |
// | Anonymous Confession a1b2
// |
// |
// | "example confession content"
// |
// |
// | Author
// | @user1
// |
@ -117,6 +117,7 @@ export async function execute(interaction: ChatInputCommandInteraction) {
const adminConfessionEmbed = new EmbedBuilder()
.setColor(color)
.setTitle(`Anonymous Confession \`${messageId}\``)
.setTimestamp(Date.now())
.setDescription(messageContent)
.addFields(
{
@ -136,8 +137,14 @@ export async function execute(interaction: ChatInputCommandInteraction) {
.setLabel("Submit a Confession")
.setStyle(ButtonStyle.Primary);
// const deleteConfessionButton = new ButtonBuilder()
// .setCustomId("deleteConfession")
// .setLabel("Delete")
// .setStyle(ButtonStyle.Danger);
const actionRow = new ActionRowBuilder<ButtonBuilder>().setComponents(
submitConfessionButton
// deleteConfessionButton
);
const message = await (
@ -153,7 +160,13 @@ export async function execute(interaction: ChatInputCommandInteraction) {
collector.on("collect", i => {
if (i.customId === "submitConfession") {
i.showModal(submit);
// Check if the user is banned from confessions first before displaying the modal
dt.isBanned(i.guild.id, i.user.id)
? i.reply({
content: "You are banned from confessions in this server!",
ephemeral: true
})
: i.showModal(submit);
}
});

View file

@ -1,66 +0,0 @@
/*
* 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/>.
*/
import {
ChatInputCommandInteraction,
PermissionFlagsBits,
SlashCommandBuilder
} from "discord.js";
import { dt } from "../main";
import Logger from "../utils/Logger";
const logger = new Logger("(/) confessban");
export const data = new SlashCommandBuilder()
.setName("confessban")
.setDescription("Ban a user from submitting confessions.")
.addStringOption(option =>
option
.setName("id")
.setDescription("The confession ID to ban")
.setRequired(true)
)
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers);
export async function execute(interaction: ChatInputCommandInteraction) {
const guildId = interaction.guild?.id!;
const confessionId = interaction.options.getString("id")!;
if (dt.isBanned(guildId, confessionId)) {
return interaction.reply({
content: "That user is already banned!",
ephemeral: true
});
}
const result = dt.addBan(guildId, confessionId);
try {
return result
? interaction.reply({
content: "User was banned.",
ephemeral: true
})
: interaction.reply({
content: "No confession with that ID was found.",
ephemeral: true
});
} catch (err) {
logger.error("An error occured:", err);
}
}

View file

@ -1,55 +0,0 @@
/*
* 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/>.
*/
import {
CommandInteraction,
PermissionFlagsBits,
SlashCommandBuilder
} from "discord.js";
import { dt } from "../main";
export const data = new SlashCommandBuilder()
.setName("confessbanlist")
.setDescription("Get the current ban list")
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages);
export async function execute(interaction: CommandInteraction) {
const bannedMembers = dt.getBans(interaction.guild?.id!);
let content = bannedMembers.length
? "Banned Members:\n"
: "There are no banned members.";
// For each member, add them to the message content.
// It will end up looking something like this:
//
// Banned Members:
//
// @user1 | a1b2
// @user2 | c3d4
// @user3 | e5f6
//
for (const member of bannedMembers) {
content += `\n<@${member.user}> | \`${member.confessionId}\``;
}
return interaction.reply({
content: content,
ephemeral: true
});
}

View file

@ -19,6 +19,7 @@
import {
ChatInputCommandInteraction,
EmbedBuilder,
PermissionFlagsBits,
SlashCommandBuilder,
TextChannel
} from "discord.js";
@ -37,7 +38,6 @@ export const data = new SlashCommandBuilder()
);
export async function execute(interaction: ChatInputCommandInteraction) {
// If there is no guild info, don't let the user delete anything
if (!dt.getGuildInfo(interaction.guild?.id!)) {
return interaction.reply({
@ -49,22 +49,31 @@ export async function execute(interaction: ChatInputCommandInteraction) {
const idVal = interaction.options.getString("id")!;
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.
// Otherwise, don't let the user delete anything.
if (result) {
try {
const confession = dt.getConfession(
interaction.guild?.id!,
idVal
)?.messageId;
const channelId = dt.getGuildInfo(interaction.guild?.id!)?.settings
.confessChannel!;
const emptyEmbed = new EmbedBuilder()
.setColor(getRandomColor())
.setTitle("Confession Deleted")
.setDescription("[Confession Deleted]");
if (allowedByUser || allowedByMod) {
const confession = dt.getConfession(
interaction.guild?.id!,
idVal
)?.messageId;
const channelId = dt.getGuildInfo(interaction.guild?.id!)?.settings
.confessChannel!;
const emptyEmbed = new EmbedBuilder()
.setColor(getRandomColor())
.setTitle("Confession Deleted")
.setDescription(
allowedByUser
? "[Confession removed by user]"
: "[Confession removed by moderator]"
);
try {
// Replace the given confession with an empty embed
await (BotClient.channels.cache.get(channelId) as TextChannel).messages
.fetch(confession!)
@ -79,13 +88,31 @@ export async function execute(interaction: ChatInputCommandInteraction) {
ephemeral: true
});
} 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 {
return interaction.reply({
content:
"Either the confession wasn't found or you may not be allowed to remove it.",
ephemeral: true
});
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:
"Either the confession wasn't found or you may not be allowed to remove it.",
ephemeral: true
});
} catch (err) {
logger.error("A confession delete interaction occured:", err);
return interaction.reply({
content: "An error occured.",
ephemeral: true
});
}
}
}

151
src/commands/confessmod.ts Normal file
View file

@ -0,0 +1,151 @@
/*
* 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/>.
*/
import {
ChatInputCommandInteraction,
PermissionFlagsBits,
SlashCommandBuilder
} from "discord.js";
import { dt } from "../main";
import Logger from "../utils/Logger";
const logger = new Logger("(/) confessban");
export const data = new SlashCommandBuilder()
.setName("confessmod")
.setDescription("Moderate confessions")
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages)
.addSubcommand(ban =>
ban
.setName("ban")
.setDescription("Ban a user from confessions")
.addStringOption(option =>
option
.setName("id")
.setDescription("The confession ID to ban")
.setMinLength(4)
.setMaxLength(4)
.setRequired(true)
)
)
.addSubcommand(list =>
list.setName("list").setDescription("Show the list of banned users")
)
.addSubcommand(pardon =>
pardon
.setName("pardon")
.setDescription("Unban a user from confessions")
.addStringOption(id =>
id
.setName("id")
.setDescription("The confession ID to ban")
.setMinLength(4)
.setMaxLength(4)
.setRequired(true)
)
);
export async function execute(interaction: ChatInputCommandInteraction) {
const guildId = interaction.guild?.id!;
// /confessmod ban <id>
if (interaction.options.getSubcommand() === "ban") {
const confessionId = interaction.options.getString("id")!;
if (dt.isBanned(guildId, confessionId)) {
try {
return interaction.reply({
content: "That user is already banned!",
ephemeral: true
});
} catch (err) {
logger.error("A ban interaction error occured:", err);
}
}
const result = dt.addBan(guildId, confessionId);
try {
return result
? interaction.reply({
content: "User was banned.",
ephemeral: true
})
: interaction.reply({
content: "No confession with that ID was found.",
ephemeral: true
});
} catch (err) {
logger.error("A ban interaction error occured:", err);
}
// /confessmod list
} else if (interaction.options.getSubcommand() === "list") {
const bannedMembers = dt.getBans(interaction.guild?.id!);
let content = bannedMembers.length
? "Banned Members:\n"
: "There are no banned members.";
// For each member, add them to the message content.
// It will end up looking something like this:
//
// Banned Members:
//
// @user1 | a1b2
// @user2 | c3d4
// @user3 | e5f6
//
for (const member of bannedMembers) {
content += `\n<@${member.user}> | \`${member.confessionId}\``;
}
try {
return interaction.reply({
content: content,
ephemeral: true
});
} catch (err) {
logger.error("A banlist interaction error occured:", err);
}
// /confessmod pardon <id>
} else if (interaction.options.getSubcommand() === "pardon") {
const result = dt.removeBan(
interaction.guild?.id!,
interaction.options.getString("id")!
);
try {
return result
? interaction.reply({
content: "User was unbanned.",
ephemeral: true
})
: interaction.reply({
content: "No confession with that ID was found.",
ephemeral: true
});
} catch (err) {
logger.error("An unban interaction error occured:", err);
}
}
return interaction.reply({
content: "Unknown error",
ephemeral: true
});
}

View file

@ -1,59 +0,0 @@
/*
* 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/>.
*/
import {
ChatInputCommandInteraction,
PermissionFlagsBits,
SlashCommandBuilder
} from "discord.js";
import { dt } from "../main";
import Logger from "../utils/Logger";
const logger = new Logger("(/) confesspardon");
export const data = new SlashCommandBuilder()
.setName("confesspardon")
.setDescription("Unbans a user from confessions")
.addStringOption(option =>
option
.setName("id")
.setDescription("The confession ID to unban")
.setRequired(true)
)
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages);
export function execute(interaction: ChatInputCommandInteraction) {
const result = dt.removeBan(
interaction.guild?.id!,
interaction.options.getString("id")!
);
try {
return result
? interaction.reply({
content: "User was unbanned.",
ephemeral: true
})
: interaction.reply({
content: "No confession with that ID was found.",
ephemeral: true
});
} catch (err) {
logger.error("An error occured:", err);
}
}

View file

@ -18,18 +18,14 @@
import * as confess from "./confess";
import * as confessdel from "./confessdel";
import * as confessban from "./confessban";
import * as confessbanlist from "./confessbanlist";
import * as confesspardon from "./confesspardon";
import * as confessmod from "./confessmod";
import * as ping from "./ping";
import * as setup from "./setup";
export const commands = {
confess,
confessdel,
confessban,
confessbanlist,
confesspardon,
confessmod,
ping,
setup
};