open source!
diff --git a/src/commands/mod/ban.ts b/src/commands/mod/ban.ts
index 8da4f1c..7861cdd 100644
--- a/src/commands/mod/ban.ts
+++ b/src/commands/mod/ban.ts
@@ -129,11 +129,11 @@
// Check if Nucleus has permission to ban
if (! interaction.guild.me.permissions.has("BAN_MEMBERS")) throw "I do not have the `ban_members` permission";
// Do not allow banning Nucleus
- if ((interaction.member as GuildMember).id == interaction.guild.me.id) throw "I cannot ban myself"
+ if (member.id == interaction.guild.me.id) throw "I cannot ban myself"
// Allow the owner to ban anyone
- if ((interaction.member as GuildMember).id == interaction.guild.ownerId) return true
+ if (member.id == interaction.guild.ownerId) return true
// Check if the user has ban_members permission
- if (! (interaction.member as GuildMember).permissions.has("BAN_MEMBERS")) throw "You do not have the `ban_members` permission";
+ if (! member.permissions.has("BAN_MEMBERS")) throw "You do not have the `ban_members` permission";
// Check if the user is below on the role list
if (! (memberPos > applyPos)) throw "You do not have a role higher than that member"
// Allow ban
diff --git a/src/commands/mod/kick.ts b/src/commands/mod/kick.ts
index b6ab653..9d434f8 100644
--- a/src/commands/mod/kick.ts
+++ b/src/commands/mod/kick.ts
@@ -126,11 +126,11 @@
// Check if Nucleus has permission to kick
if (! interaction.guild.me.permissions.has("KICK_MEMBERS")) throw "I do not have the `kick_members` permission";
// Do not allow kicking Nucleus
- if ((interaction.member as GuildMember).id == interaction.guild.me.id) throw "I cannot kick myself"
+ if (member.id == interaction.guild.me.id) throw "I cannot kick myself"
// Allow the owner to kick anyone
- if ((interaction.member as GuildMember).id == interaction.guild.ownerId) return true
+ if (member.id == interaction.guild.ownerId) return true
// Check if the user has kick_members permission
- if (! (interaction.member as GuildMember).permissions.has("KICK_MEMBERS")) throw "You do not have the `kick_members` permission";
+ if (! member.permissions.has("KICK_MEMBERS")) throw "You do not have the `kick_members` permission";
// Check if the user is below on the role list
if (! (memberPos > applyPos)) throw "You do not have a role higher than that member"
// Allow kick
diff --git a/src/commands/mod/mute.ts b/src/commands/mod/mute.ts
index 3d6d912..2942844 100644
--- a/src/commands/mod/mute.ts
+++ b/src/commands/mod/mute.ts
@@ -227,13 +227,13 @@
// Check if Nucleus has permission to mute
if (! interaction.guild.me.permissions.has("MODERATE_MEMBERS")) throw "I do not have the `moderate_members` permission";
// Do not allow the user to have admin or be the owner
- if ((interaction.options.getMember("user") as GuildMember).permissions.has("ADMINISTRATOR") || (interaction.options.getMember("user") as GuildMember).id == interaction.guild.ownerId) throw "You cannot mute an admin or the owner"
+ if (apply.permissions.has("ADMINISTRATOR") || apply.id == interaction.guild.ownerId) throw "You cannot mute an admin or the owner"
// Do not allow muting Nucleus
- if ((interaction.member as GuildMember).id == interaction.guild.me.id) throw "I cannot mute myself"
+ if (member.id == interaction.guild.me.id) throw "I cannot mute myself"
// Allow the owner to mute anyone
- if ((interaction.member as GuildMember).id == interaction.guild.ownerId) return true
+ if (member.id == interaction.guild.ownerId) return true
// Check if the user has moderate_members permission
- if (! (interaction.member as GuildMember).permissions.has("MODERATE_MEMBERS")) throw "You do not have the `moderate_members` permission";
+ if (! member.permissions.has("MODERATE_MEMBERS")) throw "You do not have the `moderate_members` permission";
// Check if the user is below on the role list
if (! (memberPos > applyPos)) throw "You do not have a role higher than that member"
// Allow mute
diff --git a/src/commands/mod/nick.ts b/src/commands/mod/nick.ts
index 72b2524..1e57e01 100644
--- a/src/commands/mod/nick.ts
+++ b/src/commands/mod/nick.ts
@@ -122,9 +122,9 @@
// Check if Nucleus has permission to change the nickname
if (! interaction.guild.me.permissions.has("MANAGE_NICKNAMES")) throw "I do not have the `manage_nicknames` permission";
// Allow the owner to change anyone's nickname
- if ((interaction.member as GuildMember).id == interaction.guild.ownerId) return true
+ if (member.id == interaction.guild.ownerId) return true
// Check if the user has manage_nicknames permission
- if (! (interaction.member as GuildMember).permissions.has("MANAGE_NICKNAMES")) throw "You do not have the `manage_nicknames` permission";
+ if (! member.permissions.has("MANAGE_NICKNAMES")) throw "You do not have the `manage_nicknames` permission";
// Allow changing your own nickname
if (member == apply) return true
// Check if the user is below on the role list
diff --git a/src/commands/mod/purge.ts b/src/commands/mod/purge.ts
index a1c8fe3..7a35e5b 100644
--- a/src/commands/mod/purge.ts
+++ b/src/commands/mod/purge.ts
@@ -308,10 +308,11 @@
}
const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
+ let member = (interaction.member as GuildMember)
// Allow the owner to purge
- if ((interaction.member as GuildMember).id == interaction.guild.ownerId) return true
+ if (member.id == interaction.guild.ownerId) return true
// Check if the user has manage_messages permission
- if (! (interaction.member as GuildMember).permissions.has("MANAGE_MESSAGES")) throw "You do not have the `manage_messages` permission";
+ if (! member.permissions.has("MANAGE_MESSAGES")) throw "You do not have the `manage_messages` permission";
// Check if nucleus has the manage_messages permission
if (! interaction.guild.me.permissions.has("MANAGE_MESSAGES")) throw "I do not have the `manage_messages` permission";
// Allow warn
diff --git a/src/commands/mod/slowmode.ts b/src/commands/mod/slowmode.ts
index 8f6f323..b91f065 100644
--- a/src/commands/mod/slowmode.ts
+++ b/src/commands/mod/slowmode.ts
@@ -1,18 +1,72 @@
-import { CommandInteraction } from "discord.js";
+import humanizeDuration from 'humanize-duration';
+import { CommandInteraction, GuildMember, TextChannel } from "discord.js";
import { SlashCommandSubcommandBuilder } from "@discordjs/builders";
import { WrappedCheck } from "jshaiku";
+import keyValueList from "../../utils/generateKeyValueList.js";
+import confirmationMessage from "../../utils/confirmationMessage.js";
+import generateEmojiEmbed from "../../utils/generateEmojiEmbed.js";
const command = (builder: SlashCommandSubcommandBuilder) =>
builder
.setName("slowmode")
.setDescription("Manages slowmode in a channel")
+ .addStringOption(option => option.setName("time").setDescription("The delay between messages").setRequired(false).addChoices([
+ ["Off", "0"],
+ ["5 seconds", "5"], ["10 seconds", "10"], ["15 seconds", "15"], ["30 seconds", "30"],
+ ["1 minute", "60"], ["2 minutes", "120"], ["5 minutes", "300"], ["10 minutes", "600"],
+ ["15 minutes", "900"], ["30 minutes", "1800"],
+ ["1 hour", "3600"], ["2 hours", "7200"], ["6 hours", "21600"]
+ ]))
-const callback = (interaction: CommandInteraction) => {
- interaction.reply("This command is not yet finished [mod/slowmode]");
+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)
+ .setEmoji("CHANNEL.SLOWMODE.RED")
+ .setTitle("Slowmode")
+ .setDescription(keyValueList({
+ "time": time ? humanizeDuration(time * 1000, { round: true }) : "No delay",
+ })
+ + `Are you sure you want to set the slowmode in this channel?`)
+ .setColor("Danger")
+// pluralize("day", interaction.options.getInteger("delete"))
+// const pluralize = (word: string, count: number) => { return count === 1 ? word : word + "s" }
+ .send()
+ if (confirmation.success) {
+ try {
+ (interaction.channel as TextChannel).setRateLimitPerUser(time)
+ } catch (e) {
+ await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setEmoji("CHANNEL.SLOWMODE.RED")
+ .setTitle(`Slowmode`)
+ .setDescription("An error occurred while setting the slowmode")
+ .setStatus("Danger")
+ ], components: []})
+ }
+ await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setEmoji(`CHANNEL.SLOWMODE.GREEN`)
+ .setTitle(`Slowmode`)
+ .setDescription("The channel slowmode was set successfully")
+ .setStatus("Success")
+ ], components: []})
+ } else {
+ await interaction.editReply({embeds: [new generateEmojiEmbed()
+ .setEmoji("CHANNEL.SLOWMODE.GREEN")
+ .setTitle(`Slowmode`)
+ .setDescription("No changes were made")
+ .setStatus("Success")
+ ], components: []})
+ }
}
const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
- return true;
+ let member = (interaction.member as GuildMember)
+ // Check if Nucleus can set the slowmode
+ if (! interaction.guild.me.permissions.has("MANAGE_CHANNELS")) throw "I do not have the `manage_channels` permission";
+ // Check if the user has manage_channel permission
+ if (! member.permissions.has("MANAGE_CHANNELS")) throw "You do not have the `manage_channels` permission";
+ // Allow slowmode
+ return true
}
export { command, callback, check };
\ No newline at end of file
diff --git a/src/commands/mod/softban.ts b/src/commands/mod/softban.ts
index 2b9643d..334f7f2 100644
--- a/src/commands/mod/softban.ts
+++ b/src/commands/mod/softban.ts
@@ -100,11 +100,11 @@
// Check if Nucleus has permission to ban
if (! interaction.guild.me.permissions.has("BAN_MEMBERS")) throw "I do not have the `ban_members` permission";
// Do not allow softbanning Nucleus
- if ((interaction.member as GuildMember).id == interaction.guild.me.id) throw "I cannot softban myself"
+ if (member.id == interaction.guild.me.id) throw "I cannot softban myself"
// Allow the owner to ban anyone
- if ((interaction.member as GuildMember).id == interaction.guild.ownerId) return true
+ if (member.id == interaction.guild.ownerId) return true
// Check if the user has ban_members permission
- if (! (interaction.member as GuildMember).permissions.has("BAN_MEMBERS")) throw "You do not have the `ban_members` permission";
+ if (! member.permissions.has("BAN_MEMBERS")) throw "You do not have the `ban_members` permission";
// Check if the user is below on the role list
if (! (memberPos > applyPos)) throw "You do not have a role higher than that member"
// Allow softban
diff --git a/src/commands/mod/unban.ts b/src/commands/mod/unban.ts
index f96a7bd..26815eb 100644
--- a/src/commands/mod/unban.ts
+++ b/src/commands/mod/unban.ts
@@ -88,13 +88,12 @@
const check = (interaction: CommandInteraction, defaultCheck: WrappedCheck) => {
let member = (interaction.member as GuildMember)
- let me = (interaction.guild.me as GuildMember)
// Check if Nucleus can unban members
if (! interaction.guild.me.permissions.has("BAN_MEMBERS")) throw "I do not have the `ban_members` permission";
// Allow the owner to unban anyone
- if ((interaction.member as GuildMember).id == interaction.guild.ownerId) return true
+ if (member.id == interaction.guild.ownerId) return true
// Check if the user has ban_members permission
- if (! (interaction.member as GuildMember).permissions.has("BAN_MEMBERS")) throw "You do not have the `ban_members` permission";
+ if (! member.permissions.has("BAN_MEMBERS")) throw "You do not have the `ban_members` permission";
// Allow unban
return true
}
diff --git a/src/commands/mod/unmute.ts b/src/commands/mod/unmute.ts
index 65e5e97..2d630ea 100644
--- a/src/commands/mod/unmute.ts
+++ b/src/commands/mod/unmute.ts
@@ -89,11 +89,11 @@
// Check if Nucleus has permission to unmute
if (! interaction.guild.me.permissions.has("MODERATE_MEMBERS")) throw "I do not have the `moderate_members` permission";
// Do not allow the user to have admin or be the owner
- if ((interaction.options.getMember("user") as GuildMember).permissions.has("ADMINISTRATOR") || (interaction.options.getMember("user") as GuildMember).id == interaction.guild.ownerId) throw "You cannot unmute an admin or the owner"
+ if (apply.permissions.has("ADMINISTRATOR") || (interaction.options.getMember("user") as GuildMember).id == interaction.guild.ownerId) throw "You cannot unmute an admin or the owner"
// Allow the owner to unmute anyone
- if ((interaction.member as GuildMember).id == interaction.guild.ownerId) return true
+ if (member.id == interaction.guild.ownerId) return true
// Check if the user has moderate_members permission
- if (! (interaction.member as GuildMember).permissions.has("MODERATE_MEMBERS")) throw "You do not have the `moderate_members` permission";
+ if (! member.permissions.has("MODERATE_MEMBERS")) throw "You do not have the `moderate_members` permission";
// Check if the user is below on the role list
if (! (memberPos > applyPos)) throw "You do not have a role higher than that member"
// Allow unmute
diff --git a/src/commands/mod/unnamed.ts b/src/commands/mod/unnamed.ts
index 2d65a87..c2d5618 100644
--- a/src/commands/mod/unnamed.ts
+++ b/src/commands/mod/unnamed.ts
@@ -217,13 +217,13 @@
// Check if Nucleus has permission to UNNAMED
if (! interaction.guild.me.permissions.has("MANAGE_ROLES")) throw "I do not have the `manage_roles` permission";
// Do not allow the user to have admin or be the owner
- if ((interaction.options.getMember("user") as GuildMember).permissions.has("ADMINISTRATOR") || (interaction.options.getMember("user") as GuildMember).id == interaction.guild.ownerId) throw "You cannot mute an admin or the owner"
+ if (apply.permissions.has("ADMINISTRATOR") || (interaction.options.getMember("user") as GuildMember).id == interaction.guild.ownerId) throw "You cannot mute an admin or the owner"
// Do not allow muting Nucleus
- if ((interaction.member as GuildMember).id == interaction.guild.me.id) throw "I cannot UNNAMED myself"
+ if (member.id == interaction.guild.me.id) throw "I cannot UNNAMED myself"
// Allow the owner to UNNAMED anyone
- if ((interaction.member as GuildMember).id == interaction.guild.ownerId) return true
+ if (member.id == interaction.guild.ownerId) return true
// Check if the user has moderate_members permission
- if (! (interaction.member as GuildMember).permissions.has("MODERATE_MEMBERS")) throw "You do not have the `moderate_members` permission";
+ if (! member.permissions.has("MODERATE_MEMBERS")) throw "You do not have the `moderate_members` permission";
// Check if the user is below on the role list
if (! (memberPos > applyPos)) throw "You do not have a role higher than that member"
// Allow UNNAMED
diff --git a/src/commands/mod/warn.ts b/src/commands/mod/warn.ts
index d89a778..3f63cce 100644
--- a/src/commands/mod/warn.ts
+++ b/src/commands/mod/warn.ts
@@ -166,11 +166,11 @@
let mePos = me.roles ? me.roles.highest.position : 0
let applyPos = apply.roles ? apply.roles.highest.position : 0
// Do not allow warning bots
- if ((interaction.member as GuildMember).user.bot) throw "I cannot warn bots"
+ if (member.user.bot) throw "I cannot warn bots"
// Allow the owner to warn anyone
- if ((interaction.member as GuildMember).id == interaction.guild.ownerId) return true
+ if (member.id == interaction.guild.ownerId) return true
// Check if the user has moderate_members permission
- if (! (interaction.member as GuildMember).permissions.has("MODERATE_MEMBERS")) throw "You do not have the `moderate_members` permission";
+ if (! member.permissions.has("MODERATE_MEMBERS")) throw "You do not have the `moderate_members` permission";
// Check if the user is below on the role list
if (! (memberPos > applyPos)) throw "You do not have a role higher than that member"
// Allow warn