Skip to content

Commit

Permalink
Update: Allow for more than 100 messages to be purged at one time
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathaniel Wood committed Oct 8, 2024
1 parent 8dc2484 commit a59278c
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 102 deletions.
108 changes: 54 additions & 54 deletions src/assets/emojis.json
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
{
"image":"<:image_emoji:788427949509836840>",
"currency":"<:currency_emoji:788428132683350058>",
"image":"<:image_emoji:1293231582840356946>",
"currency":"<:currency_emoji:1293232058151338075>",

"games":"<:games_emoji:788428825745817611> ",
"admin":"<:admin_emoji:788429031926005790> ",
"configs":"<:configs_emoji:788427972628447293> ",
"utils":"<:utils_emoji:788429328039280661> ",
"success": "<:success:788438144818217000> ",
"games":"<:games_emoji:1293232229526540362>",
"admin":"<:admin_emoji:1293232336225439856>",
"configs":"<:configs_emoji:1293232729831378956>",
"utils":"<:utils_emoji:1293232854003879979>",
"success": "<:success:1293235164662595756>",

"green":"<:greensquare:803527870609489931> ",
"red":"<:redsquare:803527843661217802>",
"green":"<:greensquare:1293233131016683593>",
"red":"<:redsquare:1293233250172538961>",

"dot": "<:purple_pogy_dot:788726274940076082> ",
"fail": "<:fail:790491137289879583> ",
"dot": "<:purple_mee8_dot:1293234356982251611>",
"fail": "<:fail:1293235307998740480>",

"misc": "<:speaker:790146754645196800> ",
"mod": "<:moderation_emoji:788428121375768586>",
"misc": "<:speaker:1293235452861616159>",
"mod": "<:moderation_emoji:1293235825340842096>",

"pogger1": "<:poggerz:790987235591323659> ",
"heartbreak":"<:heartbreak:790987215324184606> ",
"pogger1": "<:poggerz:1293235961123045457>",
"heartbreak":"<:heartbreak:1293236055079649331>",

"lock": "<:lock:790494601189261323> ",
"unlock": "<:unlock:790494567753187338> ",

"owner": "<:owner:790146744348442624> ",

"discord_employee":"<:discordemployee:790152842382934038> ",
"discord_partner": "<:partnered:790152935152680960>",
"bughunter_level_1": "<:bughunterl1:790152798623891466> ",
"bughunter_level_2": "<:bughunterl2:790152838763511808> ",
"hypesquad_events": "<:hypesquadevents:790152901569282048> ",
"house_brilliance": "<:brilliance:790152798288871454> ",
"house_bravery": "<:housebravery:790152899769925643> ",
"house_balance": "<:housebalance:790152901259165726> ",
"early_supporter": "<:earlysupporter:790152860742451221> ",
"verified_bot": "<:verifiedbot:790152985870991360> ",
"verified_developer": "<:verifieddev:790152986382303253> ",


"online": "<:online:790132184018059304> ",
"idle": "<:Idle:790132098806972426> ",
"offline": "<:offline:790132057523093515> ",
"dnd": "<:donotdisturb:790132081136893962> ",
"verify":"<:success:788438144818217000>",

"voice": "<:speaker:790146754645196800> ",

"pong": "<:online:790132184018059304>",

"altdetector":"<:alt:826845773656096838>",
"applications":"<:form:826846790208716831>",
"config":"<:configs_emoji:788427972628447293>",
"utility":"<:utils_emoji:788429328039280661>",
"economy":"<:currency_emoji:788428132683350058>",
"fun":"<:fun_emoji:788428109980368916> ",
"images":"<:image_emoji:788427949509836840>",
"information":"<:information_emoji:788428196528914472> ",
"moderation":"<:moderation_emoji:788428121375768586>",
"reactionrole":"<:reaction_roles:826845827191406694>",
"tickets":"<:ticket:826845944669536266>"
"lock": "<:lock:1293236154245709906>",
"unlock": "<:unlock:1293236281224073337>",

"owner": "<:owner:1293236377546391696>",

"discord_employee":"<:discordemployee:1293236507431272578>",
"discord_partner": "<:partnered:1293236593431285815>",
"bughunter_level_1": "<:bughunterl1:1293236694862135307>",
"bughunter_level_2": "<:bughunterl2:1293236864849018964>",
"hypesquad_events": "<:hypesquadevents:1293236985665687635>",
"house_brilliance": "<:brilliance:1293237074459365530>",
"house_bravery": "<:housebravery:1293237183469060187>",
"house_balance": "<:housebalance:1293237287408373813>",
"early_supporter": "<:earlysupporter:1293237683316854857>",
"verified_bot": "<:verifiedbot:1293237791219519531>",
"verified_developer": "<:verifieddev:1293237894890262588>",


"online": "<:online:1293237986359771257>",
"idle": "<:idle:1293238147441758359>",
"offline": "<:offline:1293238258230235269>",
"dnd": "<:donotdisturb:1293238425838682165>",
"verify":"<:success:1293235164662595756>",

"voice": "<:speaker:1293235452861616159>",

"pong": "<:online:1293237986359771257>",

"altdetector":"<:alt:1293238819151151195>",
"applications":"<:form:1293239246525825106>",
"config":"<:configs_emoji:1293232729831378956>",
"utility":"<:utils_emoji:1293232854003879979>",
"economy":"<:currency_emoji:1293232058151338075>",
"fun":"<:fun_emoji:1293239531629318274>",
"images":"<:image_emoji:1293231582840356946>",
"information":"<:information_emoji:1293239890934497292>",
"moderation":"<:moderation_emoji:1293235825340842096>",
"reactionrole":"<:reaction_roles:1293239986866360411>",
"tickets":"<:ticket_emoji:1293240103099170918>"

}
84 changes: 38 additions & 46 deletions src/commands/moderation/clear.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = class extends Command {

const amount = parseInt(args[0]);
const channel = message.channel;
if (isNaN(amount) === true || !amount || amount < 0 || amount > 100)
if (isNaN(amount) === true || !amount || amount < 0 || amount > 200)
return message.channel.sendCustom({
embeds: [
new MessageEmbed()
Expand All @@ -41,7 +41,7 @@ module.exports = class extends Command {
message.author.displayAvatarURL({ dynamic: true })
)
.setTitle(`${fail} Clear Error`)
.setDescription(`I can only purge between 1 - 100 messages.`)
.setDescription(`I can only purge between 1 - 200 messages.`)
.setTimestamp()
.setFooter({ text: `${process.env.AUTH_DOMAIN}` })
.setColor(message.guild.me.displayHexColor),
Expand Down Expand Up @@ -75,55 +75,47 @@ module.exports = class extends Command {
let messages;
messages = amount;

if (messages.size === 0) {
message.channel
.sendCustom(
new MessageEmbed()
.setDescription(
`
${fail} Unable to find any messages from ${member}.
let totalDeleted = 0;

while (totalDeleted < amount) {
const messagesToDelete = Math.min(100, amount - totalDeleted);
try {
const deletedMessages = await channel.bulkDelete(messagesToDelete, true);
totalDeleted += deletedMessages.size;
logger.info(`Deleted ${deletedMessages.size} ${deletedMessages.size === 1 ? "message" : "messages"}.`, { label: "Purge" });
} catch (error) {
logger.info(`Error deleting messages: ${error}`, { label: "ERROR" });
return message.channel.send({ content: "There was an error trying to delete messages in this channel." });
}
}

const embed = new MessageEmbed()

.setDescription(
`
)
.setColor(message.guild.me.displayHexColor)
)
.then((msg) => {
setTimeout(() => {
msg.delete();
}, 10000);
})
.catch(() => {});
} else {
channel.bulkDelete(messages, true).then((messages) => {
const embed = new MessageEmbed()

.setDescription(
`
${success} Successfully deleted **${messages.size}** message(s) ${
logging && logging.moderation.include_reason === "true"
? `\n\n**Reason:** ${reason}`
: ``
}
${success} Successfully deleted **${totalDeleted}** ${totalDeleted === 1 ? "message" : "messages"} ${logging && logging.moderation.include_reason === "true"
? `\n\n**Reason:** ${reason}`
: ``
}
`
)
)

.setColor(message.guild.me.displayHexColor);
.setColor(message.guild.me.displayHexColor);

message.channel
.sendCustom({ embeds: [embed] })
.then(async (s) => {
if (logging && logging.moderation.delete_reply === "true") {
setTimeout(() => {
s.delete().catch(() => {});
}, 5000);
}
})
.catch(() => {});
});
}
message.channel
.sendCustom({ embeds: [embed] })
.then(async (s) => {
if (logging && logging.moderation.delete_reply === "true") {
setTimeout(() => {
s.delete().catch(() => { });
}, 5000);
}
})
.catch(() => { });

if (logging) {
if (logging.moderation.delete_after_executed === "true") {
message.delete().catch(() => {});
message.delete().catch(() => { });
}

const role = message.guild.roles.cache.get(
Expand Down Expand Up @@ -160,10 +152,10 @@ module.exports = class extends Command {
.setFooter({ text: `Responsible ID: ${message.author.id}` })
.setColor(color);

channel.send({ embeds: [logEmbed] }).catch(() => {});
channel.send({ embeds: [logEmbed] }).catch(() => { });

logging.moderation.caseN = logcase + 1;
await logging.save().catch(() => {});
await logging.save().catch(() => { });
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/slashCommands/moderation/clear.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ module.exports = {
let totalDeleted = 0;

while (totalDeleted < amount) {
const messagesToDelete = Math.min(100, deleteCount - totalDeleted);
const messagesToDelete = Math.min(100, amount - totalDeleted);
try {
const deletedMessages = await channel.bulkDelete(messagesToDelete, true);
totalDeleted += deletedMessages.size;
logger.info(`Deleted ${deletedMessages.size} ${deletedMessages.size === 1 ? "message" : "messages"}.`, { label: "Purge" });
} catch (error) {
logger.info(`Error deleting messages: ${error}`, { label: "ERROR" });
return interaction.channel.send("There was an error trying to delete messages in this channel!");
return interaction.editReply({ content: "There was an error trying to delete messages in this channel.", ephemeral: true });
}
}

Expand Down

0 comments on commit a59278c

Please sign in to comment.