Skip to content

Commit

Permalink
Update: Some small little changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathaniel Wood committed Oct 8, 2024
1 parent a69778d commit 2790815
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 40 deletions.
29 changes: 6 additions & 23 deletions src/commands/moderation/clear.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
const Command = require("../../structures/Command");
const { MessageEmbed } = require("discord.js");
const Logging = require("../../database/schemas/logging.js");
const logger = require("../../utils/logger.js");

module.exports = class extends Command {
constructor(...args) {
super(...args, {
name: "clear",
aliases: ["cls", "purge"],
description: " Delete the specified amount of messages",
description: "Delete the specified amount of messages",
category: "Moderation",
usage: "purge <message-count> [reason]",
examples: [
"purge 20",
"purge #general 10",
"purge @peter 50",
"purge #general @peter 5",
"cls 50",
"clear 125"
],
guildOnly: true,
botPermission: ["MANAGE_MESSAGES"],
Expand Down Expand Up @@ -57,8 +57,6 @@ module.exports = class extends Command {
reason = reason.slice(0, 1021) + "...";
}

await message.delete();

let messages;
messages = amount;

Expand Down Expand Up @@ -149,26 +147,11 @@ module.exports = class extends Command {
}
}
}
} catch {
} catch (error) {
logger.info(`An error occurred: ${error}`, { label: "ERROR" });
return message.channel.sendCustom(
`${message.client.emoji.fail} | Could not purge messages`
);
}
}
};

function getMemberFromMention(message, mention) {
if (!mention) return;
const matches = mention.match(/^<@!?(\d+)>$/);
if (!matches) return;
const id = matches[1];
return message.guild.members.cache.get(id);
}

function getChannelFromMention(message, mention) {
if (!mention) return;
const matches = mention.match(/^<#(\d+)>$/);
if (!matches) return;
const id = matches[1];
return message.guild.channels.cache.get(id);
}
8 changes: 4 additions & 4 deletions src/data/emoji.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
x: "<:wrong:822379358453891123>",
fail: "<:wrong:822379358453891123> ",
check: "<:success:1159255004817932398> ",
success: "<:success:1159255004817932398> ",
x: "<:fail:1293235307998740480>",
fail: "<:fail:1293235307998740480>",
check: "<:success:1293235164662595756>",
success: "<:success:1293235164662595756>",
cash: "$",
};
4 changes: 2 additions & 2 deletions src/events/message/messageCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ module.exports = class extends Event {
`${this.client.user.tag}`,
message.client.user.displayAvatarURL({ dynamic: true }),
)
.setTitle(`<:wrong:822376943763980348> Missing Bot Permissions`)
.setTitle(`<:fail:1293235307998740480> Missing Bot Permissions`)
.setDescription(
`Command Name: **${
command.name
Expand All @@ -245,7 +245,7 @@ module.exports = class extends Event {
`${message.author.tag}`,
message.author.displayAvatarURL({ dynamic: true }),
)
.setTitle(`<:wrong:822376943763980348> Missing User Permissions`)
.setTitle(`<:fail:1293235307998740480> Missing User Permissions`)
.setDescription(
`Command Name: **${
command.name
Expand Down
19 changes: 8 additions & 11 deletions src/slashCommands/moderation/clear.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ const { SlashCommandBuilder } = require("@discordjs/builders");
const { MessageEmbed } = require("discord.js");
const Logging = require("../../database/schemas/logging.js");
const logger = require("../../utils/logger.js");
let messageDisplay = "messages";

module.exports = {
data: new SlashCommandBuilder()
.setName("clear")
.setDescription("Purges a channels messages")
.addIntegerOption((option) =>
.addStringOption((option) =>
option
.setName("amount")
.setDescription("Amount of messages to clear")
Expand All @@ -26,17 +25,17 @@ module.exports = {
const fail = client.emoji.fail;
const success = client.emoji.success;

const amount = interaction.options.getInteger("amount");
const amount = parseInt(interaction.options.getString("amount"));
const channel = interaction.channel;
const reason = interaction.options.getString("reason");
if (!reason) {
reason = "None";
reason = "No reason provided.";
}
if (reason.length > 1024) {
reason = reason.slice(0, 1021) + "...";
}

if (amount < 0 || amount > 200) {
if (isNaN(amount) || amount < 0 || amount > 200) {
let invalidamount = new MessageEmbed()
.setAuthor({
name: `${interaction.user.tag}`,
Expand Down Expand Up @@ -86,17 +85,15 @@ module.exports = {
ephemeral: true,
});
} else {
channel.bulkDelete(messages, true).then((messages) => {
const embed = new MessageEmbed()

.setDescription(
`${success} | ***Successfully deleted ${totalDeleted} ${totalDeleted === 1 ? "message" : "messages"}* || ${reason}**`,
`${success} | ***Successfully deleted ${totalDeleted} ${totalDeleted === 1 ? "message" : "messages"}.* || ${reason}**`,
)

.setColor(interaction.client.color.green);

interaction.editReply({ embeds: [embed], ephemeral: true });
});
}

if (logging) {
Expand Down Expand Up @@ -127,11 +124,11 @@ module.exports = {
const logEmbed = new MessageEmbed()
.setAuthor(
`Action: \`Purge\` | Case #${logcase}`,
message.author.displayAvatarURL({ format: "png" })
interaction.member.displayAvatarURL({ format: "png" })
)
.addField("Moderator", `${interaction.user}`, true)
.addField("Moderator", `${interaction.member}`, true)
.setTimestamp()
.setFooter({ text: `Responsible ID: ${interaction.user.id}` })
.setFooter({ text: `Responsible ID: ${interaction.member.id}` })
.setColor(color);

loggingChannel.send({ embeds: [logEmbed] }).catch(() => {});
Expand Down

0 comments on commit 2790815

Please sign in to comment.