Compare commits
4 commits
cdbe79f2a2
...
d808ef0f15
Author | SHA1 | Date | |
---|---|---|---|
d808ef0f15 | |||
8368beca29 | |||
025a503abb | |||
b45daf8fa2 |
|
@ -104,9 +104,9 @@ export async function execute(interaction: ChatInputCommandInteraction) {
|
||||||
//
|
//
|
||||||
// |
|
// |
|
||||||
// | Anonymous Confession a1b2
|
// | Anonymous Confession a1b2
|
||||||
// |
|
// |
|
||||||
// | "example confession content"
|
// | "example confession content"
|
||||||
// |
|
// |
|
||||||
// | Author
|
// | Author
|
||||||
// | @user1
|
// | @user1
|
||||||
// |
|
// |
|
||||||
|
@ -117,6 +117,7 @@ export async function execute(interaction: ChatInputCommandInteraction) {
|
||||||
const adminConfessionEmbed = new EmbedBuilder()
|
const adminConfessionEmbed = new EmbedBuilder()
|
||||||
.setColor(color)
|
.setColor(color)
|
||||||
.setTitle(`Anonymous Confession \`${messageId}\``)
|
.setTitle(`Anonymous Confession \`${messageId}\``)
|
||||||
|
.setTimestamp(Date.now())
|
||||||
.setDescription(messageContent)
|
.setDescription(messageContent)
|
||||||
.addFields(
|
.addFields(
|
||||||
{
|
{
|
||||||
|
@ -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 (
|
||||||
|
@ -153,7 +160,13 @@ export async function execute(interaction: ChatInputCommandInteraction) {
|
||||||
|
|
||||||
collector.on("collect", i => {
|
collector.on("collect", i => {
|
||||||
if (i.customId === "submitConfession") {
|
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);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -19,6 +19,7 @@
|
||||||
import {
|
import {
|
||||||
ChatInputCommandInteraction,
|
ChatInputCommandInteraction,
|
||||||
EmbedBuilder,
|
EmbedBuilder,
|
||||||
|
PermissionFlagsBits,
|
||||||
SlashCommandBuilder,
|
SlashCommandBuilder,
|
||||||
TextChannel
|
TextChannel
|
||||||
} from "discord.js";
|
} from "discord.js";
|
||||||
|
@ -37,7 +38,6 @@ export const data = new SlashCommandBuilder()
|
||||||
);
|
);
|
||||||
|
|
||||||
export async function execute(interaction: ChatInputCommandInteraction) {
|
export async function execute(interaction: ChatInputCommandInteraction) {
|
||||||
|
|
||||||
// If there is no guild info, don't let the user delete anything
|
// If there is no guild info, don't let the user delete anything
|
||||||
if (!dt.getGuildInfo(interaction.guild?.id!)) {
|
if (!dt.getGuildInfo(interaction.guild?.id!)) {
|
||||||
return interaction.reply({
|
return interaction.reply({
|
||||||
|
@ -49,22 +49,31 @@ 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
|
)?.messageId;
|
||||||
)?.messageId;
|
const channelId = dt.getGuildInfo(interaction.guild?.id!)?.settings
|
||||||
const channelId = dt.getGuildInfo(interaction.guild?.id!)?.settings
|
.confessChannel!;
|
||||||
.confessChannel!;
|
const emptyEmbed = new EmbedBuilder()
|
||||||
const emptyEmbed = new EmbedBuilder()
|
.setColor(getRandomColor())
|
||||||
.setColor(getRandomColor())
|
.setTitle("Confession Deleted")
|
||||||
.setTitle("Confession Deleted")
|
.setDescription(
|
||||||
.setDescription("[Confession Deleted]");
|
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!)
|
||||||
|
@ -79,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 {
|
||||||
content:
|
// If there was a result, the user wasn't allowed to remove it, otherwise it didn't exist.
|
||||||
"Either the confession wasn't found or you may not be allowed to remove it.",
|
return result
|
||||||
ephemeral: true
|
? 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
151
src/commands/confessmod.ts
Normal 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
|
||||||
|
});
|
||||||
|
}
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -18,18 +18,14 @@
|
||||||
|
|
||||||
import * as confess from "./confess";
|
import * as confess from "./confess";
|
||||||
import * as confessdel from "./confessdel";
|
import * as confessdel from "./confessdel";
|
||||||
import * as confessban from "./confessban";
|
import * as confessmod from "./confessmod";
|
||||||
import * as confessbanlist from "./confessbanlist";
|
|
||||||
import * as confesspardon from "./confesspardon";
|
|
||||||
import * as ping from "./ping";
|
import * as ping from "./ping";
|
||||||
import * as setup from "./setup";
|
import * as setup from "./setup";
|
||||||
|
|
||||||
export const commands = {
|
export const commands = {
|
||||||
confess,
|
confess,
|
||||||
confessdel,
|
confessdel,
|
||||||
confessban,
|
confessmod,
|
||||||
confessbanlist,
|
|
||||||
confesspardon,
|
|
||||||
ping,
|
ping,
|
||||||
setup
|
setup
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue