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 confess from "./confess";
|
||||||
import * as confessdel from "./confessdel";
|
import * as confessdel from "./confessdel";
|
||||||
import * as confessban from "./confessban";
|
import * as confessban from "./confessban";
|
||||||
|
import * as confessbanlist from "./confessbanlist";
|
||||||
import * as confesspardon from "./confesspardon";
|
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";
|
||||||
|
@ -27,6 +28,7 @@ export const commands = {
|
||||||
confess,
|
confess,
|
||||||
confessdel,
|
confessdel,
|
||||||
confessban,
|
confessban,
|
||||||
|
confessbanlist,
|
||||||
confesspardon,
|
confesspardon,
|
||||||
ping,
|
ping,
|
||||||
setup
|
setup
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import crypto from "crypto";
|
import crypto from "crypto";
|
||||||
import { Confession, GuildData, GuildSettings } from "./types";
|
import { Confession, ConfessionBan, GuildData, GuildSettings } from "./types";
|
||||||
import { DATA_DIR } from "./config";
|
import { DATA_DIR } from "./config";
|
||||||
import { CommandInteraction, Message } from "discord.js";
|
import { CommandInteraction, Message } from "discord.js";
|
||||||
|
|
||||||
|
@ -194,7 +194,7 @@ export class StoreMan {
|
||||||
for (const guild of this.data) {
|
for (const guild of this.data) {
|
||||||
if (guild.id === guildId) {
|
if (guild.id === guildId) {
|
||||||
for (const ban of guild.settings.bans) {
|
for (const ban of guild.settings.bans) {
|
||||||
if (ban === userId) {
|
if (ban.user === userId) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -204,7 +204,7 @@ export class StoreMan {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public getBans(guildId: string): string[] {
|
public getBans(guildId: string): ConfessionBan[] {
|
||||||
for (const guild of this.data) {
|
for (const guild of this.data) {
|
||||||
if (guild.id === guildId) {
|
if (guild.id === guildId) {
|
||||||
return guild.settings.bans;
|
return guild.settings.bans;
|
||||||
|
@ -223,7 +223,10 @@ export class StoreMan {
|
||||||
if (confession) {
|
if (confession) {
|
||||||
// Only add the user to the ban list if they aren't banned already
|
// Only add the user to the ban list if they aren't banned already
|
||||||
!this.isBanned(guildId, confession.authorId) &&
|
!this.isBanned(guildId, confession.authorId) &&
|
||||||
guild.settings.bans.push(confession.authorId!);
|
guild.settings.bans.push({
|
||||||
|
user: confession.authorId,
|
||||||
|
confessionId: confessionId
|
||||||
|
});
|
||||||
|
|
||||||
this.saveFile();
|
this.saveFile();
|
||||||
return true;
|
return true;
|
||||||
|
@ -240,7 +243,7 @@ export class StoreMan {
|
||||||
if (guild.id === guildId) {
|
if (guild.id === guildId) {
|
||||||
if (this.getConfession(guildId, confessionId)) {
|
if (this.getConfession(guildId, confessionId)) {
|
||||||
guild.settings.bans = guild.settings.bans.filter(ban => {
|
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();
|
this.saveFile();
|
||||||
|
|
|
@ -24,10 +24,15 @@ export interface Confession {
|
||||||
content: string;
|
content: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ConfessionBan {
|
||||||
|
user: string;
|
||||||
|
confessionId: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface GuildSettings {
|
export interface GuildSettings {
|
||||||
confessChannel: string;
|
confessChannel: string;
|
||||||
modChannel: string;
|
modChannel: string;
|
||||||
bans: string[];
|
bans: ConfessionBan[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface GuildData {
|
export interface GuildData {
|
||||||
|
|
Loading…
Reference in a new issue