/* eslint-disable @typescript-eslint/no-non-null-assertion */ import { ChannelType, SlashCommandBuilder } from "discord.js"; import Command from "../../Structures/Command.js"; import getGuild from "../../functions/getGuild.command.js"; export default new Command({ data: new SlashCommandBuilder() .setName("moderators") .setDescription("Manage moderators to ping when post is created") .addSubcommand((subcommand) => subcommand .setName("addrole") .setDescription("Add a role to ping") .addChannelOption((channel) => channel .addChannelTypes(ChannelType.GuildForum) .setName("forum") .setDescription("Forum to add the role ping to") .setRequired(true), ) .addRoleOption((role) => role .setName("role") .setDescription("The role to ping") .setRequired(true), ), ) .addSubcommand((subcommand) => subcommand .setName("adduser") .setDescription("Add a user to ping") .addChannelOption((channel) => channel .addChannelTypes(ChannelType.GuildForum) .setName("forum") .setDescription("Forum to add the role ping to") .setRequired(true), ) .addUserOption((user) => user.setName("user").setDescription("User to ping").setRequired(true), ), ) .addSubcommand((subcommand) => subcommand .setName("removerole") .setDescription("Remove a role from being pinged") .addChannelOption((channel) => channel .addChannelTypes(ChannelType.GuildForum) .setName("forum") .setDescription("Forum to remove the role ping from") .setRequired(true), ) .addRoleOption((role) => role .setName("role") .setDescription("The role to stop pinging") .setRequired(true), ), ) .addSubcommand((subcommand) => subcommand .setName("removeuser") .setDescription("Remove a user from being pinged") .addChannelOption((channel) => channel .addChannelTypes(ChannelType.GuildForum) .setName("forum") .setDescription("Forum to remove the role ping from") .setRequired(true), ) .addUserOption((user) => user .setName("user") .setDescription("User to stop pinging") .setRequired(true), ), ) .addSubcommand((subcommand) => subcommand .setName("pingmoderators") .setDescription("Toggle pinging moderators") .addChannelOption((channel) => channel .addChannelTypes(ChannelType.GuildForum) .setName("forum") .setDescription("Forum to remove the role ping from") .setRequired(true), ) .addBooleanOption((boolean) => boolean .setName("ping_moderators") .setDescription( "Whether the bot should ghost ping added moderators.", ) .setRequired(true), ), ), async run(client, interaction) { const subcommand = interaction.options.getSubcommand() as | "addrole" | "adduser" | "removerole" | "removeuser" | "pingmoderators"; const guildData = await getGuild(interaction.guildId!); let channelId = interaction.options.getChannel("forum")!.id; const channel = guildData.forums.find((ch) => ch.channelId === channelId); if (!channel) { await interaction.reply("Channel not found."); return; } switch (subcommand) { case "addrole": { const role = interaction.options.getRole("role", true).id; const toAdd = `${role}-role`; if (channel?.moderators.includes(toAdd)) { await interaction.reply(`Nothing to add.`); return; } channel?.moderators.push(toAdd); await guildData.save(); await interaction.reply("Successfully added the moderator."); break; } case "adduser": { const toAdd = interaction.options.getUser("user", true).id; if (channel?.moderators.includes(toAdd)) { await interaction.reply(`Nothing to add.`); return; } channel?.moderators.push(toAdd); await guildData.save(); await interaction.reply("Successfully added the moderator."); break; } case "removerole": { const toRemove = interaction.options.getRole("role", true).id + "-role"; if (!channel?.moderators.includes(toRemove)) { await interaction.reply(`Nothing to remove.`); return; } const index = channel?.moderators?.findIndex((val) => val === toRemove); if (index !== -1) { channel?.moderators.splice(index, 1); await guildData.save(); await interaction.reply(`Successfully removed the moderator.`); } else { await interaction.reply(`Nothing to remove.`); return; } break; } case "removeuser": { const toRemove = interaction.options.getUser("user", true).id; if (!channel?.moderators.includes(toRemove)) { await interaction.reply(`Nothing to remove.`); return; } const index = channel?.moderators?.findIndex((val) => val === toRemove); if (index !== -1) { channel?.moderators.splice(index, 1); await guildData.save(); await interaction.reply(`Successfully removed the moderator.`); } else { await interaction.reply(`Nothing to remove.`); return; } break; } case "pingmoderators": { if (!channel) { await interaction.reply("Invalid forum channel."); return; } const boolean = interaction.options.getBoolean("ping_moderators", true); channel.ping_moderators = boolean; await guildData.save(); await interaction.reply( `Ping moderators ${boolean ? "enabled" : "disabled"}.`, ); break; } } }, });