blob: 8fe9f16c0a716e334544bc5a3d0beb3be11325dd [file] [log] [blame]
pineafan3a02ea32022-08-11 21:35:04 +01001// @ts-expect-error
pineafan63fc5e22022-08-04 22:04:10 +01002import humanizeDuration from "humanize-duration";
pineafan3a02ea32022-08-11 21:35:04 +01003import type { CommandInteraction, GuildMember, TextChannel } from "discord.js";
TheCodedProff86ba092023-01-27 17:10:07 -05004import type { SlashCommandSubcommandBuilder } from "discord.js";
pineafan167bde32022-05-19 19:33:46 +01005import keyValueList from "../../utils/generateKeyValueList.js";
6import confirmationMessage from "../../utils/confirmationMessage.js";
pineafan4edb7762022-06-26 19:21:04 +01007import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
8
pineafan4f164f32022-02-26 22:07:12 +00009const command = (builder: SlashCommandSubcommandBuilder) =>
10 builder
pineafan63fc5e22022-08-04 22:04:10 +010011 .setName("slowmode")
12 .setDescription("Manages slowmode in a channel")
Skyler Grey75ea9172022-08-06 10:22:23 +010013 .addStringOption((option) =>
14 option
15 .setName("time")
16 .setDescription("The delay between messages")
17 .setRequired(false)
PineaFan64486c42022-12-28 09:21:04 +000018 .addChoices(
Skyler Greyda16adf2023-03-05 10:22:12 +000019 { name: "Off", value: "0" },
20 { name: "5 seconds", value: "5" },
21 { name: "10 seconds", value: "10" },
22 { name: "15 seconds", value: "15" },
23 { name: "30 seconds", value: "30" },
24 { name: "1 minute", value: "60" },
25 { name: "2 minutes", value: "120" },
26 { name: "5 minutes", value: "300" },
27 { name: "10 minutes", value: "600" },
28 { name: "15 minutes", value: "900" },
29 { name: "30 minutes", value: "1800" },
30 { name: "1 hour", value: "3600" },
31 { name: "2 hours", value: "7200" },
32 { name: "6 hours", value: "21600" }
PineaFan64486c42022-12-28 09:21:04 +000033 )
Skyler Grey75ea9172022-08-06 10:22:23 +010034 );
pineafan4f164f32022-02-26 22:07:12 +000035
pineafanbd02b4a2022-08-05 22:01:38 +010036const callback = async (interaction: CommandInteraction): Promise<void> => {
Skyler Greyda16adf2023-03-05 10:22:12 +000037 let time = parseInt((interaction.options.get("time")?.value as string) || "0");
Skyler Grey11236ba2022-08-08 21:13:33 +010038 if (time === 0 && (interaction.channel as TextChannel).rateLimitPerUser === 0) {
Skyler Grey75ea9172022-08-06 10:22:23 +010039 time = 10;
40 }
pineafan63fc5e22022-08-04 22:04:10 +010041 const confirmation = await new confirmationMessage(interaction)
pineafan4edb7762022-06-26 19:21:04 +010042 .setEmoji("CHANNEL.SLOWMODE.OFF")
pineafan663dc472022-05-10 18:13:47 +010043 .setTitle("Slowmode")
Skyler Grey75ea9172022-08-06 10:22:23 +010044 .setDescription(
45 keyValueList({
Skyler Grey11236ba2022-08-08 21:13:33 +010046 time: time ? humanizeDuration(time * 1000, { round: true }) : "No delay"
Skyler Grey75ea9172022-08-06 10:22:23 +010047 }) + "Are you sure you want to set the slowmode in this channel?"
48 )
pineafan663dc472022-05-10 18:13:47 +010049 .setColor("Danger")
TheCodedProf1f675042023-02-16 17:01:29 -050050 .setFailedMessage("No changes were made", "Success", "CHANNEL.SLOWMODE.ON")
pineafan63fc5e22022-08-04 22:04:10 +010051 .send();
PineaFan1dee28f2023-01-16 22:09:07 +000052 if (confirmation.cancelled || !confirmation.success) return;
53 try {
Skyler Greyf4f21c42023-03-08 14:36:29 +000054 await (interaction.channel as TextChannel).setRateLimitPerUser(time);
PineaFan1dee28f2023-01-16 22:09:07 +000055 } catch (e) {
Skyler Grey75ea9172022-08-06 10:22:23 +010056 await interaction.editReply({
57 embeds: [
58 new EmojiEmbed()
PineaFan1dee28f2023-01-16 22:09:07 +000059 .setEmoji("CHANNEL.SLOWMODE.OFF")
Skyler Grey75ea9172022-08-06 10:22:23 +010060 .setTitle("Slowmode")
PineaFan1dee28f2023-01-16 22:09:07 +000061 .setDescription("Something went wrong while setting the slowmode")
62 .setStatus("Danger")
Skyler Grey75ea9172022-08-06 10:22:23 +010063 ],
64 components: []
65 });
pineafan663dc472022-05-10 18:13:47 +010066 }
PineaFan1dee28f2023-01-16 22:09:07 +000067 await interaction.editReply({
68 embeds: [
69 new EmojiEmbed()
70 .setEmoji("CHANNEL.SLOWMODE.ON")
71 .setTitle("Slowmode")
72 .setDescription("The channel slowmode was set successfully")
73 .setStatus("Success")
74 ],
75 components: []
76 });
pineafan63fc5e22022-08-04 22:04:10 +010077};
pineafan4f164f32022-02-26 22:07:12 +000078
TheCodedProff86ba092023-01-27 17:10:07 -050079const check = (interaction: CommandInteraction, partial: boolean = false) => {
Skyler Grey75ea9172022-08-06 10:22:23 +010080 const member = interaction.member as GuildMember;
pineafan167bde32022-05-19 19:33:46 +010081 // Check if the user has manage_channel permission
PineaFan0d06edc2023-01-17 22:10:31 +000082 if (!member.permissions.has("ManageChannels")) return "You do not have the *Manage Channels* permission";
TheCodedProff86ba092023-01-27 17:10:07 -050083 if (partial) return true;
84 // Check if Nucleus can set the slowmode
Skyler Greyda16adf2023-03-05 10:22:12 +000085 if (!interaction.guild!.members.me!.permissions.has("ManageChannels"))
86 return "I do not have the *Manage Channels* permission";
pineafan663dc472022-05-10 18:13:47 +010087 // Allow slowmode
pineafan63fc5e22022-08-04 22:04:10 +010088 return true;
89};
pineafan4f164f32022-02-26 22:07:12 +000090
Skyler Grey75ea9172022-08-06 10:22:23 +010091export { command, callback, check };
TheCodedProfa112f612023-01-28 18:06:45 -050092export const metadata = {
Skyler Greyda16adf2023-03-05 10:22:12 +000093 longDescription:
94 "Stops members from being able to send messages without waiting a certain amount of time between messages.",
95 premiumOnly: true
96};