Add detailed ban searching
This commit is contained in:
parent
1612fa8ca1
commit
11404358eb
43
src/commands/confessbanlist.ts
Normal file
43
src/commands/confessbanlist.ts
Normal file
|
@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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
|
||||
})
|
||||
}
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue