blob: f282e82382ef050e5aabf302358c4ffbaf203024 [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";
Samuel Shuert27bf3cd2023-03-03 15:51:25 -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(
19 {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"}
33 )
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> => {
PineaFana00db1b2023-01-02 15:32:54 +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")
Samuel Shuert27bf3cd2023-03-03 15:51:25 -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 {
54 (interaction.channel as TextChannel).setRateLimitPerUser(time);
55 } 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
Samuel Shuert27bf3cd2023-03-03 15:51:25 -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";
Samuel Shuert27bf3cd2023-03-03 15:51:25 -050083 if (partial) return true;
84 // Check if Nucleus can set the slowmode
85 if (!interaction.guild!.members.me!.permissions.has("ManageChannels")) return "I do not have the *Manage Channels* permission";
pineafan663dc472022-05-10 18:13:47 +010086 // Allow slowmode
pineafan63fc5e22022-08-04 22:04:10 +010087 return true;
88};
pineafan4f164f32022-02-26 22:07:12 +000089
Skyler Grey75ea9172022-08-06 10:22:23 +010090export { command, callback, check };
Samuel Shuert27bf3cd2023-03-03 15:51:25 -050091export const metadata = {
92 longDescription: "Stops members from being able to send messages without waiting a certain amount of time between messages.",
93 premiumOnly: true,
94}