Skip to content

Commit

Permalink
remove shitty logger, some minor tweaks to msg logs
Browse files Browse the repository at this point in the history
  • Loading branch information
jvnipers committed Jan 16, 2025
1 parent 93d95d7 commit 7a2bbdc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 27 deletions.
26 changes: 2 additions & 24 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,19 @@ const client = new Client({
exports.client = client;
client.commands = new Collection();

function logError(error) {
const filepath = path.join(__dirname, "error.log");
const timestamp = new Date().toISOString();
const message = `[${timestamp}]: ${error.stack || error}\n`;

fs.appendFile(filepath, message, (err) => {
if (err) {
console.error("Failed to write to log file:", err);
}
});
}

const process = require("node:process");
process.on("unhandledRejection", (reason, promise) => {
console.log("Unhandled Rejection at:", promise, "reason:", reason);
logError("Unhandled Rejection at:", promise, "reason:", reason);
});

client.on("error", (error) => {
console.error("Error occurred:", error);
logError("Error occurred:", error);
});

require("dotenv").config();

client.on("disconnect", () => {
console.log("Disconnected from Discord API");
logError("Disconnected from Discord API");
const retry = (fn, retries = 3, timeout = 1000) => {
return new Promise((resolve, reject) => {
fn()
Expand All @@ -89,16 +74,9 @@ client.on("disconnect", () => {
});
};
console.log("Attempting to reconnect...");
logError("Attempting to reconnect...");
retry(() => client.login(process.env.TOKEN))
.then(
() => console.log("Logged in successfully"),
logError("Logged in successfully")
)
.catch(
(error) => console.error("Failed to log in:", error),
logError("Failed to log in:", error)
);
.then(() => console.log("Logged in successfully"))
.catch((error) => console.error("Failed to log in:", error));
});

require("./auto-roles.js");
Expand Down
9 changes: 6 additions & 3 deletions src/logger/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ client.on(Events.MessageDelete, async (message) => {
const settingsData = await settings.findOne({
Guild: message.guild.id,
});
if (settingsData.Messages === false) return;
if (settingsData.Store === false && settingsData.Post === false) return;
if (
settingsData.Messages === false ||
(settingsData.Store === false && settingsData.Post === false)
)
return;

try {
if (message.partial === true) await message.fetch();
if (message.partial && message.partial === true) await message.fetch();
} catch (error) {
console.log(error);
}
Expand Down

0 comments on commit 7a2bbdc

Please sign in to comment.