Skip to content

Commit

Permalink
a
Browse files Browse the repository at this point in the history
  • Loading branch information
eYuM-coder committed Dec 5, 2024
2 parents b034bed + 9d2efb8 commit fc3758c
Show file tree
Hide file tree
Showing 20 changed files with 528 additions and 228 deletions.
29 changes: 29 additions & 0 deletions .codesandbox/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
// These tasks will run in order when initializing your CodeSandbox project.
"setupTasks": [
{
"command": "npm install",
"name": "Install Dependencies"
}
],

// These tasks can be run from CodeSandbox. Running one will open a log in the app.
"tasks": {
"node": {
"name": "node",
"command": "npm run node"
},
"dev": {
"name": "dev",
"command": "npm run dev",
"runAtStart": true
},
"start": {
"name": "start",
"command": "npm run start",
"preview": {
"port": 4000
}
}
}
}
28 changes: 28 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"parse-ms": "^2.1.0",
"passport": "^0.4.1",
"passport-oauth2": "^1.6.1",
"pretty-ms": "^9.2.0",
"prodia.js": "^2.1.3",
"random": "^2.2.0",
"random-email": "^1.0.3",
Expand Down
27 changes: 8 additions & 19 deletions src/commands/information/uptime.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ const Command = require("../../structures/Command");
const Guild = require("../../database/schemas/Guild");
const { MessageEmbed } = require("discord.js");
const config = require("../../../config.json");
async function usePrettyMs(ms) {
const { default: prettyMilliseconds } = await import("pretty-ms");
const time = prettyMilliseconds(ms);
return time;
}

