diff --git a/src/commands/confessbanlist.ts b/src/commands/confessbanlist.ts new file mode 100644 index 0000000..95fbf9d --- /dev/null +++ b/src/commands/confessbanlist.ts @@ -0,0 +1,43 @@ +/* + * 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 . + */ + +import { CommandInteraction,PermissionFlagsBits,SlashCommandBuilder } from "discord.js"; +import { dt } from "../main"; +import { BotClient } from "../bot"; + +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 (const member of bannedMembers) { + const identifiedMember = await BotClient.users.fetch(member.user); + + content += `\n${identifiedMember.displayName} | \`${member.confessionId}\``; + } + + return interaction.reply({ + content: content, + ephemeral: true + }) +} diff --git a/src/commands/index.ts b/src/commands/index.ts index 58af41e..b6009cc 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -19,6 +19,7 @@ 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 ping from "./ping"; import * as setup from "./setup"; @@ -27,6 +28,7 @@ export const commands = { confess, confessdel, confessban, + confessbanlist, confesspardon, ping, setup diff --git a/src/storeman/client.ts b/src/storeman/client.ts index eea6454..0df819f 100644 --- a/src/storeman/client.ts +++ b/src/storeman/client.ts @@ -18,7 +18,7 @@ import fs from "fs"; import crypto from "crypto"; -import { Confession, GuildData, GuildSettings } from "./types"; +import { Confession, ConfessionBan, GuildData, GuildSettings } from "./types"; import { DATA_DIR } from "./config"; import { CommandInteraction, Message } from "discord.js"; @@ -194,7 +194,7 @@ export class StoreMan { for (const guild of this.data) { if (guild.id === guildId) { for (const ban of guild.settings.bans) { - if (ban === userId) { + if (ban.user === userId) { return true; } } @@ -204,7 +204,7 @@ export class StoreMan { return false; } - public getBans(guildId: string): string[] { + public getBans(guildId: string): ConfessionBan[] { for (const guild of this.data) { if (guild.id === guildId) { return guild.settings.bans; @@ -223,7 +223,10 @@ export class StoreMan { if (confession) { // Only add the user to the ban list if they aren't banned already !this.isBanned(guildId, confession.authorId) && - guild.settings.bans.push(confession.authorId!); + guild.settings.bans.push({ + user: confession.authorId, + confessionId: confessionId + }); this.saveFile(); return true; @@ -240,7 +243,7 @@ export class StoreMan { if (guild.id === guildId) { if (this.getConfession(guildId, confessionId)) { guild.settings.bans = guild.settings.bans.filter(ban => { - return ban !== this.getConfession(guildId, confessionId)?.authorId!; + return ban.user !== this.getConfession(guildId, confessionId)?.authorId!; }); this.saveFile(); diff --git a/src/storeman/types.ts b/src/storeman/types.ts index 7d16ae5..4a76c2b 100644 --- a/src/storeman/types.ts +++ b/src/storeman/types.ts @@ -24,10 +24,15 @@ export interface Confession { content: string; } +export interface ConfessionBan { + user: string; + confessionId: string; +} + export interface GuildSettings { confessChannel: string; modChannel: string; - bans: string[]; + bans: ConfessionBan[]; } export interface GuildData {