Skip to content

Commit

Permalink
Merge pull request #17 from woozystudio/custom-duration
Browse files Browse the repository at this point in the history
chore: customized duration in moderation commands
  • Loading branch information
woozystudio authored Jun 17, 2024
2 parents dec333d + b4c0566 commit 13094b6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 94 deletions.
29 changes: 5 additions & 24 deletions commands/moderation/TempBanCommand.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { ApplicationCommandOptionType, ChatInputCommandInteraction, EmbedBuilder, GuildMember, PermissionFlagsBits, Role, User, bold, codeBlock, heading, inlineCode, quote, time } from "discord.js";
import { ApplicationCommandOptionType, ChatInputCommandInteraction, DefaultUserAgent, EmbedBuilder, GuildMember, PermissionFlagsBits, Role, User, bold, codeBlock, heading, inlineCode, quote, time } from "discord.js";
import Command from "../../class/Command";
import Eclipse from "../../class/Eclipse";
import Category from "../../enums/Category";
import ErrorEmbed from "../../embeds/ErrorEmbed";
import SuccessEmbed from "../../embeds/SuccessEmbed";
import ms from "@naval-base/ms";

export default class TempBan extends Command {
constructor(client: Eclipse) {
Expand All @@ -21,29 +22,9 @@ export default class TempBan extends Command {
},
{
name: "duration",
description: "Select the duration of the ban.",
description: "Write the duration with the format: 1s, 1m, 1h, 1d, 1w and 1y",
required: true,
type: ApplicationCommandOptionType.String,
choices: [
{ name: '60 Seconds', value: '60' },
{ name: '2 Minutes', value: '120' },
{ name: '5 Minutes', value: '300' },
{ name: '10 Minutes', value: '600' },
{ name: '15 Minutes', value: '900' },
{ name: '20 Minutes', value: '1200' },
{ name: '30 Minutes', value: '1800' },
{ name: '45 Minutes', value: '2700' },
{ name: '1 Hour', value: '3600' },
{ name: '2 Hours', value: '7200' },
{ name: '3 Hours', value: '10800' },
{ name: '5 Hours', value: '18000' },
{ name: '10 Hours', value: '36000' },
{ name: '1 Day', value: '86400' },
{ name: '2 Day', value: '172800' },
{ name: '3 Day', value: '259200' },
{ name: '5 Days', value: '432000' },
{ name: 'One Week', value: '604800' },
]
type: ApplicationCommandOptionType.String
},
{
name: "reason",
Expand Down Expand Up @@ -74,7 +55,7 @@ export default class TempBan extends Command {
if (targetHighestRole.comparePositionTo(botHighestRole) >= 0) return await interaction.reply({ embeds: [new ErrorEmbed("You cannot select this user as they has a role superior or equal to mine.")], ephemeral: true });
if (hasHigherPermissions) return await interaction.reply({ embeds: [new ErrorEmbed("You cannot select this user as they have higher or equal permissions to mine.")], ephemeral: true });

const durationMs = duration * 1000;
const durationMs = ms(duration);
const banExpiresAt = Math.floor((Date.now() + durationMs) / 1000);

const UserDirectMessagesEmbed = new EmbedBuilder()
Expand Down
27 changes: 4 additions & 23 deletions commands/moderation/TempMuteCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Category from "../../enums/Category";
import ErrorEmbed from "../../embeds/ErrorEmbed";
import SuccessEmbed from "../../embeds/SuccessEmbed";
import MuteConfig from "../../database/MuteConfig";
import ms from "@naval-base/ms";

export default class TempMute extends Command {
constructor(client: Eclipse) {
Expand All @@ -22,29 +23,9 @@ export default class TempMute extends Command {
},
{
name: "duration",
description: "Select the duration of the mute.",
description: "Write the duration with the format: 1s, 1m, 1h, 1d, 1w and 1y",
required: true,
type: ApplicationCommandOptionType.String,
choices: [
{ name: '60 Seconds', value: '60' },
{ name: '2 Minutes', value: '120' },
{ name: '5 Minutes', value: '300' },
{ name: '10 Minutes', value: '600' },
{ name: '15 Minutes', value: '900' },
{ name: '20 Minutes', value: '1200' },
{ name: '30 Minutes', value: '1800' },
{ name: '45 Minutes', value: '2700' },
{ name: '1 Hour', value: '3600' },
{ name: '2 Hours', value: '7200' },
{ name: '3 Hours', value: '10800' },
{ name: '5 Hours', value: '18000' },
{ name: '10 Hours', value: '36000' },
{ name: '1 Day', value: '86400' },
{ name: '2 Day', value: '172800' },
{ name: '3 Day', value: '259200' },
{ name: '5 Days', value: '432000' },
{ name: 'One Week', value: '604800' },
]
type: ApplicationCommandOptionType.String
}
],
development: false
Expand All @@ -68,7 +49,7 @@ export default class TempMute extends Command {
if (hasHigherPermissions) return await interaction.reply({ embeds: [new ErrorEmbed("You cannot select this user as they have higher or equal permissions to mine.")], ephemeral: true });
if (member.roles.cache.has(`${data.RoleID}`)) return await interaction.reply({ embeds: [new ErrorEmbed(`The user ${target} is already muted within the server.`)], ephemeral: true });

const durationMs = duration * 1000;
const durationMs = ms(duration);
const muteExpiresAt = Math.floor((Date.now() + durationMs) / 1000);

try {
Expand Down
27 changes: 4 additions & 23 deletions commands/moderation/TempRoleCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Eclipse from "../../class/Eclipse";
import Category from "../../enums/Category";
import ErrorEmbed from "../../embeds/ErrorEmbed";
import SuccessEmbed from "../../embeds/SuccessEmbed";
import ms from "@naval-base/ms";

export default class TempRole extends Command {
constructor(client: Eclipse) {
Expand All @@ -27,29 +28,9 @@ export default class TempRole extends Command {
},
{
name: "duration",
description: "Select the duration that the user will have the role.",
description: "Write the duration with the format: 1s, 1m, 1h, 1d, 1w and 1y",
required: true,
type: ApplicationCommandOptionType.String,
choices: [
{ name: '60 Seconds', value: '60' },
{ name: '2 Minutes', value: '120' },
{ name: '5 Minutes', value: '300' },
{ name: '10 Minutes', value: '600' },
{ name: '15 Minutes', value: '900' },
{ name: '20 Minutes', value: '1200' },
{ name: '30 Minutes', value: '1800' },
{ name: '45 Minutes', value: '2700' },
{ name: '1 Hour', value: '3600' },
{ name: '2 Hours', value: '7200' },
{ name: '3 Hours', value: '10800' },
{ name: '5 Hours', value: '18000' },
{ name: '10 Hours', value: '36000' },
{ name: '1 Day', value: '86400' },
{ name: '2 Day', value: '172800' },
{ name: '3 Day', value: '259200' },
{ name: '5 Days', value: '432000' },
{ name: 'One Week', value: '604800' },
]
type: ApplicationCommandOptionType.String
}
],
development: false
Expand All @@ -75,7 +56,7 @@ export default class TempRole extends Command {
if (hasHigherPermissions) return await interaction.reply({ embeds: [new ErrorEmbed("You cannot select this user as they have higher or equal permissions to mine.")], ephemeral: true });
if (member.roles.cache.has(role.id)) return await interaction.reply({ embeds: [new ErrorEmbed(`The user ${target} already has the role ${role}.`)], ephemeral: true });

const durationMs = duration * 1000;
const durationMs = ms(duration);
const roleExpiresAt = Math.floor((Date.now() + durationMs) / 1000);

await member.roles.add(role.id);
Expand Down
29 changes: 5 additions & 24 deletions commands/moderation/TimeoutCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Eclipse from "../../class/Eclipse";
import Category from "../../enums/Category";
import ErrorEmbed from "../../embeds/ErrorEmbed";
import SuccessEmbed from "../../embeds/SuccessEmbed";
import ms from "@naval-base/ms";

export default class Timeout extends Command {
constructor(client: Eclipse) {
Expand All @@ -21,29 +22,9 @@ export default class Timeout extends Command {
},
{
name: "duration",
description: "Select the duration of the timeout.",
description: "Write the duration with the format: 1s, 1m, 1h, 1d, 1w and 1y",
required: true,
type: ApplicationCommandOptionType.String,
choices: [
{ name: '60 Seconds', value: '60' },
{ name: '2 Minutes', value: '120' },
{ name: '5 Minutes', value: '300' },
{ name: '10 Minutes', value: '600' },
{ name: '15 Minutes', value: '900' },
{ name: '20 Minutes', value: '1200' },
{ name: '30 Minutes', value: '1800' },
{ name: '45 Minutes', value: '2700' },
{ name: '1 Hour', value: '3600' },
{ name: '2 Hours', value: '7200' },
{ name: '3 Hours', value: '10800' },
{ name: '5 Hours', value: '18000' },
{ name: '10 Hours', value: '36000' },
{ name: '1 Day', value: '86400' },
{ name: '2 Day', value: '172800' },
{ name: '3 Day', value: '259200' },
{ name: '5 Days', value: '432000' },
{ name: 'One Week', value: '604800' },
]
type: ApplicationCommandOptionType.String
},
{
name: "reason",
Expand Down Expand Up @@ -76,7 +57,7 @@ export default class Timeout extends Command {
if (targetHighestRole.comparePositionTo(botHighestRole) >= 0) return await interaction.reply({ embeds: [new ErrorEmbed("You cannot select this user as they has a role superior or equal to mine.")], ephemeral: true });
if (hasHigherPermissions) return await interaction.reply({ embeds: [new ErrorEmbed("You cannot select this user as they have higher or equal permissions to mine.")], ephemeral: true });

const durationMs = duration * 1000;
const durationMs = ms(duration);
const timeoutExpiresAt = Math.floor((Date.now() + durationMs) / 1000);

member.timeout(durationMs, reason);
Expand All @@ -97,6 +78,6 @@ export default class Timeout extends Command {
`)

await member.send({ embeds: [UserDirectMessagesEmbed] }).catch(err => { return; });
await interaction.reply({ embeds: [new SuccessEmbed(`The user ${target} has been timeout successfully.\nThe timeout will be cancelled ${time(timeoutExpiresAt, "R")}\n${heading('Reason', 3)} \n${codeBlock(`${reason}`)}`)], ephemeral: true })
await interaction.reply({ embeds: [new SuccessEmbed(`The user ${target} has been timeout successfully.\nThe timeout will be cancelled ${time(timeoutExpiresAt, "R")}\n${heading('Reason', 3)} \n${codeBlock(`${reason}`)}`)], ephemeral: false })
}
}

0 comments on commit 13094b6

Please sign in to comment.