module.exports = class extends Command {
constructor(...args) {
Expand All @@ -23,27 +28,11 @@ module.exports = class extends Command {
if (uptime instanceof Array) {
uptime = uptime.reduce((max, cur) => Math.max(max, cur), -Infinity);
}
let seconds = uptime / 1000;
let days = parseInt(seconds / 86400);
seconds = seconds % 86400;
let hours = parseInt(seconds / 3600);
seconds = seconds % 3600;
let minutes = parseInt(seconds / 60);
seconds = parseInt(seconds % 60);
uptime = `${seconds}s`;
if (days) {
uptime = `${days} ${days === 1 ? "day" : "days"}, ${hours} ${hours === 1 ? "hour" : "hours"}, ${minutes} ${minutes === 1 ? "minutes" : "minutes"} and ${seconds} ${seconds === 1 ? "second" : "seconds"}`;
} else if (hours) {
uptime = `${hours} ${hours === 1 ? "hour" : "hours"}, ${minutes} ${minutes === 1 ? "minutes" : "minutes"} and ${seconds} ${seconds === 1 ? "second" : "seconds"}`;
} else if (minutes) {
uptime = `${minutes} ${minutes === 1 ? "minute" : "minutes"} and ${seconds} ${seconds === 1 ? "second" : "seconds"}`;
} else if (seconds) {
uptime = `${seconds} ${seconds === 1 ? "second" : "seconds"}`;
}
const formattedTime = await usePrettyMs(uptime);
// const date = moment().subtract(days, 'ms').format('dddd, MMMM Do YYYY');
const embed = new MessageEmbed()
.setDescription(`${config.botName} ${language.uptime1} \`${uptime}\`.`)
.setFooter({ text: `${process.env.AUTH_DOMAIN}/` })
.setDescription(`${config.botName} ${language.uptime1} \`${formattedTime}\`.`)
.setFooter({ text: `${process.env.AUTH_DOMAIN}` })
.setColor(message.guild.me.displayHexColor);
message.channel.sendCustom({ embeds: [embed] });
}
Expand Down
44 changes: 25 additions & 19 deletions src/commands/moderation/clear.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ module.exports = class extends Command {
description: "Delete the specified amount of messages (limit: 1000)",
category: "Moderation",
usage: "purge <message-count> [reason]",
examples: [
"purge 20",
"cls 50",
"clear 125"
],
examples: ["purge 20", "cls 50", "clear 125"],
guildOnly: true,
botPermission: ["MANAGE_MESSAGES"],
userPermission: ["MANAGE_MESSAGES"],
Expand Down Expand Up @@ -61,11 +57,16 @@ module.exports = class extends Command {
const TWO_WEEKS = 14 * 24 * 60 * 60 * 1000; // 14 days in milliseconds
const now = Date.now(); // Current timestamp

const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

while (totalDeleted < amount) {
const messagesToFetch = Math.min(100, amount - totalDeleted);
try {
// Fetch messages
const fetchedMessages = await channel.messages.fetch({ limit: messagesToFetch, before: message.id });
const fetchedMessages = await channel.messages.fetch({
limit: messagesToFetch,
before: message.id,
});

// Filter out messages older than 14 days
const validMessages = fetchedMessages.filter(
Expand All @@ -80,7 +81,9 @@ module.exports = class extends Command {
totalDeleted += deletedMessages.size;

logger.info(
`Deleted ${deletedMessages.size} ${deletedMessages.size === 1 ? "message" : "messages"}.`,
`Deleted ${deletedMessages.size} ${
deletedMessages.size === 1 ? "message" : "messages"
}.`,
{ label: "Purge" }
);

Expand All @@ -89,40 +92,43 @@ module.exports = class extends Command {
} catch (error) {
logger.error(`Error deleting messages: ${error}`, { label: "ERROR" });
return message.channel.send({
content: "There was an error trying to delete messages in this channel.",
content:
"There was an error trying to delete messages in this channel.",
});
}
await setTimeout(() => { }, 10000);
await delay(5000);
}


const embed = new MessageEmbed()

.setDescription(
`
${success} Successfully deleted **${totalDeleted}** ${totalDeleted === 1 ? "message" : "messages"} ${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);

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

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

if (logging) {
const role = message.guild.roles.cache.get(
Expand Down Expand Up @@ -159,10 +165,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 All @@ -176,4 +182,4 @@ module.exports = class extends Command {
);
}
}
};
};
2 changes: 1 addition & 1 deletion src/commands/moderation/createrole.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = class CreateRoleCommand extends Command {
description: "Create a role with optional settings",
category: "Moderation",
cooldown: 5,
usage: '"<roleName>" [color] [hoist] [mentionable]',
usage: '"<roleName>" <color> [hoist] [mentionable] [position]',
guildOnly: true,
permissions: ["MANAGE_ROLES"],
});
Expand Down
19 changes: 11 additions & 8 deletions src/commands/moderation/lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@ module.exports = class extends Command {
const language = require(`../../data/language/${guildDB.language}.json`);

let channel = message.mentions.channels.first();
let reason = args.join(" ") || "`none`";
let reason;

if (channel) {
reason = args.join(" ").slice(22) || "`none`";
} else channel = message.channel;
reason = args.slice(1).join(" ").trim() || "`none`";
} else {
channel = message.channel;
reason = args.join(" ").trim() || "`none`";
}

if (
channel.permissionsFor(message.guild.id).has("SEND_MESSAGES") === false
Expand Down Expand Up @@ -64,7 +67,7 @@ module.exports = class extends Command {
logging && logging.moderation.include_reason === "true"
? `\n\n**Reason:** ${reason}`
: ``
}`,
}`
)
.setColor(client.color.green);
message.channel
Expand All @@ -84,10 +87,10 @@ module.exports = class extends Command {
}

const role = message.guild.roles.cache.get(
logging.moderation.ignore_role,
logging.moderation.ignore_role
);
const channel = message.guild.channels.cache.get(
logging.moderation.channel,
logging.moderation.channel
);

if (logging.moderation.toggle == "true") {
Expand All @@ -97,7 +100,7 @@ module.exports = class extends Command {
!role ||
(role &&
!message.member.roles.cache.find(
(r) => r.name.toLowerCase() === role.name,
(r) => r.name.toLowerCase() === role.name
))
) {
if (logging.moderation.lock == "true") {
Expand All @@ -115,7 +118,7 @@ module.exports = class extends Command {
const logEmbed = new MessageEmbed()
.setAuthor(
`Action: \`Lock\` | ${message.author.tag} | Case #${logcase}`,
message.author.displayAvatarURL({ format: "png" }),
message.author.displayAvatarURL({ format: "png" })
)
.addField("Channel", `${channel}`, true)
.addField("Moderator", `${message.member}`, true)
Expand Down
Loading

0 comments on commit fc3758c

Please sign in to comment.