Submit confessions as embeds

This commit is contained in:
powermaker450 2024-10-12 17:48:22 -04:00
parent 96563ddffa
commit a6fdaff7c5
3 changed files with 44 additions and 9 deletions

View file

@ -18,12 +18,14 @@
import { import {
CommandInteraction, CommandInteraction,
EmbedBuilder,
SlashCommandBuilder, SlashCommandBuilder,
TextChannel, TextChannel,
} from "discord.js"; } from "discord.js";
import { BotClient } from "../bot"; import { BotClient } from "../bot";
import { dt } from "../main"; import { dt } from "../main";
import { StoreMan } from "../storeman"; import { StoreMan } from "../storeman";
import getRandomColor from "../utils/getRandomColor";
export const data = new SlashCommandBuilder() export const data = new SlashCommandBuilder()
.setName("confess") .setName("confess")
@ -36,7 +38,6 @@ export const data = new SlashCommandBuilder()
); );
export async function execute(interaction: CommandInteraction) { export async function execute(interaction: CommandInteraction) {
if (dt.isBanned(interaction.guild?.id!, interaction.user.id)) { if (dt.isBanned(interaction.guild?.id!, interaction.user.id)) {
return interaction.reply({ return interaction.reply({
content: "You are banned from confessions in this server!", content: "You are banned from confessions in this server!",
@ -52,25 +53,46 @@ export async function execute(interaction: CommandInteraction) {
}); });
} }
const confessChannel = dt.getGuildInfo(interaction.guild?.id!)?.settings const confessChannel = dt.getGuildInfo(interaction.guild?.id!)?.settings
.confessChannel; .confessChannel;
const adminChannel = dt.getGuildInfo(interaction.guild?.id!)?.settings const adminChannel = dt.getGuildInfo(interaction.guild?.id!)?.settings
.modChannel; .modChannel;
const color = getRandomColor();
const messageId = StoreMan.genId(); const messageId = StoreMan.genId();
const userConfessionEmbed = new EmbedBuilder()
.setColor(color)
.setTitle(`Anonymous Confession ${messageId}`)
// @ts-ignore
.setDescription(`"${interaction.options.getString("message")}"`);
const adminConfessionEmbed = new EmbedBuilder()
.setColor(color)
.setTitle(`Anonymous Confession ${messageId}`)
// @ts-ignore
.setDescription(`"${interaction.options.getString("message")}"`)
.addFields({
name: "Author",
value: interaction.user.displayName
},
{
name: "Author ID",
value: interaction.user.id
}
);
const message = await ( const message = await (
BotClient.channels.cache.get(confessChannel!) as TextChannel BotClient.channels.cache.get(confessChannel!) as TextChannel
) )
.send( .send({
// @ts-ignore embeds: [userConfessionEmbed]
`# Confession ${messageId}:\n${interaction.options.getString("message")}`, });
);
await (BotClient.channels.cache.get(adminChannel!) as TextChannel) await (BotClient.channels.cache.get(adminChannel!) as TextChannel)
.send( .send({
// @ts-ignore embeds: [adminConfessionEmbed]
`# Confession ${messageId}:\n### Author: ${interaction.user.displayName}\n### Author ID: ${interaction.user.id}\n${interaction.options.getString("message")}`, });
);
dt.addConfession(message, messageId, interaction.user.displayName, interaction.user.id); dt.addConfession(message, messageId, interaction.user.displayName, interaction.user.id);

View file

@ -189,6 +189,16 @@ export class StoreMan {
return false; return false;
} }
public getBans(guildId: string): string[] {
for (const guild of this.data) {
if (guild.id === guildId) {
return guild.settings.bans;
}
}
return [];
}
// Attempts to ban a user from confessions. // Attempts to ban a user from confessions.
public addBan(guildId: string, confessionId: string): boolean { public addBan(guildId: string, confessionId: string): boolean {
const confession = this.getConfession(guildId, confessionId); const confession = this.getConfession(guildId, confessionId);

View file

@ -0,0 +1,3 @@
const getRandomColor = () => (Math.random() * 0xFFFFFF << 0);
export default getRandomColor;