|
|
|
@ -1,53 +1,57 @@
|
|
|
|
import { CommandInteraction } from "discord.js";
|
|
|
|
import humanizeDuration from 'humanize-duration';
|
|
|
|
|
|
|
|
import { CommandInteraction, GuildMember, TextChannel } from "discord.js";
|
|
|
|
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
|
|
|
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
|
|
|
|
import { WrappedCheck } from "jshaiku";
|
|
|
|
import { WrappedCheck } from "jshaiku";
|
|
|
|
import humanizeDuration from 'humanize-duration';
|
|
|
|
import keyValueList from "../../utils/generateKeyValueList.js";
|
|
|
|
|
|
|
|
import confirmationMessage from "../../utils/confirmationMessage.js";
|
|
|
|
|
|
|
|
import generateEmojiEmbed from "../../utils/generateEmojiEmbed.js";
|
|
|
|
|
|
|
|
|
|
|
|
const command = (builder: SlashCommandSubcommandBuilder) =>
|
|
|
|
const command = (builder: SlashCommandSubcommandBuilder) =>
|
|
|
|
builder
|
|
|
|
builder
|
|
|
|
.setName("slowmode")
|
|
|
|
.setName("slowmode")
|
|
|
|
.setDescription("Manages slowmode in a channel")
|
|
|
|
.setDescription("Manages slowmode in a channel")
|
|
|
|
.addIntegerOption(option => option.setName("seconds").setDescription("The seconds between messages").setRequired(false))
|
|
|
|
.addStringOption(option => option.setName("time").setDescription("The delay between messages").setRequired(false).addChoices([
|
|
|
|
.addIntegerOption(option => option.setName("minutes").setDescription("The minutes between messages").setRequired(false))
|
|
|
|
["Off", "0"],
|
|
|
|
.addIntegerOption(option => option.setName("hours").setDescription("The hours between messages").setRequired(false))
|
|
|
|
["5 seconds", "5"], ["10 seconds", "10"], ["15 seconds", "15"], ["30 seconds", "30"],
|
|
|
|
|
|
|
|
["1 minute", "60"], ["2 minutes", "120"], ["5 minutes", "300"], ["10 minutes", "600"],
|
|
|
|
const callback = (interaction: CommandInteraction) => {
|
|
|
|
["15 minutes", "900"], ["30 minutes", "1800"],
|
|
|
|
let seconds = interaction.option.getInteger("seconds")
|
|
|
|
["1 hour", "3600"], ["2 hours", "7200"], ["6 hours", "21600"]
|
|
|
|
let minutes = interaction.option.getInteger("minutes")
|
|
|
|
]))
|
|
|
|
let hours = interaction.option.getInteger("hours")
|
|
|
|
|
|
|
|
let totalTime = seconds + (minutes * 60) + (hours * 60 * 60)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const callback = async (interaction: CommandInteraction) => {
|
|
|
|
|
|
|
|
let time = parseInt(interaction.options.getString("time") ?? "0");
|
|
|
|
|
|
|
|
if (time === 0 && (interaction.channel as TextChannel).rateLimitPerUser === 0) { time = 10 }
|
|
|
|
let confirmation = await new confirmationMessage(interaction)
|
|
|
|
let confirmation = await new confirmationMessage(interaction)
|
|
|
|
.setEmoji("PUNISH.SLOWMODE.RED")
|
|
|
|
.setEmoji("CHANNEL.SLOWMODE.RED")
|
|
|
|
.setTitle("Slowmode")
|
|
|
|
.setTitle("Slowmode")
|
|
|
|
.setDescription(keyValueList({
|
|
|
|
.setDescription(keyValueList({
|
|
|
|
"delay": `${totalTime ? humanizeDuration(totalTime * 1000) : "*No delay*"}`
|
|
|
|
"time": time ? humanizeDuration(time * 1000, { round: true }) : "No delay",
|
|
|
|
})
|
|
|
|
})
|
|
|
|
+ `Are you sure you want to enable slowmode in this channel?`)
|
|
|
|
+ `Are you sure you want to set the slowmode in this channel?`)
|
|
|
|
.setColor("Danger")
|
|
|
|
.setColor("Danger")
|
|
|
|
// pluralize("day", interaction.options.getInteger("delete"))
|
|
|
|
// pluralize("day", interaction.options.getInteger("delete"))
|
|
|
|
// const pluralize = (word: string, count: number) => { return count === 1 ? word : word + "s" }
|
|
|
|
// const pluralize = (word: string, count: number) => { return count === 1 ? word : word + "s" }
|
|
|
|
.send()
|
|
|
|
.send()
|
|
|
|
if (confirmation.success) {
|
|
|
|
if (confirmation.success) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
await interaction.setRateLimitPerUser(totalTime, "Nucleus slowmode")
|
|
|
|
(interaction.channel as TextChannel).setRateLimitPerUser(time)
|
|
|
|
} catch {
|
|
|
|
} catch (e) {
|
|
|
|
return await interaction.editReply({embeds: [new generateEmojiEmbed()
|
|
|
|
await interaction.editReply({embeds: [new generateEmojiEmbed()
|
|
|
|
.setEmoji("PUNISH.SLOWMODE.RED")
|
|
|
|
.setEmoji("CHANNEL.SLOWMODE.RED")
|
|
|
|
.setTitle(`Slowmode`)
|
|
|
|
.setTitle(`Slowmode`)
|
|
|
|
.setDescription("Something went wrong and the slowmode could not be set.")
|
|
|
|
.setDescription("An error occurred while setting the slowmode")
|
|
|
|
.setStatus("Danger")
|
|
|
|
.setStatus("Danger")
|
|
|
|
], components: []})
|
|
|
|
], components: []})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await interaction.editReply({embeds: [new generateEmojiEmbed()
|
|
|
|
await interaction.editReply({embeds: [new generateEmojiEmbed()
|
|
|
|
.setEmoji("PUNISH.NICKNAME.GREEN")
|
|
|
|
.setEmoji(`CHANNEL.SLOWMODE.GREEN`)
|
|
|
|
.setTitle(`Slowmode`)
|
|
|
|
.setTitle(`Slowmode`)
|
|
|
|
.setDescription("The channel slowmode was set successfully")
|
|
|
|
.setDescription("The channel slowmode was set successfully")
|
|
|
|
.setStatus("Success")
|
|
|
|
.setStatus("Success")
|
|
|
|
], components: []})
|
|
|
|
], components: []})
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
await interaction.editReply({embeds: [new generateEmojiEmbed()
|
|
|
|
await interaction.editReply({embeds: [new generateEmojiEmbed()
|
|
|
|
.setEmoji("PUNISH.SLOWMODE.GREEN")
|
|
|
|
.setEmoji("CHANNEL.SLOWMODE.GREEN")
|
|
|
|
.setTitle(`Slowmode`)
|
|
|
|
.setTitle(`Slowmode`)
|
|
|
|
.setDescription("No changes were made")
|
|
|
|
.setDescription("No changes were made")
|
|
|
|
.setStatus("Success")
|
|
|
|
.setStatus("Success")
|
|
|
|
@ -57,12 +61,9 @@ const callback = (interaction: CommandInteraction) => {
|
|
|
|
|
|
|
|
|
|
|
|
const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
|
|
|
|
const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
|
|
|
|
let member = (interaction.member as GuildMember)
|
|
|
|
let member = (interaction.member as GuildMember)
|
|
|
|
let me = (interaction.guild.me as GuildMember)
|
|
|
|
// Check if Nucleus can set the slowmode
|
|
|
|
// Check if Nucleus can edit the channel
|
|
|
|
if (! interaction.guild.me.permissions.has("MANAGE_CHANNELS")) throw "I do not have the `manage_channels` permission";
|
|
|
|
if (! me.permission.has("MANAGE_CHANNELS")) throw "I do not have permission to edit this channel"
|
|
|
|
// Check if the user has manage_channel permission
|
|
|
|
// Allow the owner to set any channel
|
|
|
|
|
|
|
|
if (member.id == interaction.guild.ownerId) return true
|
|
|
|
|
|
|
|
// Check if the user has manage_channels permission
|
|
|
|
|
|
|
|
if (! member.permissions.has("MANAGE_CHANNELS")) throw "You do not have the `manage_channels` permission";
|
|
|
|
if (! member.permissions.has("MANAGE_CHANNELS")) throw "You do not have the `manage_channels` permission";
|
|
|
|
// Allow slowmode
|
|
|
|
// Allow slowmode
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
|