Add pardonuser command

This commit is contained in:
powermaker450 2024-10-23 15:34:52 -04:00
parent f5b18513d2
commit a2279ef93c
2 changed files with 50 additions and 2 deletions

View file

@ -71,6 +71,17 @@ export const data = new SlashCommandBuilder()
.setMaxLength(4) .setMaxLength(4)
.setRequired(true) .setRequired(true)
) )
)
.addSubcommand(pardonuser =>
pardonuser
.setName("pardonuser")
.setDescription("Pardon a user from confessions")
.addUserOption(user =>
user
.setName("user")
.setDescription("The user to pardon")
.setRequired(true)
)
); );
export async function execute(interaction: ChatInputCommandInteraction) { export async function execute(interaction: ChatInputCommandInteraction) {
@ -172,7 +183,7 @@ export async function execute(interaction: ChatInputCommandInteraction) {
} }
// /confessmod pardon <id> // /confessmod pardon <id>
} else if (interaction.options.getSubcommand() === "pardon") { } else if (interaction.options.getSubcommand() === "pardon") {
const result = dt.removeBan(guildId, interaction.options.getString("id")!); const result = dt.removeBanById(guildId, interaction.options.getString("id")!);
try { try {
return result return result
@ -187,6 +198,24 @@ export async function execute(interaction: ChatInputCommandInteraction) {
} catch (err) { } catch (err) {
logger.error("An unban interaction error occured:", err); logger.error("An unban interaction error occured:", err);
} }
} else if (interaction.options.getSubcommand() === "pardonuser") {
const { id: userId } = interaction.options.getUser("user")!;
const result = dt.removeBanByUser(guildId, userId);
try {
return result
? interaction.reply({
content: "User was unbanned.",
ephemeral: true
})
: interaction.reply({
content: "That user is not banned from confessions.",
ephemeral: true
});
} catch (err) {
logger.error("An unban user interaction error occured:", err);
}
} }
return interaction.reply({ return interaction.reply({

View file

@ -302,7 +302,7 @@ export class StoreMan {
} }
// Attempts to pardon a user from a ban. If sucessfully completed, returns true, false if otherwise. // Attempts to pardon a user from a ban. If sucessfully completed, returns true, false if otherwise.
public removeBan(guildId: string, confessionId: string): boolean { public removeBanById(guildId: string, confessionId: string): boolean {
for (const guild of this.data) { for (const guild of this.data) {
if (guild.id === guildId) { if (guild.id === guildId) {
if (this.getConfession(guildId, confessionId)) { if (this.getConfession(guildId, confessionId)) {
@ -320,4 +320,23 @@ export class StoreMan {
return false; return false;
} }
public removeBanByUser(guildId: string, userId: string): boolean {
for (const guild of this.data) {
if (guild.id === guildId) {
for (const ban of guild.settings.bans) {
if (ban.method === BanReason.ByUser && ban.user === userId) {
guild.settings.bans = guild.settings.bans.filter(ban => {
return ban.user !== userId;
});
this.saveFile();
return true;
}
}
}
}
return false;
}
} }